001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
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        
047        @In(create=false,required=false) 
048        private AbstractSeamServiceContext serviceContext;
049        
050        
051        public AsynchronousInvoker() throws ServiceException {
052            super();
053        }
054        
055        
056        /**
057         * Implementations of intercepted asynchronous calls (cron interval)
058         * @param asyncContext current context (session id)
059         * @param targetComponentName target component name
060         * @param methodName method name
061         * @param paramTypes method argument types
062         * @param params argument values
063         * @param duration optional duration
064         * @param expiration optional expiration date
065         * @param finalExpiration optional final expiration date
066         * @param intervalCron cron interval
067         * @return result
068         */
069        @Asynchronous
070        public Object invokeAsynchronousCron(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
071                @Duration Long duration, @Expiration Date expiration, @FinalExpiration Date finalExpiration, @IntervalCron String intervalCron) {
072            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
073        }
074        
075        /**
076         * Implementations of intercepted asynchronous calls (duration interval)
077         * @param asyncContext current context (session id)
078         * @param targetComponentName target component name
079         * @param methodName method name
080         * @param paramTypes method argument types
081         * @param params argument values
082         * @param duration optional duration
083         * @param expiration optional expiration date
084         * @param intervalDuration duration interval
085         * @return result
086         */
087        @Asynchronous
088        public Object invokeAsynchronousDuration(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
089                @Duration Long duration, @Expiration Date expiration, @IntervalDuration Long intervalDuration) {
090            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
091        }
092        
093        /**
094         * Implementations of intercepted asynchronous calls (duration interval)
095         * @param asyncContext current context (session id)
096         * @param targetComponentName target component name
097         * @param methodName method name
098         * @param paramTypes method argument types
099         * @param params argument values
100         * @param duration optional duration
101         * @param expiration optional expiration date
102         * @param finalExpiration optional final expiration date
103         * @param intervalDuration duration interval
104         * @return result
105         */
106        @Asynchronous
107        public Object invokeAsynchronousDuration(AsyncContext asyncContext, String targetComponentName, Class<?> targetComponentClass, String methodName, Class<?>[] paramTypes, Object[] params,
108                @Duration Long duration, @Expiration Date expiration, @FinalExpiration Date finalExpiration, @IntervalDuration Long intervalDuration) {
109            return serviceContext.invokeAsynchronous(asyncContext, targetComponentName, targetComponentClass, methodName, paramTypes, params);
110        }
111    }