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