13 Replies Latest reply on Oct 8, 2007 7:41 AM by motte1979

    Call scheduled method from another scheduled method

    robin.hultman

      Hi,

      Is it possible to call an asynchronous method from another asynchronous method?

      I have this method:

      public QuartzTriggerHandle scheduleSeason(@Expiration Date endDate, Season season)
      


      In that method I want to call these scheduled methods:
      QuartzTriggerHandle expirationHandle = destroyOffer(endDate,offer);
      QuartzTriggerHandle reminderHandle = sendReminder(endDate,offer);
      


      The method heads looks like this:
      public QuartzTriggerHandle sendReminder(@Expiration Date endDate, Subscription winner)
      public QuartzTriggerHandle destroyOffer(@Expiration Date endDate, Subscription winner)
      


      The first method is called as expected but the ones called from that one gets called immediately.

      Any suggestions?

        • 1. Re: Call scheduled method from another scheduled method
          robin.hultman

          Sorry forgot.

          All methods is marked with

          @Asynchronous
          @Transactional
          


          And I am using Seam 2.0 beta1

          • 2. Re: Call scheduled method from another scheduled method

            You mean that the first method is delayed properly. But when the first method is called, the nested methods in it were called as if they are synchronous methods?

            That might be that the first @Aync method is not properly intercepted by Seam since its thread spawn from Quartz? Can you try the EJB3 timer and see if the same thing happens? Thanks.

            cheers
            Michael

            • 3. Re: Call scheduled method from another scheduled method
              pmuir

              Someone else reported this not in the context of Quartz. If you are sure this is happening please file a JIRA issue with simple example built using seam-gen with the lib/ directory removed.

              • 4. Re: Call scheduled method from another scheduled method
                motte1979

                Hello !

                Is this known as bug now ? Could anyone post the JIRA issue nbr/link ?

                I've an similar problem: I try to implments a retry-mechanism for an asynchronous task. This is implemented as follows ..

                The retry is not processed in an asynchron way as expected .. (?)

                @Stateless
                @AutoCreate
                @Name(AlertingEngineTask.NAME)
                public class AlertingEngineTaskBean implements AlertingEngineTask {
                
                ...........
                
                 @Asynchronous
                 public void recieve(Info info) {
                 try {
                
                 .........
                
                 } catch (Throwable th) {
                 retry (info);
                 }
                 }
                
                ...........
                
                 private void retry(Info info) throws LogPermanentErrorsException {
                 retry ++ ;
                
                 if (retry > 4)
                 throw new LogPermanentErrorsException();
                 AlertingEngineTask task = (AlertingEngineTask)
                 Component.getInstance(this.getClass(), ScopeType.EVENT, true);
                 task.setRetry(getRetry());
                 task.recieve(info);
                 }
                
                }
                


                I'm using seam 2.0.0.BETA1


                • 5. Re: Call scheduled method from another scheduled method
                  motte1979

                  Hmmmm .....

                  There is a condition in the AsynchronousInterceptor which prevents @Asynchronous calls to be made from @Asynchronous methods ...

                  Why ?

                  !Contexts.getEventContext().isSet(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL)


                  @AroundInvoke
                   public Object aroundInvoke(InvocationContext invocation) throws Exception
                   {
                   boolean scheduleAsync = invocation.getMethod().isAnnotationPresent(Asynchronous.class) &&
                   !Contexts.getEventContext().isSet(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL);
                   if (scheduleAsync)
                   {
                   Dispatcher dispatcher = AbstractDispatcher.instance();
                   if (dispatcher==null)
                   {
                   throw new IllegalStateException("org.jboss.seam.async.dispatcher is not installed in components.xml");
                   }
                   Object timer = dispatcher.scheduleInvocation( invocation, getComponent() );
                   //if the method returns a Timer, return it to the client
                   return timer!=null && invocation.getMethod().getReturnType().isAssignableFrom( timer.getClass() ) ? timer : null;
                   }
                   else
                   {
                   return invocation.proceed();
                   }
                   }
                  


                  • 6. Re: Call scheduled method from another scheduled method
                    motte1979

                    Hi Gavin,

                    I would be pleased if you could help me in this case; the org.jboss.seam.async.AsynchronousInterceptor is written by you ...

                    Why it's not allowed to make asynchronous calls from asychronous methods ?

                    Thanks in advance
                    Matthias

                    • 7. Re: Call scheduled method from another scheduled method
                      pmuir
                      • 8. Re: Call scheduled method from another scheduled method
                        motte1979

                        Thanks very much!

                        • 9. Re: Call scheduled method from another scheduled method
                          motte1979

                          The version 2.0.0.CR2 throws an exception on startup ...

                          java.lang.NullPointerException
                           at org.jboss.seam.async.AsynchronousInterceptor.isExecutingAsynchronousCall(AsynchronousInterceptor.java:64)
                           at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:44)
                           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
                           at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                           at org.javassist.tmp.java.lang.Object_$$_javassist_5.destroy(Object_$$_javassist_5.java)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
                           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
                           at org.jboss.seam.Component.callComponentMethod(Component.java:2087)
                           at org.jboss.seam.Component.callDestroyMethod(Component.java:2018)
                           at org.jboss.seam.Component.destroy(Component.java:1336)
                           at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:251)
                           at org.jboss.seam.contexts.Lifecycle.endApplication(Lifecycle.java:52)
                           at org.jboss.seam.contexts.ServletLifecycle.endApplication(ServletLifecycle.java:118)
                           at org.jboss.seam.servlet.SeamListener.contextDestroyed(SeamListener.java:39)
                           at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3893)
                           at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4525)
                           at org.apache.catalina.core.StandardContext.start(StandardContext.java:4389)
                           at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
                           at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
                           at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
                           at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.apache.catalina.core.StandardContext.init(StandardContext.java:5310)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
                           at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
                           at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
                           at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
                           at org.jboss.web.WebModule.startModule(WebModule.java:83)
                           at org.jboss.web.WebModule.startService(WebModule.java:61)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                           at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                           at $Proxy0.start(Unknown Source)
                           at org.jboss.system.ServiceController.start(ServiceController.java:417)
                           at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                           at $Proxy45.start(Unknown Source)
                           at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                           at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                           at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                           at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:93)
                           at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                           at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                           at $Proxy46.start(Unknown Source)
                           at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                           at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
                           at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                           at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                           at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                           at $Proxy9.deploy(Unknown Source)
                           at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                           at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
                           at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                           at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                           at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                           at $Proxy0.start(Unknown Source)
                           at org.jboss.system.ServiceController.start(ServiceController.java:417)
                           at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                           at $Proxy4.start(Unknown Source)
                           at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
                           at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                           at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                           at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                           at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                           at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                           at $Proxy5.deploy(Unknown Source)
                           at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
                           at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
                           at org.jboss.Main.boot(Main.java:200)
                           at org.jboss.Main$1.run(Main.java:508)
                           at java.lang.Thread.run(Thread.java:595)
                          
                          


                          • 10. Re: Call scheduled method from another scheduled method
                            pmuir

                            How do trigger the Aync method at startup?

                            • 11. Re: Call scheduled method from another scheduled method
                              motte1979

                              It's is not an asynchronous method to be invoked ... It's the method marked with @Destroy @Remove ...

                              • 12. Re: Call scheduled method from another scheduled method
                                pmuir

                                Ok, let me put it another way. How do I reproduce this?

                                • 13. Re: Call scheduled method from another scheduled method
                                  motte1979

                                  I'm sorry, i did place an @Asynchronous on a statefull application-scoped @Startup bean.
                                  I splitted the bean into a stateless one and an application-scoped bean for holding the state ...

                                  For which contexts are @Asynchronous methods allowed ?