Quartz Attempted to invoke a Seam component outside an initialized application
ssarver Apr 7, 2010 5:14 PMHow should I change my async code to avoid the following error that occurs when JBoss is restarted, and Quartz is trying to recover jobs from the database?
Error:
java.lang.IllegalStateException: Attempted to invoke a Seam component outside an initialized application
Log:
07:00:49,797 INFO [QuartzService] Create QuartzService(Quartz)... 07:00:49,816 INFO [QuartzService] QuartzService(Quartz) created. 07:00:49,817 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=QuartzNoTxDS' to JNDI name 'java:QuartzNoTxDS' 07:00:49,817 INFO [QuartzService] Start QuartzService(Quartz)... 07:00:49,901 INFO [SchedulerSignalerImpl] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 07:00:49,902 INFO [QuartzScheduler] Quartz Scheduler v.1.7.3 created. 07:00:49,904 INFO [JobStoreCMT] Using db table-based data access locking (synchronization). 07:00:49,943 INFO [JobStoreCMT] Removed 0 Volatile Trigger(s). 07:00:49,943 INFO [JobStoreCMT] Removed 0 Volatile Job(s). 07:00:49,944 INFO [JobStoreCMT] JobStoreCMT initialized. 07:00:49,944 INFO [StdSchedulerFactory] Quartz scheduler 'JBossQuartzScheduler' initialized from an externally provided properties instance. 07:00:49,944 INFO [StdSchedulerFactory] Quartz scheduler version: 1.7.3 07:00:49,948 INFO [JobStoreCMT] Freed 0 triggers from 'acquired' / 'blocked' state. 07:00:49,949 INFO [JobStoreCMT] Recovering 0 jobs that were in-progress at the time of the last shut-down. 07:00:49,949 INFO [JobStoreCMT] Recovery complete. 07:00:49,950 INFO [JobStoreCMT] Removed 0 'complete' triggers. 07:00:49,950 INFO [JobStoreCMT] Removed 0 stale fired job entries. 07:00:49,952 INFO [QuartzScheduler] Scheduler JBossQuartzScheduler_$_NON_CLUSTERED started. 07:00:49,952 INFO [QuartzService] QuartzService(Quartz) started. 07:00:50,049 WARN [InterceptorInfoRepository] EJBTHREE-1852: InterceptorInfoRepository is deprecated 07:00:50,385 ERROR [JobRunShell] Job DEFAULT.33f24256:127d8beb737:-7ff8 threw an unhandled Exception: java.lang.IllegalStateException: Attempted to invoke a Seam component outside an initialized application at org.jboss.seam.contexts.Lifecycle.getApplication(Lifecycle.java:36) at org.jboss.seam.contexts.Lifecycle.beginCall(Lifecycle.java:89) at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.setup(Asynchronous.java:54) at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:77) at org.jboss.seam.async.AsynchronousInvocation.handleException(AsynchronousInvocation.java:78) at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:247) at org.quartz.core.JobRunShell.run(JobRunShell.java:199) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546) 07:00:50,445 ERROR [ErrorLogger] Job (DEFAULT.33f24256:127d8beb737:-7ff8 threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.IllegalStateException: Attempted to invoke a Seam component outside an initialized application] at org.quartz.core.JobRunShell.run(JobRunShell.java:210) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546) Caused by: java.lang.IllegalStateException: Attempted to invoke a Seam component outside an initialized application at org.jboss.seam.contexts.Lifecycle.getApplication(Lifecycle.java:36) at org.jboss.seam.contexts.Lifecycle.beginCall(Lifecycle.java:89) at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.setup(Asynchronous.java:54) at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:77) at org.jboss.seam.async.AsynchronousInvocation.handleException(AsynchronousInvocation.java:78) at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:247) at org.quartz.core.JobRunShell.run(JobRunShell.java:199) ... 1 more
Async code:
@Name("processor") @AutoCreate public class PaymentProcessor { @Logger Log log; @In EntityManager entityManager; @In QuartzTriggerHandle timer; @Asynchronous @Transactional public QuartzTriggerHandle schedulePayment( @Expiration Date when, @IntervalDuration Long interval, @FinalExpiration Date stoptime, Long paymentId) throws Exception { QuartzDispatcher dispatcher = QuartzDispatcher.instance(); Scheduler scheduler = dispatcher.getScheduler(); SimpleTrigger t = (SimpleTrigger) timer.getTrigger(); Date date = new Date(); date.setTime(date.getTime() + 30000L); SimpleTrigger trigger = new SimpleTrigger(t.getName(), t.getGroup(), t.getJobName(), t.getJobGroup(), date, null, 0, 0); // Schedule trigger scheduler.rescheduleJob(t.getName(), t.getGroup(), trigger); ... }