deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r891754 - in /websites/staging/deltaspike/trunk/content: ./ scheduler.html
Date Wed, 25 Dec 2013 15:52:16 GMT
Author: buildbot
Date: Wed Dec 25 15:52:15 2013
New Revision: 891754

Log:
Staging update by buildbot for deltaspike

Modified:
    websites/staging/deltaspike/trunk/content/   (props changed)
    websites/staging/deltaspike/trunk/content/scheduler.html

Propchange: websites/staging/deltaspike/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Dec 25 15:52:15 2013
@@ -1 +1 @@
-1553391
+1553392

Modified: websites/staging/deltaspike/trunk/content/scheduler.html
==============================================================================
--- websites/staging/deltaspike/trunk/content/scheduler.html (original)
+++ websites/staging/deltaspike/trunk/content/scheduler.html Wed Dec 25 15:52:15 2013
@@ -81,10 +81,79 @@
               <div class="toc">
 <ul>
 <li><a href="#intro">Intro</a></li>
+<li><a href="#scheduled">@Scheduled</a></li>
+<li><a href="#scheduler">Scheduler</a></li>
+<li><a href="#custom-scheduler">Custom Scheduler</a></li>
 </ul>
 </div>
 <hr />
 <h1 id="intro">Intro</h1>
+<p>This module provides a simple integration with Quartz v2 (per default) or any other
scheduler which supports cron-expressions for job-classes.</p>
+<h1 id="scheduled">@Scheduled</h1>
+<p>Just annotate your Quartz-Jobs with <code>@Scheduled</code> and they
will get picked up and passed to the scheduler automatically (during the bootstrapping process).</p>
+<div class="codehilite"><pre><span class="nd">@Scheduled</span><span
class="o">(</span><span class="n">cronExpression</span> <span class="o">=</span>
<span class="s">&quot;0 0/10 * * * ?&quot;</span><span class="o">)</span>
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">CdiAwareQuartzJob</span> <span class="kd">implements</span>
<span class="n">org</span><span class="o">.</span><span class="na">quartz</span><span
class="o">.</span><span class="na">Job</span>
+<span class="o">{</span>
+    <span class="nd">@Inject</span>
+    <span class="kd">private</span> <span class="n">MyService</span>
<span class="n">service</span><span class="o">;</span>
+
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span
class="nf">execute</span><span class="o">(</span><span class="n">JobExecutionContext</span>
<span class="n">context</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">JobExecutionException</span>
+    <span class="o">{</span>
+        <span class="c1">//...</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>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 <code>@Scheduled#startScopes</code> (possible values:
all scopes supported by the container-control module as well as <code>{}</code>
for 'no scopes').</p>
+<p>With 'false' for <code>@Scheduled#onStartup</code> it's even possible
to schedule/install jobs dynamically - e.g.:</p>
+<div class="codehilite"><pre><span class="nd">@ApplicationScoped</span>
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">ProjectStageAwareSchedulerController</span>
+<span class="o">{</span>
+    <span class="nd">@Inject</span>
+    <span class="kd">private</span> <span class="n">Scheduler</span><span
class="o">&lt;</span><span class="n">Job</span><span class="o">&gt;</span>
<span class="n">jobScheduler</span><span class="o">;</span>
+
+    <span class="nd">@Inject</span>
+    <span class="kd">private</span> <span class="n">ProjectStage</span>
<span class="n">projectStage</span><span class="o">;</span>
+
+    <span class="kd">public</span> <span class="kt">void</span> <span
class="nf">registerJobs</span><span class="o">()</span>
+    <span class="o">{</span>
+        <span class="k">if</span> <span class="o">(</span><span
class="n">ProjectStage</span><span class="o">.</span><span class="na">Production</span><span
class="o">.</span><span class="na">equals</span><span class="o">(</span><span
class="k">this</span><span class="o">.</span><span class="na">projectStage</span><span
class="o">))</span>
+        <span class="o">{</span>
+            <span class="c1">//see &#39;false&#39; for @Scheduled#onStartup</span>
+            <span class="k">this</span><span class="o">.</span><span
class="na">jobScheduler</span><span class="o">.</span><span class="na">scheduleJob</span><span
class="o">(</span><span class="n">ManualCdiAwareQuartzJob</span><span
class="o">.</span><span class="na">class</span><span class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+
+    <span class="nd">@Scheduled</span><span class="o">(</span><span
class="n">cronExpression</span> <span class="o">=</span> <span class="s">&quot;0
0/10 * * * ?&quot;</span><span class="o">,</span> <span class="n">onStartup</span>
<span class="o">=</span> <span class="kc">false</span><span class="o">)</span>
+    <span class="kd">public</span> <span class="kd">class</span>
<span class="nc">ManualCdiAwareQuartzJob</span> <span class="kd">implements</span>
<span class="n">org</span><span class="o">.</span><span class="na">quartz</span><span
class="o">.</span><span class="na">Job</span>
+    <span class="o">{</span>
+        <span class="nd">@Inject</span>
+        <span class="kd">private</span> <span class="n">MyService</span>
<span class="n">service</span><span class="o">;</span>
+
+        <span class="nd">@Override</span>
+        <span class="kd">public</span> <span class="kt">void</span>
<span class="nf">execute</span><span class="o">(</span><span class="n">JobExecutionContext</span>
<span class="n">context</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">JobExecutionException</span>
+        <span class="o">{</span>
+            <span class="c1">//...</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h1 id="scheduler">Scheduler</h1>
+<p>This SPI allows to control the scheduler (or integrate any other compatible scheduler
as an alternative to Quartz2)</p>
+<p>Via std. injection like</p>
+<div class="codehilite"><pre><span class="nd">@Inject</span>
+<span class="kd">private</span> <span class="n">Scheduler</span><span
class="o">&lt;</span><span class="n">Job</span><span class="o">&gt;</span>
<span class="n">jobScheduler</span><span class="o">;</span>
+</pre></div>
+
+
+<p>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).</p>
+<h1 id="custom-scheduler">Custom Scheduler</h1>
+<p>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 <code>org.apache.deltaspike.test.scheduler.custom</code>
for further details.</p>
           </div>
       </div>
 



Mime
View raw message