[jboss-svn-commits] JBL Code SVN: r34398 - labs/jbossrules/trunk/drools-docs/drools-docs-expert/src/main/docbook/en-US/Chapter-Rule_Language.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jul 30 00:43:06 EDT 2010


Author: tirelli
Date: 2010-07-30 00:43:05 -0400 (Fri, 30 Jul 2010)
New Revision: 34398

Modified:
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/src/main/docbook/en-US/Chapter-Rule_Language/Section-Rule.xml
Log:
Adding timers to docs

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-expert/src/main/docbook/en-US/Chapter-Rule_Language/Section-Rule.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/src/main/docbook/en-US/Chapter-Rule_Language/Section-Rule.xml	2010-07-30 04:30:23 UTC (rev 34397)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/src/main/docbook/en-US/Chapter-Rule_Language/Section-Rule.xml	2010-07-30 04:43:05 UTC (rev 34398)
@@ -245,8 +245,86 @@
     when ...
 </programlisting>
     </example>
-  </section>
+    <section>
+      <title>Timers and Calendars</title>
 
+      <para>Rule's now suport both interval and cron based timers, which
+      replace the now deprecated duration attribute.</para>
+
+      <example>
+        <title>Sample timer attribute uses</title>
+
+        <programlisting language="java">timer ( int: &lt;initial delay&gt; &lt;repeat interval&gt;? )
+timer ( int: 30s )
+timer ( int: 30s 5m )
+ 
+timer ( cron: &lt;cron expression&gt; )
+timer ( cron:* 0/15 * * * ? )</programlisting>
+      </example>
+
+      <para>Interval "int:" timers follow the JDK semantics for initial delay
+      optionally followed by a repeat interval. Cron "cron:" timers follow
+      standard cron expressions:</para>
+
+      <example>
+        <title>A Cron Example</title>
+
+        <programlisting language="java">rule "Send SMS every 15 minutes"
+    timer (cron:* 0/15 * * * ?)
+when
+    $a : Alarm( on == true )
+then
+    channels[ "sms" ].insert( new Sms( $a.mobileNumber, "The alarm is still on" );
+end</programlisting>
+      </example>
+
+      <para>Calendars can now controll when rules can fire. The Calendar api
+      is modelled on <link
+      xlink:href="http://www.quartz-scheduler.org/">Quartz
+      http://www.quartz-scheduler.org/</link> :</para>
+
+      <example>
+        <title>Adapting a Quartz Calendar</title>
+
+        <programlisting language="java">Calendar weekDayCal = QuartzHelper.quartzCalendarAdapter(org.quartz.Calendar quartzCal)</programlisting>
+      </example>
+
+      <para>Calendars are registered with the StatefulKnowledgeSession:</para>
+
+      <example>
+        <title>Registering a Calendar</title>
+
+        <programlisting language="java">ksession.getCalendars().set( "week day", weekDayCal );</programlisting>
+      </example>
+
+      <para>They can be used in conjunction with normal rules and rules
+      including timers. The rule calendar attribute can have one or more comma
+      calendar names.</para>
+
+      <example>
+        <title>Using Calendars and Timers together</title>
+
+        <programlisting language="java">rule "weekdays are high priority"
+   calendars "weekday"
+   timer (int:0 1h)
+when 
+    Alarm()
+then
+    send( "priority high - we have an alarm” );
+end 
+
+rule "weekend are low priority"
+   calendars "weekend"
+   timer (int:0 4h)
+when 
+    Alarm()
+then
+    send( "priority low - we have an alarm” );
+end</programlisting>
+      </example>
+   </section>
+   </section>
+
   <section id="RuleLanguage-ConditionalElements">
     <title>Left Hand Side (when) Conditional Elements</title>
 



More information about the jboss-svn-commits mailing list