001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2007-2010 ADEQUATE SYSTEMS SARL
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.tide.seam.async;
022    
023    import java.util.Date;
024    
025    import org.granite.messaging.service.ServiceException;
026    import org.granite.tide.seam.AbstractSeamServiceContext;
027    import org.jboss.seam.ScopeType;
028    import org.jboss.seam.annotations.In;
029    import org.jboss.seam.annotations.Name;
030    import org.jboss.seam.annotations.Scope;
031    import org.jboss.seam.annotations.async.Asynchronous;
032    import org.jboss.seam.annotations.async.Duration;
033    import org.jboss.seam.annotations.async.Expiration;
034    import org.jboss.seam.annotations.async.FinalExpiration;
035    import org.jboss.seam.annotations.async.IntervalCron;
036    import org.jboss.seam.annotations.async.IntervalDuration;
037    
038    
039    /**
040     * @author William DRAI
041     */
042    @Scope(ScopeType.STATELESS)
043    @Name("org.granite.tide.seam.asynchronousInvoker")
044    public class AsynchronousInvoker {
045    
046        private static final long serialVersionUID = 1L;
047        
048        
049        @In(create=false,required=false) 
050        private AbstractSeamServiceContext serviceContext;
051        
052        
053        public AsynchronousInvoker() throws ServiceException {
054            super();
055        }
056        
057        
058        /**
059         * Implementations of intercepted asynchronous calls (cron interval)
060         * @param asyncContext current context (session id)
061         * @param targetComponentName target component name
062         * @param methodName method name
063         * @param paramTypes method argument types
064         * @param params argument values
065         * @param duration optional duration
066         * @param expiration optional expiration date
067         * @param finalExpiration optional final expiration date
068         * @param intervalCron cron interval
069         * @return result
070         */
071        @Asynchronous
072        public Object invokeAsynchronousCron(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
073                @Duration Long duration, @Expiration Date expiration, @FinalExpiration Date finalExpiration, @IntervalCron String intervalCron) {
074            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
075        }
076        
077        /**
078         * Implementations of intercepted asynchronous calls (duration interval)
079         * @param asyncContext current context (session id)
080         * @param targetComponentName target component name
081         * @param methodName method name
082         * @param paramTypes method argument types
083         * @param params argument values
084         * @param duration optional duration
085         * @param expiration optional expiration date
086         * @param intervalDuration duration interval
087         * @return result
088         */
089        @Asynchronous
090        public Object invokeAsynchronousDuration(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
091                @Duration Long duration, @Expiration Date expiration, @IntervalDuration Long intervalDuration) {
092            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
093        }
094        
095        /**
096         * Implementations of intercepted asynchronous calls (duration interval)
097         * @param asyncContext current context (session id)
098         * @param targetComponentName target component name
099         * @param methodName method name
100         * @param paramTypes method argument types
101         * @param params argument values
102         * @param duration optional duration
103         * @param expiration optional expiration date
104         * @param finalExpiration optional final expiration date
105         * @param intervalDuration duration interval
106         * @return result
107         */
108        @Asynchronous
109        public Object invokeAsynchronousDuration(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
110                @Duration Long duration, @Expiration Date expiration, @FinalExpiration Date finalExpiration, @IntervalDuration Long intervalDuration) {
111            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
112        }
113    }