1 2 Previous Next 17 Replies Latest reply on Jul 10, 2011 10:38 AM by Nicoletta Fan

    Quartz Scheduler

    elfuhrer Novice

      I'm trying to build a sample job scheduler using the Quartz approach and I have referred to the existing examples in the seam distribution.


      However I can't seem to inject the component that handles the execution of the tasks.


      I'll try to briefly explain my approach in here. For now I just want my application to log a message at the console every 10 seconds.


      The Quartz scheduler is initialized through an action that executes after the application is deployed. This is defined in the components.xml file:



          ...
          <async:quartz-dispatcher/>
      
          <event type="org.jboss.seam.postInitialization">
              <action execute="#{reservationsScheduler.scheduleReservationsProcessing}" />
          </event>



      The quartz properties file consists of the following:



      org.quartz.scheduler.instanceName = reservationsDispatcher
      org.quartz.scheduler.instanceId = 1
      org.quartz.scheduler.rmi.export = false
      org.quartz.scheduler.rmi.proxy = false
      
      org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
      org.quartz.threadPool.threadCount = 3
      
      org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
      





      The scheduler class consists of the following:



      @Name("reservationsScheduler")
      public class ReservationsScheduler {
          @In
          ReservationDispatcher dispatcher;
      
          @Logger
          Log                   log;
      
          public void scheduleReservationsProcessing() {
           long interval = 10 * 1000;
           dispatcher.dispatchReservations(interval);
          }
      }





      and the task being executed is as follows:




      @Name("reservationsScheduler")
      public class ReservationsScheduler {
          @In
          ReservationDispatcher dispatcher;
      
          @Logger
          Log                   log;
      
          public void scheduleReservationsProcessing() {
           long interval = 10 * 1000;
           dispatcher.dispatchReservations(interval);
          }
      }
      




      Now the exception I get is the following:




      12:41:08,279 ERROR [[/hsimulation]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      javax.el.ELException: org.jboss.seam.RequiredException: @In attribute requires non-null value: reservationsScheduler.dispatcher
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
              at org.jboss.seam.core.Events.raiseEvent(Events.java:68)
              at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:118)
              at org.jboss.seam.init.Initialization.init(Initialization.java:740)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
              at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
              at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
              at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
              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:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
              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:668)
              at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
              at $Proxy38.start(Unknown Source)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
              at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
              at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
              at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
              at org.jboss.system.ServiceController.start(ServiceController.java:460)
              at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
              at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
              at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
              at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
              at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
              at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
              at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
              at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
              at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
              at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
              at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
              at org.jboss.Main.boot(Main.java:221)
              at org.jboss.Main$1.run(Main.java:556)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: reservationsScheduler.dispatcher
              at org.jboss.seam.Component.getValueToInject(Component.java:2335)
              at org.jboss.seam.Component.injectAttributes(Component.java:1736)
              at org.jboss.seam.Component.inject(Component.java:1554)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at org.webpatterns.hsimulation.action.ReservationsScheduler_$$_javassist_seam_1.scheduleReservationsProcessing(ReservationsScheduler_$$_javassist_seam_1.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:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
              ... 79 more
      12:41:08,549 ERROR [StandardContext] Error listenerStart
      12:41:08,553 ERROR [StandardContext] Context [/hsimulation] startup failed due to previous errors
      12:41:08,557 INFO  [QuartzScheduler] Scheduler ReservationsDispatcher_$_1 shutting down.
      12:41:08,561 INFO  [QuartzScheduler] Scheduler ReservationsDispatcher_$_1 paused.
      12:41:08,566 INFO  [QuartzScheduler] Scheduler ReservationsDispatcher_$_1 shutdown complete.
      12:41:08,582 ERROR [AbstractKernelController] Error installing to Start: name=jboss.web.deployment:war=/hsimulation state=Create mode=Manual requiredState=Installed
      org.jboss.deployers.spi.DeploymentException: URL file:/D:/workspace/servers/jboss-5.1.0.GA/server/default/tmp/5c4o12s-latu0m-g6kkhrhz-1-g6kkjd6p-v/hsimulation.ear/hsimulation
      .war/ deployment failed
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:331)
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
              at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
              at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
              at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
              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:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
              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:668)
              at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
              at $Proxy38.start(Unknown Source)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
              at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
              at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
              at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
              at org.jboss.system.ServiceController.start(ServiceController.java:460)
              at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
              at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
              at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
              at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
              at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
              at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
              at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
              at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
              at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
              at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
              at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
              at org.jboss.Main.boot(Main.java:221)
              at org.jboss.Main$1.run(Main.java:556)
              at java.lang.Thread.run(Thread.java:619)




      I'm pretty sure the problem is pretty simple, can someone assist me in this? why the injected component is always null?


      Cheers,


      Fady

        • 1. Re: Quartz Scheduler
          Nikolay Elenkov Master

          Try:


          @In(create=true)
          ReservationDispatcher dispatcher
          

          • 2. Re: Quartz Scheduler
            elfuhrer Novice

            The @AutoCreate annotation must handle that, I have tried it initially while trying to debug the problem and that didn't solve the problem

            • 3. Re: Quartz Scheduler
              Nikolay Elenkov Master

              Post ReservationDispatcher code.

              • 4. Re: Quartz Scheduler
                elfuhrer Novice

                Posted earlier in the initial post ;-)


                The scheduler class consists of the following:




                @Name("reservationsScheduler")
                public class ReservationsScheduler {
                    @In
                    ReservationDispatcher dispatcher;
                
                    @Logger
                    Log                   log;
                
                    public void scheduleReservationsProcessing() {
                     long interval = 10 * 1000;
                     dispatcher.dispatchReservations(interval);
                    }
                }



                • 5. Re: Quartz Scheduler
                  Emir Calabuch Newbie

                  No, you posted the ReservationsScheduler class twice..., you haven't posted the ReservationDispatcher code.


                  Anyway, try making ReservationDispatcher an application-scoped component. When dealing with asynchronous components, remember that you cannot use contexts as you would during a JSF request.

                  • 6. Re: Quartz Scheduler
                    elfuhrer Novice

                    Here's the reservations dispatcher class:


                    @Name("reservationsDispatcher")
                    @AutoCreate
                    public class ReservationDispatcher {

                        @Logger
                        Log log;

                        @Asynchronous
                        @Transactional
                        public QuartzTriggerHandle dispatchReservations(
                             @IntervalDuration Long interval) {
                         log.info("Scheduled task started on #0", Calendar.getInstance()
                                 .getTime());
                         return null;
                        }
                    }


                    Adding the @Scope(ScopeType.APPLICATION) made the exception disappear but still the task is not fired after 10 seconds as specified in the interval.


                    Thanks for the help

                    • 7. Re: Quartz Scheduler
                      elfuhrer Novice

                      You can ignore my previous post as it's irrelevant.


                      The scope has nothing to do with the null dispatcher in here, since the component simply can't be injected. Furthermore I have modified to code to be triggered from an action button and still that didn't work out.


                      Most probably I'll resort to the old way of programming quartz schedulers since this approach is not working for me.


                      Any clue why the reservations dispatcher cannot be injected? Here's the code for it, nothing fancy in there, still I have no clue why it ain't being properly injected:




                      @Name("reservationsDispatcher")
                      @Scope(ScopeType.APPLICATION)
                      @AutoCreate
                      public class ReservationDispatcher {
                      
                          @Logger
                          Log log;
                      
                          @Asynchronous
                          @Transactional
                          public QuartzTriggerHandle dispatchReservations(
                               @IntervalDuration Long interval) {
                           log.info("Scheduled task started on #0", Calendar.getInstance()
                                   .getTime());     
                           return null;
                          }
                      }




                      and again the Reservations Scheduler:




                      @Name("reservationsScheduler")
                      public class ReservationsScheduler {
                          @In(create = true)
                          ReservationDispatcher dispatcher;
                      
                          @Logger
                          Log                   log;
                      
                          public void scheduleReservationsProcessing() {
                           long interval = 10 * 1000L;
                           log.info("Interval set to #0 seconds.", interval);
                           dispatcher.dispatchReservations(interval);
                          }
                      }
                      



                      Cheers,


                      Fady

                      • 8. Re: Quartz Scheduler
                        Arbi Sookazian Master

                        I have used Quartz in a Seam app in the past but don't have access to the code right now.


                        Anyways, try trouble-shooting by doing something like this:


                        @Name("reservationsDispatcher")
                        @Scope(ScopeType.APPLICATION)
                        @AutoCreate
                        public class ReservationDispatcher {
                        
                            @Logger
                            Log log;
                        
                            public void dispatchReservations(Long interval) {
                             log.info("Scheduled task started on #0", Calendar.getInstance().getTime());     
                             return null;
                            }
                        }



                        If you do this, is the injection successful? 


                        As an alternative, you could also try an EJB3 timer with session bean components.

                        • 9. Re: Quartz Scheduler
                          elfuhrer Novice

                          No it doesn't work this way, The EJB3 timer works fine, I want to figure out why this approach doesn't work, the requirements of the application do not scale to EJBs this is an overload of the lightweight system I'm putting up in place

                          • 10. Re: Quartz Scheduler
                            elfuhrer Novice

                            Finally I got it working, I feel like banging my head against a wall to stop those stupid brain cells from functioning.


                            The dispatcher object can not be injected since it was named as reservationsDispatcher. and I was injecting it as dispatcher


                            Renaming the object from dispatcher to reservationsDispatcher sorted it out.

                            • 11. Re: Quartz Scheduler
                              Nicoletta Fan Newbie

                              Hi and thank you for this thread, it almost helped me in everything, but at last this problem is driving me crazy.
                              I cannot succeed in repeating my schedulation, it works once, and then no more...
                              this is my starter class



                              @Name("actiononstartup")
                              public class ActionOnStartup {
                                   
                                   //@In
                                   //EntityManager entityManager;
                                   
                                   @Logger
                                     private Log log;
                                   
                                   @In(required=false)
                                   DiscoverySchedulerSniffer discoverySchedulersniff;
                                   
                                   @Observer("org.jboss.seam.postInitialization")
                                   @Asynchronous
                                   public void doAtStart() {
                                        log.info("*** Parto subito: Avvia Scheduled Discovery ***");
                                                    
                                        Calendar cal = Calendar.getInstance ();
                                        cal.set (2099, Calendar.DECEMBER, 31);
                                        QuartzTriggerHandle handle = discoverySchedulersniff.scheduleDisc(10L, cal.getTime());
                                        
                                        //return handle;
                              
                                        
                                   }
                                     
                                        
                              }



                              This is the Scheduler class



                              @Name("discoverySchedulersniff")
                              //@Scope(ScopeType.APPLICATION)
                              @AutoCreate
                              public class DiscoverySchedulerSniffer {
                                   
                                   @In
                                   EntityManager entityManager;
                                   
                                   Integer fIndex = 1;
                                   
                                   @Logger
                                     private Log log;
                                   
                                   //@Asynchronous
                                   //@Transactional @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                                     public QuartzTriggerHandle scheduleDisc(
                                               @IntervalDuration Long interval,
                                               @FinalExpiration Date endDate) {
                              
                                       log.info("Scheduling discovery with " + interval + " interval schedule");
                                      log.info(fIndex.toString());
                                      fIndex++;
                                      
                                      return null;
                              
                                     }
                              }



                              ... with the interface




                              public interface DiscoverySchedulerSnifferInterface {
                                   
                                   @Asynchronous
                                   public QuartzTriggerHandle scheduleDisc(
                                               @IntervalDuration Long interval,
                                               @FinalExpiration Date endDate);



                              the components.xml



                              <components xmlns="http://jboss.com/products/seam/components"
                                          xmlns:core="http://jboss.com/products/seam/core"
                                          xmlns:persistence="http://jboss.com/products/seam/persistence"
                                          xmlns:drools="http://jboss.com/products/seam/drools"
                                          xmlns:bpm="http://jboss.com/products/seam/bpm"
                                          xmlns:security="http://jboss.com/products/seam/security"
                                          xmlns:mail="http://jboss.com/products/seam/mail"
                                          xmlns:web="http://jboss.com/products/seam/web"
                                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                          xmlns:async="http://jboss.com/products/seam/async"
                                          xsi:schemaLocation=
                                              "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                                               http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                                               http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.2.xsd 



                              and the application.xml



                              <module>
                                     <ejb>quartz-all-2.0.1.jar</ejb>
                                 </module>



                              I've configured both the classpath and the build.xml in order to deploy the library into the EAR itself... and still nothing.


                              It runs once and then no more... what's wrong with it?
                              Any help will be appreciated
                                   





                              • 12. Re: Quartz Scheduler
                                Nikolay Elenkov Master

                                Nicoletta Fan wrote on Jul 07, 2011 15:03:


                                Hi and thank you for this thread, it almost helped me in everything, but at last this problem is driving me crazy.
                                I cannot succeed in repeating my schedulation, it works once, and then no more...
                                this is my starter class


                                @Name("discoverySchedulersniff")
                                //@Scope(ScopeType.APPLICATION)
                                @AutoCreate
                                public class DiscoverySchedulerSniffer {
                                     
                                     @In
                                     EntityManager entityManager;
                                     
                                     Integer fIndex = 1;
                                     
                                     @Logger
                                       private Log log;
                                     
                                     //@Asynchronous
                                     //@Transactional @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                                       public QuartzTriggerHandle scheduleDisc(
                                                 @IntervalDuration Long interval,
                                                 @FinalExpiration Date endDate) {
                                
                                         log.info("Scheduling discovery with " + interval + " interval schedule");
                                        log.info(fIndex.toString());
                                        fIndex++;
                                        
                                        return null;
                                
                                       }
                                }






                                You need the @Asynchronous annotation on the implementation class for the method to be registered as a Quartz job. Uncomment it and it should work.

                                • 13. Re: Quartz Scheduler
                                  Nicoletta Fan Newbie

                                  Thank you so much Nicolay! Uncommenting the @Asynchronous it works!
                                  It's really strange, because I created an interface for the class DiscoverySchedulerSniffer with the scheduleDisc method and the @Asynchronous annotation, but it didn't work at all. No matter, now it's all right!

                                  • 14. Re: Quartz Scheduler
                                    Nikolay Elenkov Master

                                    Nicoletta Fan wrote on Jul 08, 2011 05:01:


                                    Thank you so much Nicolay! Uncommenting the @Asynchronous it works!
                                    It's really strange, because I created an interface for the class DiscoverySchedulerSniffer with the scheduleDisc method and the @Asynchronous annotation, but it didn't work at all. No matter, now it's all right!


                                    IIRC, Seam examines the actual component class for the relevant annotations. By the way, at least in the example you posted, your component class doesn't implement the interface, so it doesn't matter what annotations you have on the interface at all.

                                    1 2 Previous Next