[jbpm-commits] JBoss JBPM SVN: r4534 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/eventlistener and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Apr 10 05:57:59 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-04-10 05:57:59 -0400 (Fri, 10 Apr 2009)
New Revision: 4534

Added:
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/EventListenerTest.java
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/LogListener.java
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/process.jpdl.xml
   jbpm4/trunk/modules/userguide/src/main/docbook/en/images/process.eventlistener.png
Modified:
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
   jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch05-Jpdl.xml
Log:
JBPM-2027 adding example and docs for event listeners

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/EventListenerTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/EventListenerTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/EventListenerTest.java	2009-04-10 09:57:59 UTC (rev 4534)
@@ -0,0 +1,29 @@
+package org.jbpm.examples.eventlistener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class EventListenerTest extends JbpmTestCase {
+  
+  public void testEventListener() {
+    deployJpdlResource("org/jbpm/examples/eventlistener/process.jpdl.xml");
+
+    LogListener.logs = new ArrayList<String>();
+    
+    Execution execution = executionService.startProcessInstanceByKey("EventListener");
+    executionService.signalExecutionById(execution.getId());
+    
+    List<String> expectedLogs = new ArrayList<String>();
+    expectedLogs.add("event(start) on process(EventListener)");
+    expectedLogs.add("event(start) on activity(wait)");
+    expectedLogs.add("event(end) on activity(wait)");
+    expectedLogs.add("event(take) on (wait)-->(end)");
+    expectedLogs.add("event(end) on process(EventListener)");
+    
+    assertEquals(expectedLogs, LogListener.logs);
+  }
+}


Property changes on: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/EventListenerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/LogListener.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/LogListener.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/LogListener.java	2009-04-10 09:57:59 UTC (rev 4534)
@@ -0,0 +1,18 @@
+package org.jbpm.examples.eventlistener;
+
+import java.util.List;
+
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+
+
+public class LogListener implements EventListener {
+
+  private static final long serialVersionUID = 1L;
+  
+  public static List<String> logs; // initialization done in test method
+
+  public void notify(EventListenerExecution execution) {
+    logs.add(execution.getEvent()+" on "+execution.getEventSource());
+  }
+}


Property changes on: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/eventlistener/LogListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/process.jpdl.xml	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/process.jpdl.xml	2009-04-10 09:57:59 UTC (rev 4534)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="EventListener" xmlns="http://jbpm.org/4/jpdl">
+
+  <on event="start">
+    <event-listener class="org.jbpm.examples.eventlistener.LogListener"/>
+  </on>
+
+  <on event="end">
+    <event-listener class="org.jbpm.examples.eventlistener.LogListener"/>
+  </on>
+
+
+  <start g="17,19,48,48">
+    <transition to="wait"/>
+  </start>
+
+  <state g="96,16,104,52" name="wait">
+	  <on event="start">
+	    <event-listener class="org.jbpm.examples.eventlistener.LogListener"/>
+	  </on>
+    <on event="end">
+      <event-listener class="org.jbpm.examples.eventlistener.LogListener"/>
+    </on>
+
+    <transition to="end">
+      <event-listener class="org.jbpm.examples.eventlistener.LogListener"/>
+    </transition>
+    
+  </state>
+  
+  <end g="231,19,80,52" name="end"/>
+
+</process>


Property changes on: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/eventlistener/process.jpdl.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-04-10 00:07:30 UTC (rev 4533)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-04-10 09:57:59 UTC (rev 4534)
@@ -124,57 +124,49 @@
     super.tearDown();
   }
 
