Author: gpetracek
Date: Wed Dec 25 15:52:10 2013
New Revision: 1553392
URL: http://svn.apache.org/r1553392
Log:
updated content
Modified:
deltaspike/site/trunk/content/scheduler.mdtext
Modified: deltaspike/site/trunk/content/scheduler.mdtext
URL:
http://svn.apache.org/viewvc/deltaspike/site/trunk/content/scheduler.mdtext?rev=1553392&r1=1553391&r2=1553392&view=diff
==============================================================================
--- deltaspike/site/trunk/content/scheduler.mdtext (original)
+++ deltaspike/site/trunk/content/scheduler.mdtext Wed Dec 25 15:52:10 2013
@@ -22,3 +22,77 @@ Notice: Licensed to the Apache Softwa
# Intro
+This module provides a simple integration with Quartz v2 (per default) or any
other scheduler which supports cron-expressions for job-classes.
+
+# @Scheduled
+
+Just annotate your Quartz-Jobs with `@Scheduled` and they will get picked up
and passed to the scheduler automatically (during the bootstrapping process).
+
+ :::java
+ @Scheduled(cronExpression = "0 0/10 * * * ?")
+ public class CdiAwareQuartzJob implements org.quartz.Job
+ {
+ @Inject
+ private MyService service;
+
+ @Override
+ public void execute(JobExecutionContext context) throws
JobExecutionException
+ {
+ //...
+ }
+ }
+
+In such Quartz-jobs CDI based dependency-injection is enabled. Furthermore,
the request- and session-scope get started (and stopped) per job-execution.
Therefore, the container-control module (of DeltaSpike) is required.
+That can be controlled via `@Scheduled#startScopes` (possible values: all
scopes supported by the container-control module as well as `{}` for 'no
scopes').
+
+With 'false' for `@Scheduled#onStartup` it's even possible to schedule/install
jobs dynamically - e.g.:
+
+ :::java
+ @ApplicationScoped
+ public class ProjectStageAwareSchedulerController
+ {
+ @Inject
+ private Scheduler<Job> jobScheduler;
+
+ @Inject
+ private ProjectStage projectStage;
+
+ public void registerJobs()
+ {
+ if (ProjectStage.Production.equals(this.projectStage))
+ {
+ //see 'false' for @Scheduled#onStartup
+ this.jobScheduler.scheduleJob(ManualCdiAwareQuartzJob.class);
+ }
+ }
+
+ @Scheduled(cronExpression = "0 0/10 * * * ?", onStartup = false)
+ public class ManualCdiAwareQuartzJob implements org.quartz.Job
+ {
+ @Inject
+ private MyService service;
+
+ @Override
+ public void execute(JobExecutionContext context) throws
JobExecutionException
+ {
+ //...
+ }
+ }
+ }
+
+
+# Scheduler
+
+This SPI allows to control the scheduler (or integrate any other compatible
scheduler as an alternative to Quartz2)
+
+Via std. injection like
+
+ :::java
+ @Inject
+ private Scheduler<Job> jobScheduler;
+
+it's possible to manually start/stop the scheduler,
pause/resume/interrupt/check scheduled jobs, register jobs manually or start a
job once (without registering it permanently).
+
+# Custom Scheduler
+
+It's possible to replace the default integration with Quartz. Any other
scheduler which supports cron-expressions for job-classes can be used. Please
have a look at `org.apache.deltaspike.test.scheduler.custom` for further
details.