-  protected void deploy(String archive)
-  {
-    if(isIntegrationTest())
+  @Deprecated
+  protected void deploy(String archive) {
+    if (isIntegrationTest())
       remoteDeploy(archive);
     else
       localDeploy(archive);
   }
 
-  private void remoteDeploy(String archive)
-  {
-    try
-    {
+  @Deprecated
+  private void remoteDeploy(String archive) {
+    try {
       getTestHelper().deploy(archive);
-    }
-    catch (Exception e)
-    {
+    } catch (Exception e) {
       throw new RuntimeException("Failed to deploy " + archive, e);
     }
   }
 
-  protected void undeploy(String archive)
-  {
-    if(isIntegrationTest())
+  @Deprecated
+  protected void undeploy(String archive) {
+    if (isIntegrationTest())
       remoteUndeploy(archive);
 
     // TODO: localUndeploy() happens in tearDown()
   }
 
-  private void localUndeploy(String archive)
-  {
+  @Deprecated
+  private void localUndeploy(String archive) {
     // TODO: Match archive with dbId, but for now undeploy any
-    for (Long deploymentDbid : registeredDeployments)
-    {
+    for (Long deploymentDbid : registeredDeployments) {
       repositoryService.deleteDeploymentCascade(deploymentDbid);
     }
   }
 
-  private void remoteUndeploy(String archive)
-  {
-    try
-    {
+  @Deprecated
+  private void remoteUndeploy(String archive) {
+    try {
       getTestHelper().undeploy(archive);
-    }
-    catch (Exception e)
-    {
+    } catch (Exception e) {
       throw new RuntimeException("Failed to undeploy " + archive, e);
     }
   }
 
-  protected IntegrationTestHelper getTestHelper()
-  {
+  protected IntegrationTestHelper getTestHelper() {
     if(!isIntegrationTest())
       throw new IllegalArgumentException("'jboss.bind.address' system property is missing");
 
@@ -184,12 +176,11 @@
     return testHelper;
   }
 
-  public static boolean isIntegrationTest()
-  {
+  @Deprecated
+  public static boolean isIntegrationTest() {
     return System.getProperty("jboss.bind.address")!=null;
   }
 
-  @Deprecated
   public long deployJpdlXmlString(String jpdlXmlString) {
     long deploymentDbid =
         repositoryService.createDeployment()
@@ -201,7 +192,6 @@
     return deploymentDbid;
   }
 
-  /*@Deprecated
   public void deployJpdlResource(String resource) {
     long deploymentDbid =
         repositoryService.createDeployment()
@@ -209,8 +199,9 @@
             .deploy();
 
     registerDeployment(deploymentDbid);
-  }*/
+  }
 
+  @Deprecated
   public void localDeploy(String archive) {
 
     URL archiveUrl = IntegrationTestHelper.getTestArchiveURL(archive);

Added: jbpm4/trunk/modules/userguide/src/main/docbook/en/images/process.eventlistener.png
===================================================================
(Binary files differ)


Property changes on: jbpm4/trunk/modules/userguide/src/main/docbook/en/images/process.eventlistener.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch05-Jpdl.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch05-Jpdl.xml	2009-04-10 00:07:30 UTC (rev 4533)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch05-Jpdl.xml	2009-04-10 09:57:59 UTC (rev 4534)
@@ -108,11 +108,12 @@
     </table>
   </section>
 
-  <section id="activities">
-    <title>Activities</title>
-    <para>(BPMN note: when we mention activities here, we are not only refering to BPMN 
-    activities, but also to BPMN events and BPMN gateways.)
-    </para>
+  <!-- ##################################################################### -->
+  <!-- ### CONTROL FLOW ACTIVITIES                                       ### -->
+  <!-- ##################################################################### -->
+  
+  <section id="controlflowactivities">
+    <title>Control flow activities</title>
 
     <section id="start">
       <title><literal>start</literal></title>
@@ -691,132 +692,6 @@
       </section>
     </section>
 
-    <!-- ### JAVA ########################################################## -->
-      
-    <section id="java">
-      <title><literal>java</literal></title>
-      <para>The Java task. A process execution will execute the method of the class that is configured
-      in this activity.</para> 
-      <table><title><literal>java</literal> attributes:</title>
-        <tgroup cols="5" rowsep="1" colsep="1">
-          <thead>
-            <row>
-              <entry>Attribute</entry>
-              <entry>Type</entry>
-              <entry>Default</entry>
-              <entry>Required?</entry>
-              <entry>Description</entry>
-            </row>
-          </thead>
-          <tbody>
-            <row>
-              <entry><literal>class</literal></entry>
-              <entry>classname</entry>
-              <entry></entry>
-              <entry><emphasis role="bold">required</emphasis></entry>
-              <entry>The fully qualified classname.</entry>
-            </row>
-            <row>
-              <entry><literal>method</literal></entry>
-              <entry>methodname</entry>
-              <entry></entry>
-              <entry><emphasis role="bold">required</emphasis></entry>
-              <entry>The name of the method to invoke</entry>
-            </row>
-            <row>
-              <entry><literal>var</literal></entry>
-              <entry>variablename</entry>
-              <entry></entry>
-              <entry>optional</entry>
-              <entry>The name of the variable in which the return value 
-              should be stored.
-              </entry>
-            </row>
-          </tbody>
-        </tgroup>
-      </table>
-      <table><title><literal>java</literal> elements:</title>
-        <tgroup cols="3" rowsep="1" colsep="1">
-          <thead>
-            <row>
-              <entry>Element</entry>
-              <entry>Multiplicity</entry>
-              <entry>Description</entry>
-            </row>
-          </thead>
-          <tbody>
-            <row>
-              <entry><literal>field</literal></entry>
-              <entry>0..*</entry>
-              <entry>describes a configuration value to inject in a memberfield before 
-              the method is invoked.</entry>
-            </row>
-            <row>
-              <entry><literal>arg</literal></entry>
-              <entry>0..*</entry>
-              <entry>method parameters</entry>
-            </row>
-          </tbody>
-        </tgroup>
-      </table>
-      <para>Consider the following example.</para>
-      <figure id="process.java">
-        <title>A java task</title>
-        <mediaobject><imageobject><imagedata align="center" fileref="images/process.java.png"/></imageobject></mediaobject>
-      </figure>
-      <programlisting>&lt;process name=&quot;Java&quot; xmlns=&quot;http://jbpm.org/4/jpdl&quot;&gt;
-
-  &lt;start&gt;
-    &lt;transition to=&quot;invoke java method&quot; /&gt;
-  &lt;/start&gt;
-
-  &lt;java name=&quot;invoke java method&quot; 
-        class=&quot;org.jbpm.examples.java.JohnDoe&quot;
-        method=&quot;hello&quot;
-        var=&quot;answer&quot;&gt;
-        
-    &lt;field name=&quot;state&quot;&gt;&lt;string value=&quot;fine&quot;/&gt;&lt;/field&gt;
-    &lt;field name=&quot;session&quot;&gt;&lt;env type=&quot;org.hibernate.Session&quot;/&gt;&lt;/field&gt;
-
-    &lt;arg&gt;&lt;string value=&quot;Hi, how are you?&quot;/&gt;&lt;/arg&gt;
-    
-    &lt;transition to=&quot;wait&quot; /&gt;
-  &lt;/java&gt;
-  
-  &lt;state name=&quot;wait&quot;&gt;
-
-&lt;/process&gt;
-      </programlisting>
-      <para>The java task specifies that during its execution an instance of the class <literal>org.jbpm.examples.java.JohnDoe</literal>
-      will be instantiated and the method <literal>hello</literal> of this class will be invoked on the resulting object. The variable named
-      <literal>answer</literal> will contain the result of the invocation. Let's look at the class <literal>JohnDoe</literal> below.
-      </para>
-      <programlisting>package org.jbpm.examples.java;
-
-import org.hibernate.Session;
-
-public class JohnDoe {
-  
-  String state;
-  Session session;
-  
-  public String hello(String msg) {
-    if ( (msg.indexOf(&quot;how are you?&quot;)!=-1)
-         &amp;&amp; (session.isOpen())
-       ) {
-      return &quot;I&#39;m &quot;+state+&quot;, thank you.&quot;;
-    }
-    return null;
-  }
-}</programlisting>
-      <para>The class above reveals that it contains two fields named <literal>state</literal> and <literal>session</literal>
-      and that the method <literal>hello</literal> accepts one argument. During the execution the values specified in the 
-      <literal>field</literal> and <literal>arg</literal> configuration elements will be used. The expected result of creating
-      a process instance is that the process variable <literal>answer</literal> contains the string
-      <literal>I'm fine, thank you.</literal>.
-      </para>
-    </section>
-
     <!-- ### TASK ########################################################## -->
 
     <section id="task">
@@ -1250,7 +1125,141 @@
 taskService.setVariables(taskDbid, variables);</programlisting>
       </section>
     </section>
+  </section>
+  
+  <!-- ##################################################################### -->
+  <!-- ### AUTOMATIC ACTIVITIES                                          ### -->
+  <!-- ##################################################################### -->
+  
+  <section id="automaticactivities">
+    <title>Automatic activities</title>
 
+    <!-- ### JAVA ########################################################## -->
+      
+    <section id="java">
+      <title><literal>java</literal></title>
+      <para>The Java task. A process execution will execute the method of the class that is configured
+      in this activity.</para> 
+      <table><title><literal>java</literal> attributes:</title>
+        <tgroup cols="5" rowsep="1" colsep="1">
+          <thead>
+            <row>
+              <entry>Attribute</entry>
+              <entry>Type</entry>
+              <entry>Default</entry>
+              <entry>Required?</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry><literal>class</literal></entry>
+              <entry>classname</entry>
+              <entry></entry>
+              <entry><emphasis role="bold">required</emphasis></entry>
+              <entry>The fully qualified classname.</entry>
+            </row>
+            <row>
+              <entry><literal>method</literal></entry>
+              <entry>methodname</entry>
+              <entry></entry>
+              <entry><emphasis role="bold">required</emphasis></entry>
+              <entry>The name of the method to invoke</entry>
+            </row>
+            <row>
+              <entry><literal>var</literal></entry>
+              <entry>variablename</entry>
+              <entry></entry>
+              <entry>optional</entry>
+              <entry>The name of the variable in which the return value 
+              should be stored.
+              </entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </table>
+      <table><title><literal>java</literal> elements:</title>
+        <tgroup cols="3" rowsep="1" colsep="1">
+          <thead>
+            <row>
+              <entry>Element</entry>
+              <entry>Multiplicity</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry><literal>field</literal></entry>
+              <entry>0..*</entry>
+              <entry>describes a configuration value to inject in a memberfield before 
+              the method is invoked.</entry>
+            </row>
+            <row>
+              <entry><literal>arg</literal></entry>
+              <entry>0..*</entry>
+              <entry>method parameters</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </table>
+      <para>Consider the following example.</para>
+      <figure id="process.java">
+        <title>A java task</title>
+        <mediaobject><imageobject><imagedata align="center" fileref="images/process.java.png"/></imageobject></mediaobject>
+      </figure>
+      <programlisting>&lt;process name=&quot;Java&quot; xmlns=&quot;http://jbpm.org/4/jpdl&quot;&gt;
+
+  &lt;start&gt;
+    &lt;transition to=&quot;invoke java method&quot; /&gt;
+  &lt;/start&gt;
+
+  &lt;java name=&quot;invoke java method&quot; 
+        class=&quot;org.jbpm.examples.java.JohnDoe&quot;
+        method=&quot;hello&quot;
+        var=&quot;answer&quot;&gt;
+        
+    &lt;field name=&quot;state&quot;&gt;&lt;string value=&quot;fine&quot;/&gt;&lt;/field&gt;
+    &lt;field name=&quot;session&quot;&gt;&lt;env type=&quot;org.hibernate.Session&quot;/&gt;&lt;/field&gt;
+
+    &lt;arg&gt;&lt;string value=&quot;Hi, how are you?&quot;/&gt;&lt;/arg&gt;
+    
+    &lt;transition to=&quot;wait&quot; /&gt;
+  &lt;/java&gt;
+  
+  &lt;state name=&quot;wait&quot;&gt;
+
+&lt;/process&gt;
+      </programlisting>
+      <para>The java task specifies that during its execution an instance of the class <literal>org.jbpm.examples.java.JohnDoe</literal>
+      will be instantiated and the method <literal>hello</literal> of this class will be invoked on the resulting object. The variable named
+      <literal>answer</literal> will contain the result of the invocation. Let's look at the class <literal>JohnDoe</literal> below.
+      </para>
+      <programlisting>package org.jbpm.examples.java;
+
+import org.hibernate.Session;
+
+public class JohnDoe {
+  
+  String state;
+  Session session;
+  
+  public String hello(String msg) {
+    if ( (msg.indexOf(&quot;how are you?&quot;)!=-1)
+         &amp;&amp; (session.isOpen())
+       ) {
+      return &quot;I&#39;m &quot;+state+&quot;, thank you.&quot;;
+    }
+    return null;
+  }
+}</programlisting>
+      <para>The class above reveals that it contains two fields named <literal>state</literal> and <literal>session</literal>
+      and that the method <literal>hello</literal> accepts one argument. During the execution the values specified in the 
+      <literal>field</literal> and <literal>arg</literal> configuration elements will be used. The expected result of creating
+      a process instance is that the process variable <literal>answer</literal> contains the string
+      <literal>I'm fine, thank you.</literal>.
+      </para>
+    </section>
+
     <!-- ### SCRIPT ######################################################## -->
 
     <section id="script">
@@ -1642,55 +1651,193 @@
       <literal>session.createSQLQuery(...)</literal> is used.   
       </para>
     </section>
+  </section>
 
-    <section id="commonactivitycontents">
-      <title>Common activity contents</title>
-      <para>Unless specified otherwise above, all activities also include this 
-      content model:
-      </para>
-      <table><title>Common activity attributes:</title>
-        <tgroup cols="5" rowsep="1" colsep="1">
-          <thead>
-            <row>
-              <entry>Attribute</entry>
-              <entry>Type</entry>
-              <entry>Default</entry>
-              <entry>Required?</entry>
-              <entry>Description</entry>
-            </row>
-          </thead>
-          <tbody>
-            <row>
-              <entry><literal>name</literal></entry>
-              <entry>any text</entry>
-              <entry></entry>
-              <entry><emphasis role="bold">required</emphasis></entry>
-              <entry>name of the activity</entry>
-            </row>
-          </tbody>
-        </tgroup>
-      </table>
-      <table><title>Common activity elements:</title>
-        <tgroup cols="3" rowsep="1" colsep="1">
-          <thead>
-            <row>
-              <entry>Element</entry>
-              <entry>Multiplicity</entry>
-              <entry>Description</entry>
-            </row>
-          </thead>
-          <tbody>
-            <row>
-              <entry><literal>transition</literal></entry>
-              <entry>0..*</entry>
-              <entry>the outgoing transitions</entry>
-            </row>
-          </tbody>
-        </tgroup>
-      </table>
-    </section>
+  <!-- ##################################################################### -->
+  <!-- ### COMMON ACTIVITY CONTENTS                                      ### -->
+  <!-- ##################################################################### -->
+
+  <section id="commonactivitycontents">
+    <title>Common activity contents</title>
+    <para>Unless specified otherwise above, all activities also include this 
+    content model:
+    </para>
+    <table><title>Common activity attributes:</title>
+      <tgroup cols="5" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Attribute</entry>
+            <entry>Type</entry>
+            <entry>Default</entry>
+            <entry>Required?</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry><literal>name</literal></entry>
+            <entry>any text</entry>
+            <entry></entry>
+            <entry><emphasis role="bold">required</emphasis></entry>
+            <entry>name of the activity</entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
+    <table><title>Common activity elements:</title>
+      <tgroup cols="3" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Element</entry>
+            <entry>Multiplicity</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry><literal>transition</literal></entry>
+            <entry>0..*</entry>
+            <entry>the outgoing transitions</entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
   </section>
 
+  <!-- ##################################################################### -->
+  <!-- ### EVENTS                                                        ### -->
+  <!-- ##################################################################### -->
+
+  <section id="events">
+    <title>Events</title>
+    <para>Events specify points in a process on which a list of event listeners can be registered.
+    When an execution passes that point in the process, the event listeners are notified.
+    The events and listeners are not shown in the graphical view of the process. An event 
+    is fired by an element in the process definition like e.g. the process definition, 
+    an activity or a transition.  
+    </para>
+    <para>The EventListener interface looks like this:
+    </para>
+    <programlisting>public interface <emphasis role="bold">EventListener</emphasis> extends Serializable {
+  
+  void notify(EventListenerExecution execution) throws Exception;
+
+}</programlisting>
+    <para>All <link linkend="automaticactivities">automatic activities</link> can be used as 
+    event listeners as well.</para>
+    <para>To associate a list of event listeners with a process or an activity, use 
+    the <literal>on</literal> element to group the event listeners and specifiy the 
+    event.  <literal>on</literal> can be nested as a subelement of <literal>process</literal>
+    or any activity.
+    </para>
+    <para>To associate a list of event listeners with a transition <literal>take</literal> 
+    event, just include the event listeners directly in the <literal>transition</literal> 
+    element. 
+    </para>
+    <table><title><literal>on</literal> attributes:</title>
+      <tgroup cols="5" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Attribute</entry>
+            <entry>Type</entry>
+            <entry>Default</entry>
+            <entry>Required?</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry><literal>event</literal></entry>
+            <entry>{start | end}</entry>
+            <entry></entry>
+            <entry><emphasis role="bold">required</emphasis></entry>
+            <entry>name name of the event</entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
+    <table><title><literal>on</literal> elements:</title>
+      <tgroup cols="3" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Element</entry>
+            <entry>Multiplicity</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry><literal>event-listener</literal></entry>
+            <entry>0..*</entry>
+            <entry>An event listener implementation object.</entry>
+          </row>
+          <row>
+            <entry>any automatic activity</entry>
+            <entry>0..*</entry>
+            <entry></entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
+    <para>Let's look at an example process with event listeners:</para>
+    <figure id="process.eventlistener">
+      <title>The event listener example process</title>
+      <mediaobject><imageobject><imagedata align="center" fileref="images/process.eventlistener.png"/></imageobject></mediaobject>
+    </figure>
+    <programlisting>&lt;process name=&quot;EventListener&quot; xmlns=&quot;http://jbpm.org/4/jpdl&quot;&gt;
+
+  <emphasis role="bold">&lt;on event=&quot;start&quot;&gt;
+    &lt;event-listener class=&quot;org.jbpm.examples.eventlistener.LogListener&quot;/&gt;
+  &lt;/on&gt;
+
+  &lt;on event=&quot;end&quot;&gt;
+    &lt;event-listener class=&quot;org.jbpm.examples.eventlistener.LogListener&quot;/&gt;
+  &lt;/on&gt;</emphasis>
+
+
+  &lt;start&gt;
+    &lt;transition to=&quot;wait&quot; name=&quot;&quot;/&gt;
+  &lt;/start&gt;
+
+  &lt;state name=&quot;wait&quot;&gt;
+    <emphasis role="bold">&lt;on event=&quot;start&quot;&gt;
+      &lt;event-listener class=&quot;org.jbpm.examples.eventlistener.LogListener&quot;/&gt;
+    &lt;/on&gt;
+    &lt;on event=&quot;end&quot;&gt;
+      &lt;event-listener class=&quot;org.jbpm.examples.eventlistener.LogListener&quot;/&gt;
+    &lt;/on&gt;</emphasis>
+
+    &lt;transition to=&quot;end&quot; name=&quot;&quot;&gt;
+      &lt;event-listener class=&quot;org.jbpm.examples.eventlistener.LogListener&quot;/&gt;
+    &lt;/transition&gt;
+  &lt;/state&gt;
+  
+  &lt;end name=&quot;end&quot;/&gt;
+
+&lt;/process&gt;</programlisting>
+    <para><literal>LogListener</literal>  will maintain a list of logs in a static member 
+    field:</para>
+    <programlisting>public class <emphasis role="bold">LogListener</emphasis> implements EventListener {
+  
+  public static List&lt;String&gt; logs; // initialization done in test method
+
+  public void notify(EventListenerExecution execution) {
+    logs.add(execution.getEvent()+&quot; on &quot;+execution.getEventSource());
+  }
+}</programlisting>
+    <para>Next, we start a new process instance.</para>
+    <programlisting>Execution execution = executionService.startProcessInstanceByKey(&quot;EventListener&quot;);</programlisting>
+    <para>Then the process instance executes up to the wait activity.  So we provide a signal 
+    and that will cause it to execute till the end.</para>
+    <programlisting>executionService.signalExecutionById(execution.getId());</programlisting>
+    <para>The list of log messages will now look like this:</para>
+    <programlisting>[event(start) on process(EventListener),
+ event(start) on activity(wait),
+ event(end) on activity(wait),
+ event(take) on (wait)-->(end),
+ event(end) on process(EventListener)]</programlisting>
+  </section>
+
   <section id="usercode">
     <title>User code</title>
     <para>Various elements in the jPDL process language refer to a an 




More information about the jbpm-commits mailing list