[jbpm-commits] JBoss JBPM SVN: r2279 - in jbpm4/pvm/trunk/modules: core/src/test/java/org/jbpm/pvm/example04 and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Sep 18 09:55:29 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-09-18 09:55:29 -0400 (Thu, 18 Sep 2008)
New Revision: 2279
Added:
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/Display.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/DisplayActivityTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/TestConsole.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/ExternalActivityExampleTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/WaitState.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example06/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example06/BasicProcessExecutionTest.java
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.archive.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.end.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.evaluate.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.ab.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.loan.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-ImplementingBasicActivities.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch05-ProcessAnatomy.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch06-ImplementingAdvancedActivities.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch07-Variables.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch08-Timers.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch09-AsynchronousContinuations.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch10-SoftwareLogging.xml
Removed:
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.accept.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.end.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.evaluation.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.process.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.png
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-BasicProcessExecutionConcepts.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AdvancedGraphExecution.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AsynchronousContinuations.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-SoftwareLogging.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Timers.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Variables.xml
Modified:
jbpm4/pvm/trunk/modules/manual/src/main/diagrams/diagrams.mdzip
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/master.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch01-Introduction.xml
jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml
Log:
docs
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/Display.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/Display.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/Display.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.example04;
+
+import org.jbpm.pvm.activity.Activity;
+import org.jbpm.pvm.activity.ActivityExecution;
+
+public class Display implements Activity {
+
+ private static final long serialVersionUID = 1L;
+
+ String message;
+
+ public Display(String message) {
+ this.message = message;
+ }
+
+ public void execute(ActivityExecution execution) {
+ System.out.println(message);
+ }
+}
\ No newline at end of file
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/DisplayActivityTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/DisplayActivityTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/DisplayActivityTest.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,34 @@
+package org.jbpm.pvm.example04;
+
+import org.jbpm.pvm.Execution;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.test.base.JbpmTestCase;
+
+
+public class DisplayActivityTest extends JbpmTestCase {
+
+ TestConsole testConsole;
+
+ public void setUp() {
+ testConsole = TestConsole.install();
+ }
+
+ public void tearDown() {
+ TestConsole.uninstall();
+ testConsole = null;
+ }
+
+ public void testHelloWorld() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new Display("hello"))
+ .transition().to("b")
+ .node("b").behaviour(new Display("world"))
+ .done();
+
+ Execution execution = processDefinition.startProcessInstance();
+
+ assertEquals("hello", testConsole.getLine(0));
+ assertEquals("world", testConsole.getLine(1));
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/TestConsole.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/TestConsole.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example04/TestConsole.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,38 @@
+package org.jbpm.pvm.example04;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/** wraps the System.out and buffers the println(String) invocations
+ * so that those can be asserted */
+public class TestConsole extends PrintStream {
+
+ List<String> lines = new ArrayList<String>();
+
+ public TestConsole() {
+ super(System.out);
+ }
+
+ public static TestConsole install() {
+ TestConsole testConsole = new TestConsole();
+ System.setOut(testConsole);
+ return testConsole;
+ }
+
+ public static void uninstall() {
+ if (System.out instanceof TestConsole) {
+ TestConsole testConsole = (TestConsole) System.out;
+ System.setOut((PrintStream) testConsole.out);
+ }
+ }
+
+ public void println(String x) {
+ lines.add(x);
+ super.println(x);
+ }
+
+ public String getLine(int i) {
+ return lines.get(i);
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/ExternalActivityExampleTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/ExternalActivityExampleTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/ExternalActivityExampleTest.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,27 @@
+package org.jbpm.pvm.example05;
+
+import org.jbpm.pvm.client.ClientExecution;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.test.base.JbpmTestCase;
+
+
+public class ExternalActivityExampleTest extends JbpmTestCase {
+
+ public void testExternalActivityExample() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("a", execution.getNodeName());
+
+ execution.signal();
+
+ assertEquals("b", execution.getNodeName());
+ }
+
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/WaitState.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/WaitState.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example05/WaitState.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,21 @@
+package org.jbpm.pvm.example05;
+
+import java.util.Map;
+
+import org.jbpm.pvm.activity.ActivityExecution;
+import org.jbpm.pvm.activity.ExternalActivity;
+
+public class WaitState implements ExternalActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) {
+ execution.waitForSignal();
+ }
+
+ public void signal(ActivityExecution execution,
+ String signalName,
+ Map<String, Object> parameters) {
+ execution.take(signalName);
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example06/BasicProcessExecutionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example06/BasicProcessExecutionTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/example06/BasicProcessExecutionTest.java 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,32 @@
+package org.jbpm.pvm.example06;
+
+import org.jbpm.pvm.client.ClientExecution;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.example04.Display;
+import org.jbpm.pvm.example05.WaitState;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.test.base.JbpmTestCase;
+
+
+public class BasicProcessExecutionTest extends JbpmTestCase {
+
+ public void testBasicProcessExecution() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
+ .node("submit loan request").initial().behaviour(new Display("loan request submitted"))
+ .transition().to("evaluate")
+ .node("evaluate").behaviour(new WaitState())
+ .transition("approve").to("wire money")
+ .transition("reject").to("end")
+ .node("wire money").behaviour(new Display("wire the money"))
+ .transition().to("archive")
+ .node("archive").behaviour(new WaitState())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+
+
+ }
+}
Modified: jbpm4/pvm/trunk/modules/manual/src/main/diagrams/diagrams.mdzip
===================================================================
(Binary files differ)
Added: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.archive.png
===================================================================
(Binary files differ)
Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.archive.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.end.png
===================================================================
(Binary files differ)
Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.end.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.evaluate.png
===================================================================
(Binary files differ)
Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.loan.evaluate.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.accept.png
===================================================================
(Binary files differ)
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.end.png
===================================================================
(Binary files differ)
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/execution.state.evaluation.png
===================================================================
(Binary files differ)
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.process.png
===================================================================
(Binary files differ)
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.ab.png (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.png)
===================================================================
(Binary files differ)
Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.ab.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:mergeinfo
+
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.loan.png (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.process.png)
===================================================================
(Binary files differ)
Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.loan.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:mergeinfo
+
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/process.png
===================================================================
(Binary files differ)
Modified: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/master.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/master.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/master.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -4,7 +4,13 @@
<!ENTITY ch01-Introduction SYSTEM "modules/ch01-Introduction.xml">
<!ENTITY ch02-ExecutionModes SYSTEM "modules/ch02-ExecutionModes.xml">
<!ENTITY ch03-Architecture SYSTEM "modules/ch03-Architecture.xml">
- <!ENTITY ch04-BasicProcessExecutionConcepts SYSTEM "modules/ch04-BasicProcessExecutionConcepts.xml">
+ <!ENTITY ch04-ImplementingBasicActivities SYSTEM "modules/ch04-ImplementingBasicActivities.xml">
+ <!ENTITY ch05-ProcessAnatomy SYSTEM "modules/ch05-ProcessAnatomy.xml">
+ <!ENTITY ch06-ImplementingAdvancedActivities SYSTEM "modules/ch06-ImplementingAdvancedActivities.xml">
+ <!ENTITY ch07-Variables SYSTEM "modules/ch07-Variables.xml">
+ <!ENTITY ch08-Timers SYSTEM "modules/ch08-Timers.xml">
+ <!ENTITY ch09-AsynchronousContinuations SYSTEM "modules/ch09-AsynchronousContinuations.xml">
+ <!ENTITY ch10-SoftwareLogging SYSTEM "modules/ch10-SoftwareLogging.xml">
]>
<book lang="en">
@@ -21,6 +27,12 @@
&ch01-Introduction;
&ch02-ExecutionModes;
&ch03-Architecture;
- &ch04-BasicProcessExecutionConcepts;
+ &ch04-ImplementingBasicActivities;
+ &ch05-ProcessAnatomy;
+ &ch06-ImplementingAdvancedActivities;
+ &ch07-Variables;
+ &ch08-Timers;
+ &ch09-AsynchronousContinuations;
+ &ch10-SoftwareLogging;
</book>
\ No newline at end of file
Modified: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch01-Introduction.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch01-Introduction.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch01-Introduction.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -24,7 +24,7 @@
</para>
<figure id="example.process.graph">
<title>Example process definition</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/loan.process.png"/></imageobject></mediaobject>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.loan.png"/></imageobject></mediaobject>
</figure>
<para>Typically, process definitions are static. A process definition is composed of
nodes and transitions. The runtime behaviour of a node is encapsulated in a so called
Modified: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -25,7 +25,7 @@
</para>
<figure id="loan.process">
<title>The loan process</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/loan.process.png"/></imageobject></mediaobject>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.loan.png"/></imageobject></mediaobject>
</figure>
<programlisting>ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
.node("submit loan request").initial().behaviour(AutomaticActivity.class)
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-BasicProcessExecutionConcepts.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-BasicProcessExecutionConcepts.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-BasicProcessExecutionConcepts.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,544 +0,0 @@
-<chapter id="basicprocessexecutionconcepts">
- <title>Basic process execution concepts</title>
-
- <para>This chapter explains the basics of process definitions, the features offered by
- the Process Virtual Machine and how activity implementations can be build. At the same
- time the client API is shown to execute processes with those activity implementations.
- </para>
-
- <!-- ### Activity ####################################################### -->
- <section id="activity">
- <title>Activity</title>
- <para>The PVM library doesn't have a fixed set of process constructs.
- Instead, runtime behaviour of a node is delegated to an <literal>Activity</literal>.
- In other words, <literal>Activity</literal> is an interface to implement the runtime
- behaviour of process constructs in plain Java.
- </para>
- <programlisting>public <emphasis role="bold">interface Activity</emphasis> extends Serializable {
-
- void <emphasis role="bold">execute</emphasis>(ActivityExecution execution) throws Exception;
-
-}</programlisting>
- <para>When an activity is used as the node behaviour, it is in full control of the further
- propagation of the execution. In other words, a node behaviour can decide what the execution
- should do next. For example, it can take a transition with
- <literal>execution.take(Transition)</literal> or go into a wait state with
- <literal>execution.waitForSignal()</literal>. In case the node behaviour does not invoke
- any of the above execution propagation methods, the execution will
- <link linkend="defaultproceedbehaviour">proceed in a default way</link>.
- </para>
- </section>
-
- <!-- ### Activity example ############################################### -->
- <section id="activityexample">
- <title>Activity example</title>
- <para>We'll start with a very original hello world example. A Display
- activity will print a message to the console:
- </para>
- <programlisting>public <emphasis role="bold">class Display</emphasis> implements <emphasis role="bold">Activity</emphasis> {
-
- String message;
-
- public Display(String message) {
- this.message = message;
- }
-
- public void execute(ActivityExecution execution) {
- <emphasis role="bold">System.out.println(message);</emphasis>
- }
-}</programlisting>
- <para>Let' build our first process definition with this activity:</para>
- <figure id="activity.example">
- <title>Activity example process</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/process.png"/></imageobject></mediaobject>
- </figure>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build()
- .<emphasis role="bold">node("a").initial()</emphasis>.behaviour(<emphasis role="bold">new Display("hello")</emphasis>)
- .transition().to("b")
- .<emphasis role="bold">node("b")</emphasis>.behaviour(<emphasis role="bold">new Display("world")</emphasis>)
-.done();</programlisting>
- <para>Now we can execute this process as follows:</para>
- <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
- <para>The invocation of <literal>startExecution</literal> will print hello world to the console:</para>
- <programlisting>hello
-world</programlisting>
- <para>One thing already worth noticing is that activities can be configured
- with properties. In the Display example, you can see that the message property
- is configured differently in the two usages. With configuration properties
- it becomes possible to write reusable activities. They can then be configured
- differently each time they are used in a process. That is an essential part of
- how process languages can be build on top of the Process Virtual Machine.
- </para>
- </section>
-
- <!-- ### ExternalActivity ############################################### -->
- <section id="externalactivity">
- <title>ExternalActivity</title>
- <para>External activities are activities for which the responsibility for proceeding
- the execution is transferred externally, meaning outside the process system. This
- means that for the system that is executing the process, it's a wait state. The
- execution will wait until an external trigger is given.
- </para>
- <para>For dealing with external triggers, <literal>ExternalActivity</literal>
- adds two methods to the <literal>Activity</literal>:</para>
- <programlisting>public <emphasis role="bold">interface ExternalActivity</emphasis> extends <emphasis role="bold">Activity</emphasis> {
-
- void <emphasis role="bold">signal</emphasis>(Execution execution,
- String signal,
- Map<String, Object> parameters) throws Exception;
-
-}</programlisting>
- <para>Just like with plain activities, when an execution arrives in a node, the
- <literal>execute</literal>-method of the node behaviour is invoked.
- In external activities, the execute method typically does something to
- transfer the responsibility to another system and then enters a wait
- state by invoking <literal>execution.waitForSignal()</literal>. For
- example in the execute method, responsibility could be transferred to a
- person by creating a task entry in a task management system and then
- wait until the person completes the task.
- </para>
- <para>In case a node behaves as a wait state, then the execution will
- wait in that node until the execution's <literal>signal</literal> method
- is invoked. The execution will delegate that signal to the behaviour Activity
- of the current node.
- </para>
- <para>So the Activity's <literal>signal</literal>-method is invoked
- when the execution receives an external trigger during the wait state. With the
- signal method, responsibility is transferred back to the process execution. For
- example, when a person completes a task, the task management system calls the
- signal method on the execution.
- </para>
- <para>A signal can optionally have a signal name and a map of parameters. Most
- common way on how node behaviours interprete the signal and parameters is that
- the signal relates to the outgoing transition that needs to be taken and that the
- parameters are set as variables on the execution. But those are just examples, it
- is up to the activity to use the signal and the parameters as it pleases.
- </para>
- </section>
-
- <!-- ### ExternalActivity example ####################################### -->
- <section id="externalactivityexample">
- <title>ExternalActivity example</title>
- <para>Here's a first example of a simple wait state implementation:
- </para>
- <programlisting>public <emphasis role="bold">class WaitState</emphasis> implements ExternalActivity {
-
- public void <emphasis role="bold">execute</emphasis>(Execution execution) {
- execution.waitForSignal();
- }
-
- public void <emphasis role="bold">signal</emphasis>(Execution execution,
- String signal,
- Map<String, Object> parameters) {
- execution.take(signal);
- }
-}</programlisting>
- <para>The <literal>execute</literal>-method calls
- <literal>execution.waitForSignal()</literal>. This call is
- necessary to prevent automatic propagation of the execution. By calling
- <literal>execution.waitForSignal()</literal>, the node will
- behave as a wait state.
- </para>
- <para><literal>signal</literal>-method takes the transition with
- the signal parameter as the transition name. So when an execution receives an
- external trigger, the signal name is interpreted as the name of an outgoing
- transition and the execution will be propagated over that transition.
- </para>
- <para>Here's the same simple process that has a transition from a to b. This
- time, the behaviour of the two nodes will be WaitState's.
- </para>
- <figure id="process.diagram">
- <title>Process diagram</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/process.png"/></imageobject></mediaobject>
- </figure>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build()
- .<emphasis role="bold">node("a").initial()</emphasis>.behaviour(<emphasis role="bold">new WaitState()</emphasis>)
- .transition().to("b")
- .<emphasis role="bold">node("b")</emphasis>.behaviour(<emphasis role="bold">new WaitState()</emphasis>)
-.done();</programlisting>
-
-<programlisting>Execution execution = processDefinition.startExecution();</programlisting>
-<programlisting>execution.signal();</programlisting>
- </section>
-
- <!-- ### BASIC PROCESS EXECUTION ######################################## -->
- <section id="basicprocessexecution">
- <title>Basic process execution</title>
- <para>In this next example, we'll combine automatic activities and wait states.
- This example is a simplified version of a loan approval process. Graphically,
- it looks like this:
- </para>
- <figure id="the.first.graph.process">
- <title>The first graph process</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/first.graph.process.png"/></imageobject></mediaobject>
- </figure>
- <para>Building process graphs in Java code can be tedious because you have to keep track of all the
- references in local variables. To resolve that, the Process Virtual Machine comes with a
- ProcessFactory. The ProcessFactory is a kind of domain specific language (DSL) that is embedded
- in Java and eases the construction of process graphs. This pattern is also known as
- a <ulink url="http://martinfowler.com/bliki/FluentInterface.html">fluent
- interface</ulink>.
- </para>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build()
- .<emphasis role="bold">node("accept loan request").initial()</emphasis>.behaviour(new WaitState())
- .transition().to("loan evaluation")
- .<emphasis role="bold">node("loan evaluation")</emphasis>.behaviour(new WaitState())
- .transition("approve").to("wire the money")
- .transition("reject").to("end")
- .<emphasis role="bold">node("wire the money")</emphasis>.behaviour(new Display("automatic payment"))
- .transition().to("end")
- .<emphasis role="bold">node("end")</emphasis>.behaviour(new WaitState())
-.done();</programlisting>
- <para>For more details about the ProcessFactory, see the javadocs. An alternative for
- the ProcessFactory would be to create an XML language and an XML parser for expressing
- processes. The XML parser can then instantiate the classes of package
- <literal>org.jbpm.pvm.internal.model</literal> directly. That approach is typically taken by
- process languages.
- </para>
- <para>The node <literal>wire the money</literal> is an automatic node. The
- <literal>Display</literal> implementation uses the Java API's to just print a
- message to the console. But the witty reader can imagine an alternative
- <literal>Activity</literal> implementation that uses the Java API of a payment
- processing library to make a real automatic payment. All the other nodes are
- wait states.
- </para>
- <para>A new execution for the process above can be started like this
- </para>
- <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
- <para>Starting a new execution implies that the initial node is executed. Since in
- this case it's a wait state, the new execution will be positioned in the
- node 'accept loan request' when the <literal>startExecution</literal>-method returns.
- </para>
- <figure id="first.execution.state.accept">
- <title>Execution positioned in 'accept loan request'</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/execution.state.accept.png"/></imageobject></mediaobject>
- </figure>
- <para>Now we can give this execution an external trigger with the <literal>signal</literal>-
- method on the execution. Invoking the signal method will take the execution to the next
- wait state.
- </para>
- <programlisting>execution.signal();</programlisting>
- <figure id="execution.state.evaluation">
- <title>Execution positioned in 'loan evaluation'</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/execution.state.evaluation.png"/></imageobject></mediaobject>
- </figure>
- <para>Now, the execution is at an interesting point. There are two transitions out of
- the state 'loan evaluation'. One transition is called 'approve' and one transition
- is called 'reject'. As we explained above in the WaitState implementation, the transition
- taken corresponds to the signal that is given. Let's feed in the 'approve' signal like this:
- </para>
- <programlisting>execution.signal("approve");</programlisting>
- <para>The 'approve' signal will cause the execution to take the 'approve' transition and
- it will arrive in the node 'wire the money'.
- </para>
- <para>In <literal>wire the money</literal>, the message will be printed to the console.
- Since, the <literal>Display</literal> activity didn't invoke the
- <literal>execution.waitForSignal()</literal>, nor any of the other execution propagation
- methods, the default behaviour will be to just proceed.
- </para>
- <para><link linkend="defaultproceedbehaviour">Proceeding</link> in this case means that
- the default outgoing transition is taken and the execution will arrive in the <literal>end</literal>
- node, which is a wait state.</para>
- <para>So only when the <literal>end</literal> wait state is reached, the <literal>signal("approve")</literal>
- returns. That is because all of the things that needed to be done between the original
- state and this new state could be executed by the process system. Executing till the
- next wait state is the default behaviour and that behaviour can be changed with
- </para>
- <para><emphasis role="bold">TODO: add link to async continuations</emphasis></para>
- <para>asynchronous continuations in case
- transactions should not include all calculations till the next wait state. For
- more about this, see <xref linkend="executionandthreads" />.
- </para>
- <para>Another signal invocation will bring it eventually in the end state.</para>
- <figure id="execution.state.end">
- <title>Execution positioned in 'end'</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/execution.state.end.png"/></imageobject></mediaobject>
- </figure>
- </section>
-
- <!-- ### MOTIVATION ##################################################### -->
- <section id="motivation">
- <title>Motivation</title>
- <para>There are basically two forms of process languages: graph based and composite
- process languages. First of all, this design supports both. Even graph based execution
- and node composition can be used in combination to implement something like UML super states.
- </para>
- <para>In this design, control flow activity implementations will have to be
- aware of whether they are dependent on transitions (graph based) or whether they are
- using the composite node structure. The goal of this design is that all non-control
- flow activities can be implemented in the same way so that you can use them in graph
- based process languages as well as in composite process languages.
- </para>
- </section>
-
- <!-- ### EVENTS ######################################################### -->
- <section id="events">
- <title>Events</title>
- <para>Events are points in the process definition to which a list of
- activities can be subscribed as listeners. The motivation for events is to allow for
- developers to add programming logic to a process without changing the process diagram.
- This is a very valuable instrument in
- facilitating the collaboration between business analysts and developers. Business analysts
- are responsible for expressing the requirements. When they use a process graph to document
- those requirements, developers can take this diagram and make it executable. Events can
- be a very handy to insert technical details into a process (like e.g. some database insert)
- in which the business analyst is not interested.
- </para>
- <para>Most common events are fired by the execution automatically:
- </para>
- <itemizedlist>
- <listitem><literal>Transition.EVENT_TRANSITION_TAKE = "transition-take"</literal> :
- fired on transitions when transitions are taken.
- </listitem>
- <listitem><literal>Node.EVENT_NODE_ENTER = "node-enter"</literal> : fired on the node
- when execution enters that node. This happens when execution takes a transition
- to that node, when a child node is being executed with <literal>execution.execute(Node)</literal>
- or when a transition is taken from a node outside that node to a contained node.
- The latter refers to super states in state machines.
- </listitem>
- <listitem><literal>Node.EVENT_NODE_LEAVE = "node-leave"</literal> : fired on the node
- when a transition is taken out of that node or when a child node execution is
- finished and the execution is propagated to the parent node.
- </listitem>
- <listitem><literal>ProcessDefinition.EVENT_PROCESS_START = "process-start"</literal> : fired on a process
- when a new process is started.
- </listitem>
- <listitem><literal>ProcessDefinition.EVENT_PROCESS_END = "process-end"</literal> : fired on a process
- when a new process is ended. This might include a executions that are ended
- with a cancelled or error state.
- </listitem>
- </itemizedlist>
- <para>Events are identified by the combination of a process element
- and an event name. Users and process languages can also fire events
- programmatically with the fire method on the Execution:
- </para>
- <programlisting>public interface Execution extends Serializable {
- ...
- void fire(String eventName, ProcessElement eventSource);
- ...
-}</programlisting>
-
- <para>A list of <link linkend="activity"><literal>Activity</literal>s</link> can be associated to an
- event. But activities on events can not influence the control flow of the execution since
- they are merely listeners to an execution wich is already in progress. This is different from
- activities that serve as the behaviour for nodes. Node behaviour activities are responsible
- for propagating the execution. So if an activity in an event invokes any of the
- following methods, then it will result in an exception.
- </para>
-
- <itemizedlist>
- <listitem><literal>waitForSignal()</literal></listitem>
- <listitem><literal>take(Transition)</literal></listitem>
- <listitem><literal>end(*)</literal></listitem>
- <listitem><literal>execute(Node)</literal></listitem>
- </itemizedlist>
-
- <para>We'll reuse the <literal><link linkend="activity">Display</link></literal>
- activity from above in a simple process: two nodes connected by a
- transition. The Display listener will be subscribed to the transition event.</para>
- <figure id="action.process">
- <title>The process to which a listener activity will be associated</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/process.png"/></imageobject></mediaobject>
- </figure>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- <emphasis role="bold">.event("node-leave")
- .listener(new Display("leaving a"))
- .listener(new Display("second message while leaving a"))</emphasis>
- .transition().to("b")
- <emphasis role="bold">.listener(new Display("taking transition"))</emphasis>
- .node("b").behaviour(new WaitState())
- <emphasis role="bold">.event("node-enter")
- .listener(new Display("entering b"))</emphasis>
-.done();</programlisting>
- <para>The first event shows how to register multiple listeners to the same
- event. They will be notified in the order as they are specified.
- </para>
- <para>Then, on the transition, there is only one type of event. So in that case,
- the event type must not be specified and the listeners can be added directly on
- the transition.
- </para>
- <para>A listeners will be called each time an execution fires the event to
- which the listener is subscribed. The execution will be provided in the activity
- interface as a parameter and can be used by listeners except for the methods that
- control the propagation of execution.
- </para>
- </section>
-
- <!-- ### EVENT PROPAGATION ############################################## -->
- <section>
- <title>Event propagation</title>
- <para>Events are by default propagated to enclosing process elements. The motivation
- is to allow for listeners on process definitions or composite nodes that get executed
- for all events that occur within that process element. For example this feature
- allows to register a listener on a process definition or a composite node on
- <literal>node-leave</literal> events. Such action will be executed if that node is
- left. And if that listener is registered on a composite node, it will also be executed
- for all nodes that are left within that composite node.
- </para>
- <para>To show this clearly, we'll create a <literal>DisplaySource</literal> activity
- that will print the message <literal>leaving</literal> and the source of the event
- to the console.
- </para>
- <programlisting>public class <emphasis role="bold">DisplaySource</emphasis> implements Activity {
-
- public void execute(Execution execution) {
- <emphasis role="bold">System.out.println("leaving "+execution.getEventSource());</emphasis>
- }
-}</programlisting>
- <para>Note that the purpose of event listeners is not to be visible, that's why the activity
- itself should not be displayed in the diagram. A <literal>DisplaySource</literal> activity
- will be added as a listener to the event <literal>node-leave</literal> on the composite node.
- </para>
- <para>The next process shows how the <literal>DisplaySource</literal> activity is registered
- as a listener to to the 'node-leave' event on the <literal>composite</literal> node:</para>
- <figure id="propagation.process">
- <title>A process with an invisible activity on a node-leave event on a composite node.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/propagation.process.png"/></imageobject></mediaobject>
- </figure>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .compositeNode("composite")
- <emphasis role="bold">.event(Node.EVENT_NODE_LEAVE)
- .listener(new DisplaySource())</emphasis>
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .transition().to("c")
- .compositeEnd()
- .node("c").behaviour(new WaitState())
-.done();</programlisting>
- <para>Next we'll start an execution.</para>
- <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
- <para>After starting a new execution, the execution will be in node <literal>a</literal> as
- that is the initial node. No nodes have been left so no message is logged. Next a signal
- will be given to the execution, causing it to take the transition from <literal>a</literal>
- to <literal>b</literal>.
- </para>
- <programlisting>execution.signal();</programlisting>
- <para>When the signal method returns, the execution will have taken the transition and
- the node-leave event will be fired on node a. That event will be propagated to the
- composite node and to the process definition. Since our propagation logger is placed
- on node composite it will receive the event and print the following message:
- </para>
- <programlisting>leaving node(a)</programlisting>
- <para>Another</para>
- <programlisting>execution.signal();</programlisting>
- <para>will take the transition from b to c. That will fire two node-leave events. One on
- node b and one on node composite. So the following lines will be appended to the console
- output:</para>
- <programlisting>leaving node(b)
-leaving node(composite)</programlisting>
- <para>Event propagation is build on the hierarchical composition structure of the process
- definition. The top level element is always the process definition. The process
- definition contains a list of nodes. Each node can be a leaf node or it can be a
- composite node, which means that it contains a list of nested nodes. Nested nodes
- can be used for e.g. super states or composite activities in nested process languages like BPEL.
- </para>
- <para>So the even model also works similarly for composite nodes as it did for the process
- definition above. Suppose that 'Phase one' models
- a super state as in state machines. Then event propagation allows to subscribe to all events
- within that super state. The idea is that the hierarchical composition corresponds to
- diagram representation. If an element 'e' is drawn inside another element 'p', then p
- is the parent of e. A process definition has a set of top level nodes. Every node can have
- a set of nested nodes. The parent of a transition is considered as the first common
- parent for it's source and destination.
- </para>
- <para>If an event listener is not interested in propagated events, propagation can be disabled
- with <literal>propagationDisabled()</literal>. The next process is the same process
- as above except that propagated events will be disabled on the event listener. The graph diagram
- remains the same.
- </para>
- <figure id="propagation.disabled.process">
- <title>A process with a listener to 'node-leave' events with propagation disabled.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/propagation.process.png"/></imageobject></mediaobject>
- </figure>
- <para>Building the process with the process factory:
- </para>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .compositeNode("composite")
- <emphasis role="bold">.event(Node.EVENT_NODE_LEAVE)
- .listener(new DisplaySource())
- .propagationDisabled()</emphasis>
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .transition().to("c")
- .nodesEnd()
- .node("c").behaviour(new WaitState())
-.done();</programlisting>
- <para>So when the first signal is given for this process, again the node-leave event will be
- fired on node a, but now the listener on the composite node will not be executed cause
- propagated events have been disabled. Disabling propagation is a property on the listener
- and doesn't influence the other listeners. The event will always be fired and propagated
- over the whole parent hierarchy.
- </para>
- <programlisting>Execution execution = processDefinition.startExecution();
-execution.signal();
-</programlisting>
- <para>Next, the second signal will take the transition from b to c.
- </para>
- <programlisting>execution.signal()</programlisting>
- <para>Again two node-leave
- events are fired just like above on nodes b and composite respectively. The first event
- is the node-leave event on node b. That will be propagated to the composite node. So the
- listener will not be executed for this event cause it has propagation disabled. But the
- listener will be executed for the node-leave event on the composite node. That is not
- propagated, but fired directly on the composite node. So the listener will now be executed
- only once for the composite node as shown in the following console output:
- </para>
- <programlisting>leaving node(composite)</programlisting>
- </section>
-
- <!-- ### PROCESS STRUCTURE ############################################## -->
- <section>
- <title>Process structure</title>
- <para>Above we already touched briefly on the two main process constructs:
- Nodes, transitions and node composition. This section will elaborate
- on all the basic combination possibilities.
- </para>
- <figure id="process.structure">
- <title>UML class diagram of the basic process structure</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/process.structure.classes.png"/></imageobject></mediaobject>
- </figure>
- <para>Next is a series of example diagram structures that can be formed
- with the PVM process model.
- </para>
- <figure id="transition">
- <title>Any two nodes can be connected with a transition.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.png"/></imageobject></mediaobject>
- </figure>
- <figure id="self.transition">
- <title>A self transition.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/self.transition.png"/></imageobject></mediaobject>
- </figure>
- <figure id="composite.node">
- <title>Composite node is a list of nested nodes.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/composite.node.png"/></imageobject></mediaobject>
- </figure>
- <figure id="transition.into.composite">
- <title>Transition to a node inside a composite.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.into.composite.png"/></imageobject></mediaobject>
- </figure>
- <figure id="transition.out.of.composite">
- <title>Transition from a node inside a composite to a node outside the composite.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.out.of.composite.png"/></imageobject></mediaobject>
- </figure>
- <figure id="transition.inheritence">
- <title>Transition of composite nodes are inherited. The node inside can take the transition of the composite node.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.inheritence.png"/></imageobject></mediaobject>
- </figure>
- <figure id="transition.to.outer">
- <title>Transition from a node to an outer composite.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.to.outer.png"/></imageobject></mediaobject>
- </figure>
- <figure id="transition.to.inner">
- <title>Transition from a composite node to an inner composed node.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/transition.to.inner.png"/></imageobject></mediaobject>
- </figure>
- <figure id="initial.in.composite">
- <title>An initial node inside a composite node.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/initial.in.composite.png"/></imageobject></mediaobject>
- </figure>
- </section>
-
-</chapter>
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-ImplementingBasicActivities.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-BasicProcessExecutionConcepts.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-ImplementingBasicActivities.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch04-ImplementingBasicActivities.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,576 @@
+<chapter id="implementingbasicactivities">
+ <title>Implementing basic activities</title>
+
+ <para>This chapter explains the basics of process definitions, the features offered by
+ the Process Virtual Machine and how activity implementations can be build. At the same
+ time the client API is shown to execute processes with those activity implementations.
+ </para>
+
+ <!-- ### Activity ####################################################### -->
+ <section id="activity">
+ <title>Activity</title>
+ <para>The PVM library doesn't have a fixed set of process constructs.
+ Instead, runtime behaviour of a node is delegated to an <literal>Activity</literal>.
+ In other words, <literal>Activity</literal> is an interface to implement the runtime
+ behaviour of process constructs in plain Java.
+ </para>
+ <programlisting>public <emphasis role="bold">interface Activity</emphasis> extends Serializable {
+
+ void <emphasis role="bold">execute</emphasis>(ActivityExecution execution) throws Exception;
+
+}</programlisting>
+ <para>When an activity is used as the node behaviour, it is in full control of the further
+ propagation of the execution. In other words, a node behaviour can decide what the execution
+ should do next. For example, it can take a transition with
+ <literal>execution.take(Transition)</literal> or go into a wait state with
+ <literal>execution.waitForSignal()</literal>. In case the node behaviour does not invoke
+ any of the above execution propagation methods, the execution will
+ <link linkend="implicitproceedbehaviour">proceed in a default way</link>.
+ </para>
+ </section>
+
+ <!-- ### Activity example ############################################### -->
+ <section id="activityexample">
+ <title>Activity example</title>
+ <para>We'll start with a very original hello world example. A Display
+ activity will print a message to the console:
+ </para>
+ <programlisting>public <emphasis role="bold">class Display</emphasis> implements <emphasis role="bold">Activity</emphasis> {
+
+ String message;
+
+ public Display(String message) {
+ this.message = message;
+ }
+
+ public void execute(ActivityExecution execution) {
+ <emphasis role="bold">System.out.println(message);</emphasis>
+ }
+}</programlisting>
+ <para>Let' build our first process definition with this activity:</para>
+ <figure id="activity.example">
+ <title>Display example process</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.ab.png"/></imageobject></mediaobject>
+ </figure>
+ <programlisting>ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .<emphasis role="bold">node("a").initial()</emphasis>.behaviour(<emphasis role="bold">new Display("hello")</emphasis>)
+ .transition().to("b")
+ .<emphasis role="bold">node("b")</emphasis>.behaviour(<emphasis role="bold">new Display("world")</emphasis>)
+.done();</programlisting>
+ <para>Now we can execute this process as follows:</para>
+ <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
+ <para>The invocation of <literal>startExecution</literal> will print hello world to the console:</para>
+ <programlisting>hello
+world</programlisting>
+ <para>One thing already worth noticing is that activities can be configured
+ with properties. In the Display example, you can see that the message property
+ is configured differently in the two usages. With configuration properties
+ it becomes possible to write reusable activities. They can then be configured
+ differently each time they are used in a process. That is an essential part of
+ how process languages can be build on top of the Process Virtual Machine.
+ </para>
+ <para>The other part that needs explanation is that this activity
+ implementation does not contain any instructions for the propagation of the
+ execution. When a new process instance is started, the execution is positioned
+ in the initial node and that activity is executed. The method
+ <literal>Display.execute</literal> makes use of what is called implicit propagation
+ of execution. Concretely this means that the activity itself does not
+ invoke any of the methods on the execution to propagate it. In that case
+ implicit propagation kicks in. Implicit propagation will take the first
+ transition if there is one. If not, it will end the execution. This explains
+ why both nodes <literal>a</literal> and <literal>b</literal> are executed and that
+ the execution stops after node <literal>b</literal> is executed.
+ </para>
+ <para>More details about the implicit proceed behaviour can be found
+ in <xref linkend="implicitproceedbehaviour" /></para>
+ </section>
+
+ <!-- ### ExternalActivity ############################################### -->
+ <section id="externalactivity">
+ <title>ExternalActivity</title>
+ <para>External activities are activities for which the responsibility for proceeding
+ the execution is transferred externally, meaning outside the process system. This
+ means that for the system that is executing the process, it's a wait state. The
+ execution will wait until an external trigger is given.
+ </para>
+ <para>For dealing with external triggers, <literal>ExternalActivity</literal>
+ adds two methods to the <literal>Activity</literal>:</para>
+ <programlisting>public <emphasis role="bold">interface ExternalActivity</emphasis> extends <emphasis role="bold">Activity</emphasis> {
+
+ void <emphasis role="bold">signal</emphasis>(Execution execution,
+ String signal,
+ Map<String, Object> parameters) throws Exception;
+
+}</programlisting>
+ <para>Just like with plain activities, when an execution arrives in a node, the
+ <literal>execute</literal>-method of the node behaviour is invoked.
+ In external activities, the execute method typically does something to
+ transfer the responsibility to another system and then enters a wait
+ state by invoking <literal>execution.waitForSignal()</literal>. For
+ example in the execute method, responsibility could be transferred to a
+ person by creating a task entry in a task management system and then
+ wait until the person completes the task.
+ </para>
+ <para>In case a node behaves as a wait state, then the execution will
+ wait in that node until the execution's <literal>signal</literal> method
+ is invoked. The execution will delegate that signal to the behaviour Activity
+ of the current node.
+ </para>
+ <para>So the Activity's <literal>signal</literal>-method is invoked
+ when the execution receives an external trigger during the wait state. With the
+ signal method, responsibility is transferred back to the process execution. For
+ example, when a person completes a task, the task management system calls the
+ signal method on the execution.
+ </para>
+ <para>A signal can optionally have a signal name and a map of parameters. Most
+ common way on how node behaviours interprete the signal and parameters is that
+ the signal relates to the outgoing transition that needs to be taken and that the
+ parameters are set as variables on the execution. But those are just examples, it
+ is up to the activity to use the signal and the parameters as it pleases.
+ </para>
+ </section>
+
+ <!-- ### ExternalActivity example ####################################### -->
+ <section id="externalactivityexample">
+ <title>ExternalActivity example</title>
+ <para>Here's a first example of a simple wait state implementation:
+ </para>
+ <programlisting>public <emphasis role="bold">class WaitState</emphasis> implements <emphasis role="bold">ExternalActivity</emphasis> {
+
+ public void execute(ActivityExecution execution) {
+ <emphasis role="bold">execution.waitForSignal();</emphasis>
+ }
+
+ public void signal(ActivityExecution execution,
+ String signalName,
+ Map<String, Object> parameters) {
+ <emphasis role="bold">execution.take(signalName);</emphasis>
+ }
+}</programlisting>
+ <para>The <literal>execute</literal>-method calls
+ <literal>execution.waitForSignal()</literal>. The invocation of
+ <literal>execution.waitForSignal()</literal> will bring the process execution
+ into a wait state until an external trigger is given.
+ </para>
+ <para><literal>signal</literal>-method takes the transition with
+ the signal parameter as the transition name. So when an execution receives an
+ external trigger, the signal name is interpreted as the name of an outgoing
+ transition and the execution will be propagated over that transition.
+ </para>
+ <para>Here's the same simple process that has a transition from a to b. This
+ time, the behaviour of the two nodes will be WaitState's.
+ </para>
+ <figure id="process.diagram">
+ <title>The external activity example process</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.ab.png"/></imageobject></mediaobject>
+ </figure>
+ <programlisting>ClientProcessDefinition processDefinition = ProcessFactory.build()
+ <emphasis role="bold">.node("a").initial().behaviour(new WaitState())</emphasis>
+ .transition().to("b")
+ <emphasis role="bold">.node("b").behaviour(new WaitState())</emphasis>
+.done();</programlisting>
+ <para>Let's start a new process instance for this process definition:</para>
+ <programlisting>ClientExecution execution = processDefinition.startProcessInstance();</programlisting>
+ <para>Starting this process will execute the <literal>WaitState</literal> activity
+ in node <literal>a</literal>. <literal>WaitState.execute</literal> will invoke
+ <literal>ActivityExecution.waitForSignal</literal>. So when the
+ <literal>processDefinition.startProcessInstance()</literal> returns, the execution
+ will still be positioned in node a.
+ </para>
+ <programlisting>assertEquals("a", execution.getNodeName());</programlisting>
+ <para>Then we provide the external trigger by calling the <literal>signal</literal>
+ method.
+ </para>
+ <programlisting>execution.signal();</programlisting>
+ <para>The <literal>execution.signal()</literal> will delegate to the activity
+ of the current node. So in this case that is the <literal>WaitState</literal>
+ activity in node <literal>a</literal>. The <literal>WaitState.signal</literal>
+ will invoke the <literal>ActivityExecution.take(String transitionName)</literal>.
+ Since we didn't supply a signalName, the first transition with name <literal>null</literal>
+ will be taken. The only transition we specified out of node <literal>a</literal>
+ didn't get a name so that one will be taken. And that transition points to node
+ <literal>b</literal>. When the execution arrives in node <literal>b</literal>,
+ the <literal>WaitState</literal> in node <literal>b</literal> is executed.
+ Similar as we saw above, the execution will wait in node <literal>b</literal>
+ and this time the <literal>signal</literal> method will return, leaving the
+ execution positioned in node <literal>b</literal>.
+ </para>
+ <programlisting>assertEquals("b", execution.getNodeName());</programlisting>
+ </section>
+
+ <!-- ### BASIC PROCESS EXECUTION ######################################## -->
+ <section id="basicprocessexecution">
+ <title>Basic process execution</title>
+ <para>In this next example, we'll combine automatic activities and wait states.
+ This example builds upon the loan approval process with the <literal>WaitState</literal>
+ and <literal>Display</literal> activities that we've just created. Graphically,
+ the loan process looks like this:
+ </para>
+ <figure id="basicprocessexecution.loan.process">
+ <title>The loan process</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.loan.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Building process graphs in Java code can be tedious because you have to keep track of all the
+ references in local variables. To resolve that, the Process Virtual Machine comes with a
+ ProcessFactory. The ProcessFactory is a kind of domain specific language (DSL) that is embedded
+ in Java and eases the construction of process graphs. This pattern is also known as
+ a <ulink url="http://martinfowler.com/bliki/FluentInterface.html">fluent
+ interface</ulink>.
+ </para>
+ <programlisting>ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
+ .node(<emphasis role="bold">"submit loan request"</emphasis>).initial().behaviour(new Display("loan request submitted"))
+ .transition().to("evaluate")
+ <emphasis role="bold">.node("evaluate").behaviour(new WaitState())</emphasis>
+ .transition("approve").to("wire money")
+ .transition("reject").to("end")
+ <emphasis role="bold">.node("wire money").behaviour(new Display("wire the money"))</emphasis>
+ .transition().to("archive")
+ <emphasis role="bold">.node("archive").behaviour(new WaitState())</emphasis>
+ .transition().to("end")
+ <emphasis role="bold">.node("end").behaviour(new WaitState())</emphasis>
+.done();</programlisting>
+ <para>For more details about the ProcessFactory, see <ulink url="../../api/org/jbpm/pvm/package-summary.html">the
+ api docs</ulink>. An alternative for
+ the ProcessFactory would be to create an XML language and an XML parser for expressing
+ processes. The XML parser can then instantiate the classes of package
+ <literal>org.jbpm.pvm.internal.model</literal> directly. That approach is typically taken by
+ process languages.
+ </para>
+ <para>The initial node <literal>submit loan request</literal> and the node
+ <literal>wire the money</literal> are automatic nodes. In this example,
+ the <literal>Display</literal> implementation of node
+ <literal>wire the money</literal> uses the Java API's to just print a
+ message to the console. But the witty reader can imagine an alternative
+ <literal>Activity</literal> implementation that uses the Java API of a payment
+ processing library to make a real automatic payment.
+ </para>
+ <para>A new execution for the process above can be started like this
+ </para>
+ <programlisting>ClientExecution execution = processDefinition.startProcessInstance();</programlisting>
+ <para>When the <literal>startExecution</literal>-method returns, the node
+ <literal>submit loan request</literal> will be executed and the execution will be
+ positioned in the node <literal>evaluate</literal>.
+ </para>
+ <figure id="execution.loan.evaluate">
+ <title>Execution positioned in the 'evaluate' node</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/execution.loan.evaluate.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Now, the execution is at an interesting point. There are two transitions out of
+ the state <literal>evaluate</literal>. One transition is called <literal>approve</literal>
+ and one transition is called <literal>reject</literal>. As we explained above, the WaitState
+ implementation will take the transition that corresponds to the signal that is given.
+ Let's feed in the 'approve' signal like this:
+ </para>
+ <programlisting>execution.signal("approve");</programlisting>
+ <para>The <literal>approve</literal> signal will cause the execution to take the <literal>approve</literal>
+ transition and it will arrive in the node <literal>wire money</literal>.
+ </para>
+ <para>In node <literal>wire money</literal>, the message will be printed to the console.
+ Since, the <literal>Display</literal> activity didn't invoke the
+ <literal>execution.waitForSignal()</literal>, nor any of the other execution propagation
+ methods, the implicit proceed behaviour will just make the execution continue
+ over the outgoing transition to node <literal>archive</literal>, which is again
+ a <literal>WaitState</literal>.
+ </para>
+ <figure id="execution.loan.archive">
+ <title>Execution positioned in 'archive' node</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/execution.loan.archive.png"/></imageobject></mediaobject>
+ </figure>
+ <para>So only when the <literal>archive</literal> wait state is reached,
+ the <literal>signal("approve")</literal> returns.
+ </para>
+ <para>Another signal like this:</para>
+ <programlisting>execution.signal("approve");</programlisting>
+ <para>will bring the execution eventually in the end state.</para>
+ <figure id="execution.loan.end">
+ <title>Execution positioned in the 'end' node</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/execution.loan.end.png"/></imageobject></mediaobject>
+ </figure>
+ </section>
+
+ <!-- ### MOTIVATION ##################################################### -->
+ <section id="motivation">
+ <title>Motivation</title>
+ <para>There are basically two forms of process languages: graph based and composite
+ process languages. First of all, this design supports both. Even graph based execution
+ and node composition can be used in combination to implement something like UML super states.
+ </para>
+ <para>In this design, control flow activity implementations will have to be
+ aware of whether they are dependent on transitions (graph based) or whether they are
+ using the composite node structure. The goal of this design is that all non-control
+ flow activities can be implemented in the same way so that you can use them in graph
+ based process languages as well as in composite process languages.
+ </para>
+ </section>
+
+ <!-- ### EVENTS ######################################################### -->
+ <section id="events">
+ <title>Events</title>
+ <para>Events are points in the process definition to which a list of
+ activities can be subscribed as listeners. The motivation for events is to allow for
+ developers to add programming logic to a process without changing the process diagram.
+ This is a very valuable instrument in
+ facilitating the collaboration between business analysts and developers. Business analysts
+ are responsible for expressing the requirements. When they use a process graph to document
+ those requirements, developers can take this diagram and make it executable. Events can
+ be a very handy to insert technical details into a process (like e.g. some database insert)
+ in which the business analyst is not interested.
+ </para>
+ <para>Most common events are fired by the execution automatically:
+ </para>
+ <itemizedlist>
+ <listitem><literal>Transition.EVENT_TRANSITION_TAKE = "transition-take"</literal> :
+ fired on transitions when transitions are taken.
+ </listitem>
+ <listitem><literal>Node.EVENT_NODE_ENTER = "node-enter"</literal> : fired on the node
+ when execution enters that node. This happens when execution takes a transition
+ to that node, when a child node is being executed with <literal>execution.execute(Node)</literal>
+ or when a transition is taken from a node outside that node to a contained node.
+ The latter refers to super states in state machines.
+ </listitem>
+ <listitem><literal>Node.EVENT_NODE_LEAVE = "node-leave"</literal> : fired on the node
+ when a transition is taken out of that node or when a child node execution is
+ finished and the execution is propagated to the parent node.
+ </listitem>
+ <listitem><literal>ProcessDefinition.EVENT_PROCESS_START = "process-start"</literal> : fired on a process
+ when a new process is started.
+ </listitem>
+ <listitem><literal>ProcessDefinition.EVENT_PROCESS_END = "process-end"</literal> : fired on a process
+ when a new process is ended. This might include a executions that are ended
+ with a cancelled or error state.
+ </listitem>
+ </itemizedlist>
+ <para>Events are identified by the combination of a process element
+ and an event name. Users and process languages can also fire events
+ programmatically with the fire method on the Execution:
+ </para>
+ <programlisting>public interface Execution extends Serializable {
+ ...
+ void fire(String eventName, ProcessElement eventSource);
+ ...
+}</programlisting>
+
+ <para>A list of <link linkend="activity"><literal>Activity</literal>s</link> can be associated to an
+ event. But activities on events can not influence the control flow of the execution since
+ they are merely listeners to an execution wich is already in progress. This is different from
+ activities that serve as the behaviour for nodes. Node behaviour activities are responsible
+ for propagating the execution. So if an activity in an event invokes any of the
+ following methods, then it will result in an exception.
+ </para>
+
+ <itemizedlist>
+ <listitem><literal>waitForSignal()</literal></listitem>
+ <listitem><literal>take(Transition)</literal></listitem>
+ <listitem><literal>end(*)</literal></listitem>
+ <listitem><literal>execute(Node)</literal></listitem>
+ </itemizedlist>
+
+ <para>We'll reuse the <literal><link linkend="activity">Display</link></literal>
+ activity from above in a simple process: two nodes connected by a
+ transition. The Display listener will be subscribed to the transition event.</para>
+ <figure id="action.process">
+ <title>The process to which a listener activity will be associated</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.png"/></imageobject></mediaobject>
+ </figure>
+ <programlisting>ProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ <emphasis role="bold">.event("node-leave")
+ .listener(new Display("leaving a"))
+ .listener(new Display("second message while leaving a"))</emphasis>
+ .transition().to("b")
+ <emphasis role="bold">.listener(new Display("taking transition"))</emphasis>
+ .node("b").behaviour(new WaitState())
+ <emphasis role="bold">.event("node-enter")
+ .listener(new Display("entering b"))</emphasis>
+.done();</programlisting>
+ <para>The first event shows how to register multiple listeners to the same
+ event. They will be notified in the order as they are specified.
+ </para>
+ <para>Then, on the transition, there is only one type of event. So in that case,
+ the event type must not be specified and the listeners can be added directly on
+ the transition.
+ </para>
+ <para>A listeners will be called each time an execution fires the event to
+ which the listener is subscribed. The execution will be provided in the activity
+ interface as a parameter and can be used by listeners except for the methods that
+ control the propagation of execution.
+ </para>
+ </section>
+
+ <!-- ### EVENT PROPAGATION ############################################## -->
+ <section>
+ <title>Event propagation</title>
+ <para>Events are by default propagated to enclosing process elements. The motivation
+ is to allow for listeners on process definitions or composite nodes that get executed
+ for all events that occur within that process element. For example this feature
+ allows to register a listener on a process definition or a composite node on
+ <literal>node-leave</literal> events. Such action will be executed if that node is
+ left. And if that listener is registered on a composite node, it will also be executed
+ for all nodes that are left within that composite node.
+ </para>
+ <para>To show this clearly, we'll create a <literal>DisplaySource</literal> activity
+ that will print the message <literal>leaving</literal> and the source of the event
+ to the console.
+ </para>
+ <programlisting>public class <emphasis role="bold">DisplaySource</emphasis> implements Activity {
+
+ public void execute(Execution execution) {
+ <emphasis role="bold">System.out.println("leaving "+execution.getEventSource());</emphasis>
+ }
+}</programlisting>
+ <para>Note that the purpose of event listeners is not to be visible, that's why the activity
+ itself should not be displayed in the diagram. A <literal>DisplaySource</literal> activity
+ will be added as a listener to the event <literal>node-leave</literal> on the composite node.
+ </para>
+ <para>The next process shows how the <literal>DisplaySource</literal> activity is registered
+ as a listener to to the 'node-leave' event on the <literal>composite</literal> node:</para>
+ <figure id="propagation.process">
+ <title>A process with an invisible activity on a node-leave event on a composite node.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/propagation.process.png"/></imageobject></mediaobject>
+ </figure>
+ <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .compositeNode("composite")
+ <emphasis role="bold">.event(Node.EVENT_NODE_LEAVE)
+ .listener(new DisplaySource())</emphasis>
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .transition().to("c")
+ .compositeEnd()
+ .node("c").behaviour(new WaitState())
+.done();</programlisting>
+ <para>Next we'll start an execution.</para>
+ <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
+ <para>After starting a new execution, the execution will be in node <literal>a</literal> as
+ that is the initial node. No nodes have been left so no message is logged. Next a signal
+ will be given to the execution, causing it to take the transition from <literal>a</literal>
+ to <literal>b</literal>.
+ </para>
+ <programlisting>execution.signal();</programlisting>
+ <para>When the signal method returns, the execution will have taken the transition and
+ the node-leave event will be fired on node a. That event will be propagated to the
+ composite node and to the process definition. Since our propagation logger is placed
+ on node composite it will receive the event and print the following message:
+ </para>
+ <programlisting>leaving node(a)</programlisting>
+ <para>Another</para>
+ <programlisting>execution.signal();</programlisting>
+ <para>will take the transition from b to c. That will fire two node-leave events. One on
+ node b and one on node composite. So the following lines will be appended to the console
+ output:</para>
+ <programlisting>leaving node(b)
+leaving node(composite)</programlisting>
+ <para>Event propagation is build on the hierarchical composition structure of the process
+ definition. The top level element is always the process definition. The process
+ definition contains a list of nodes. Each node can be a leaf node or it can be a
+ composite node, which means that it contains a list of nested nodes. Nested nodes
+ can be used for e.g. super states or composite activities in nested process languages like BPEL.
+ </para>
+ <para>So the even model also works similarly for composite nodes as it did for the process
+ definition above. Suppose that 'Phase one' models
+ a super state as in state machines. Then event propagation allows to subscribe to all events
+ within that super state. The idea is that the hierarchical composition corresponds to
+ diagram representation. If an element 'e' is drawn inside another element 'p', then p
+ is the parent of e. A process definition has a set of top level nodes. Every node can have
+ a set of nested nodes. The parent of a transition is considered as the first common
+ parent for it's source and destination.
+ </para>
+ <para>If an event listener is not interested in propagated events, propagation can be disabled
+ with <literal>propagationDisabled()</literal>. The next process is the same process
+ as above except that propagated events will be disabled on the event listener. The graph diagram
+ remains the same.
+ </para>
+ <figure id="propagation.disabled.process">
+ <title>A process with a listener to 'node-leave' events with propagation disabled.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/propagation.process.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Building the process with the process factory:
+ </para>
+ <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .compositeNode("composite")
+ <emphasis role="bold">.event(Node.EVENT_NODE_LEAVE)
+ .listener(new DisplaySource())
+ .propagationDisabled()</emphasis>
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .transition().to("c")
+ .nodesEnd()
+ .node("c").behaviour(new WaitState())
+.done();</programlisting>
+ <para>So when the first signal is given for this process, again the node-leave event will be
+ fired on node a, but now the listener on the composite node will not be executed cause
+ propagated events have been disabled. Disabling propagation is a property on the listener
+ and doesn't influence the other listeners. The event will always be fired and propagated
+ over the whole parent hierarchy.
+ </para>
+ <programlisting>Execution execution = processDefinition.startExecution();
+execution.signal();
+</programlisting>
+ <para>Next, the second signal will take the transition from b to c.
+ </para>
+ <programlisting>execution.signal()</programlisting>
+ <para>Again two node-leave
+ events are fired just like above on nodes b and composite respectively. The first event
+ is the node-leave event on node b. That will be propagated to the composite node. So the
+ listener will not be executed for this event cause it has propagation disabled. But the
+ listener will be executed for the node-leave event on the composite node. That is not
+ propagated, but fired directly on the composite node. So the listener will now be executed
+ only once for the composite node as shown in the following console output:
+ </para>
+ <programlisting>leaving node(composite)</programlisting>
+ </section>
+
+ <!-- ### PROCESS STRUCTURE ############################################## -->
+ <section>
+ <title>Process structure</title>
+ <para>Above we already touched briefly on the two main process constructs:
+ Nodes, transitions and node composition. This section will elaborate
+ on all the basic combination possibilities.
+ </para>
+ <figure id="process.structure">
+ <title>UML class diagram of the basic process structure</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.structure.classes.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Next is a series of example diagram structures that can be formed
+ with the PVM process model.
+ </para>
+ <figure id="transition">
+ <title>Any two nodes can be connected with a transition.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="self.transition">
+ <title>A self transition.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/self.transition.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="composite.node">
+ <title>Composite node is a list of nested nodes.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/composite.node.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="transition.into.composite">
+ <title>Transition to a node inside a composite.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.into.composite.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="transition.out.of.composite">
+ <title>Transition from a node inside a composite to a node outside the composite.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.out.of.composite.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="transition.inheritence">
+ <title>Transition of composite nodes are inherited. The node inside can take the transition of the composite node.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.inheritence.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="transition.to.outer">
+ <title>Transition from a node to an outer composite.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.to.outer.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="transition.to.inner">
+ <title>Transition from a composite node to an inner composed node.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/transition.to.inner.png"/></imageobject></mediaobject>
+ </figure>
+ <figure id="initial.in.composite">
+ <title>An initial node inside a composite node.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/initial.in.composite.png"/></imageobject></mediaobject>
+ </figure>
+ </section>
+
+</chapter>
Added: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch05-ProcessAnatomy.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch05-ProcessAnatomy.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch05-ProcessAnatomy.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,4 @@
+<chapter id="timers">
+ <title>Timers</title>
+ <para>TODO</para>
+</chapter>
\ No newline at end of file
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch06-ImplementingAdvancedActivities.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AdvancedGraphExecution.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch06-ImplementingAdvancedActivities.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch06-ImplementingAdvancedActivities.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,323 @@
+<chapter id="advancedgraphexecution">
+ <title>Advanced graph execution</title>
+
+ <!-- ### LOOPS ########################################################## -->
+ <section>
+ <title>Loops</title>
+ <para>Loops can be based on transitions or on node composition. Loops can contain wait
+ states.
+ </para>
+ <para>To support high numbers of automatic loop executions, the Process Virtual Machine
+ tranformed the propagation of execution from tail recursion to a while loop. This means
+ that all the methods in the <literal>Execution</literal> class that propagate the
+ execution like <literal>take</literal> or <literal>execute</literal> will not be
+ executed when you call them. Instead, the method invocations will be appended to a list.
+ The first invocation of such a method will start a loop that will execute all invocations
+ till that list is empty. These invocations are called atomic operations.
+ </para>
+ </section>
+
+ <!-- ### SUB PROCESSES ################################################## -->
+ <section>
+ <title>Sub processes</title>
+ <para>TODO: sub processes</para>
+ </section>
+
+ <!-- ### DEFAULT PROCEED BEHAVIOUR ###################################### -->
+ <section id="implicitproceedbehaviour">
+ <title>Implicit proceed behaviour</title>
+ <para>When an <literal>Activity</literal> is used as node behaviour, it can
+ explicitely propagate the execution with following methods:
+ </para>
+ <itemizedlist>
+ <listitem><literal>waitForSignal()</literal></listitem>
+ <listitem><literal>take(Transition)</literal></listitem>
+ <listitem><literal>end(*)</literal></listitem>
+ <listitem><literal>execute(Node)</literal></listitem>
+ <listitem><literal>createExecution(*)</literal></listitem>
+ </itemizedlist>
+ <para>When <literal>Activity</literal> implementations used for node behviour
+ don't call any of the following execution propagation methods, then, after
+ the activity is executed, the execution will apply the implicit proceed behaviour.
+ </para>
+ <para>The implicit proceed behaviour is defined as follows:</para>
+ <itemizedlist>
+ <listitem>If the current node has a default outgoing transition, take it.</listitem>
+ <listitem>If the current node has a parent node, move back to the parent node.</listitem>
+ <listitem>Otherwise, end this execution.</listitem>
+ </itemizedlist>
+ <para>Process languages can overwrite the implicit proceed behaviour
+ by overriding the <literal>proceed</literal> method in
+ <literal>ExecutionImpl</literal>.
+ </para>
+ </section>
+
+ <!-- ### FUNCTIONAL ACTIVITIES ################################ -->
+ <section id="functionalactivities">
+ <title>Functional activities</title>
+ <para>Activities that also can be used as event listeners are called functional
+ activities. Examples of automatic activities are sending an email, doing a database
+ update, generating a pdf, calculating an average, etc. All of these are automatic
+ activities that do not change the execution flow. Here's how such activities can
+ be implemented:
+ </para>
+ <programlisting>public class FunctionalActivity implements Activity, EventListener {
+ public void execute(ActivityExecution execution) {
+ perform(execution);
+ }
+ public void notify(EventListenerExecution execution) {
+ perform(execution);
+ }
+ void perform(OpenExecution execution) {
+ ...do functional work...
+ }
+ }</programlisting>
+ <para>None of these methods actually invoke execution propagation methods.
+ So after the perform method is completed, the execution will
+ <link linkend="implicitproceedbehaviour">proceed in the default way</link>.
+ </para>
+ </section>
+
+
+ <!-- ### EXECUTION AND THREADS ########################################## -->
+ <section id="executionandthreads">
+ <title>Execution and threads</title>
+ <para>This section explains how the Process Virtual Machine boroughs the thread
+ from the client to bring an execution from one wait state to another.
+ </para>
+ <para>When a client invokes a method (like e.g. the signal method) on an execution,
+ by default, the Process Virtual Machine will use that thread to progress the execution
+ until it reached a wait state. Once the next wait state has been reached, the
+ method returns and the client gets the thread back. This is the default way
+ for the Process Virtual Machine to operate. Two more levels of asynchonous
+ execution complement this default behaviour:
+ <link linkend="asynchronouscontinuations">Asynchronous continuations</link>
+ and the <link linkend="architecture">asynchronous command service</link>.
+ </para>
+ <para>The next process will show the basics concretely. It has three wait states
+ and four automatic nodes.
+ </para>
+ <figure id="automatic">
+ <title>Process with many sequential automatic activities.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Here's how to build the process:</para>
+ <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("automatic")
+ .<emphasis role="bold">node("wait 1").initial()</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
+ .transition().to("automatic 1")
+ .<emphasis role="bold">node("automatic 1")</emphasis>.behaviour(new <emphasis role="bold">Display("one")</emphasis>)
+ .transition().to("wait 2")
+ .<emphasis role="bold">node("wait 2")</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
+ .transition().to("automatic 2")
+ .<emphasis role="bold">node("automatic 2")</emphasis>.behaviour(new <emphasis role="bold">Display("two")</emphasis>)
+ .transition().to("automatic 3")
+ .<emphasis role="bold">node("automatic 3")</emphasis>.behaviour(new <emphasis role="bold">Display("three")</emphasis>)
+ .transition().to("automatic 4")
+ .<emphasis role="bold">node("automatic 4")</emphasis>.behaviour(new <emphasis role="bold">Display("four")</emphasis>)
+ .transition().to("wait 3")
+ .<emphasis role="bold">node("wait 3")</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
+.done();</programlisting>
+ <para>Let's walk you through one execution of this process.
+ </para>
+ <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
+ <para>Starting a new execution means that the initial node is executed. So if an automatic
+ activity would be configured as the behaviour in the initial node, the process will start executing
+ immediatly in the startExecution. In this case however, the initial node is a wait state. So
+ the startExecution method returns immediately and the execution will be positioned in the initial
+ node 'wait 1'.
+ </para>
+ <figure id="automatic.wait1">
+ <title>A new execution will be positioned in 'wait 1'.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait1.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Then an external trigger is given with the signal method.</para>
+ <programlisting>execution.signal();</programlisting>
+ <para>As explained above when introducing the WaitState, that signal will cause the default transition to be taken. The
+ transition will move the execution to node <literal>automatic 1</literal> and execute it. The execute method
+ of the <literal>Display</literal> activity in <literal>automatic 1</literal> print a line to the console and it
+ will <emphasis role="bold">not</emphasis> call <literal>execution.waitForSignal()</literal>. Therefore, the execution
+ will proceed by taking the default transition out of <literal>automatic 1</literal>. The signal method is still blocking
+ cause this action and the transitions are taken
+ by that same thread. Then the execution arrives in <literal>wait 2</literal> and executes the <literal>WaitState</literal>
+ activity. That method will invoke the <literal>execution.waitForSignal()</literal>, which will cause the signal method
+ to return. That is when the thread is given back to the client that invoked the signal method.
+ </para>
+ <para>So when the signal method returns, the execution is positioned in <literal>wait 2</literal>.</para>
+ <figure id="automatic.wait2">
+ <title>One signal brought the execution from 'initial' to 'wait 2'.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait2.png"/></imageobject></mediaobject>
+ </figure>
+ <para>Then the execution is now waiting for an external trigger just as an object (more precisely an object graph) in
+ memory until the next external trigger is given with the signal method.
+ </para>
+ <programlisting>execution.signal();</programlisting>
+ <para>This second invocation of signal will take the execution similarly all the way to <literal>wait 3</literal> before
+ it returns.
+ </para>
+ <figure id="automatic.wait3">
+ <title>The second signal brought the execution all the way to 'wait 3'.</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait3.png"/></imageobject></mediaobject>
+ </figure>
+ <para>To make executable processes, developers need to know exactly what the automatic activities,
+ what the wait states are and which threads will be allocated to the process execution. For business
+ analysts that draw the analysis process, things are a bit simpler. For the
+ activities they draw, they usually know whether it's a human or a system that is responsible.
+ But they typically don't not how this translates to threads and transactions.
+ </para>
+ <para>So for the developer, the first job is to analyse what needs to be executed
+ within the thread of control of the process and what is outside. Looking for the external
+ triggers can be a good start to find the wait states in a process, just like verbs and nouns
+ can be the rule of thumb in building UML class diagrams.
+ </para>
+ </section>
+
+ <!-- ### PROCESS CONCURRENCY ############################################ -->
+ <section>
+ <title>Process concurrency</title>
+ <para>To model process concurrency, there is a parent-child tree structure on the
+ execution. The idea is that the main path of execution is the root of that tree.
+ This implies that on the level of the Process Virtual Machine, there is no differentiation
+ between complete process instances and paths of execution within a process instance.
+ One of the main motivations for this design is that the API actually is not made more
+ complex then necessary for simple processes with only one single path of execution.
+ </para>
+ <figure id="execution.structure">
+ <title>UML class diagram of the basic execution structure</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.execution.structure.classes.png"/></imageobject></mediaobject>
+ </figure>
+ <para>To extablish multiple concurrent paths of execution, child executions can be
+ created. Only leaf executions can be active. Non-leave executions should be
+ inactive. This tree structure of executions doesn't enforce a particular type of
+ concurrency or join behaviour. It's up to the forks or and-splits and to the joins
+ or and-merges to use the execution tree structure in any way they want to define
+ the wanted concurrency behaviour. Here you see an example
+ of concurrent executions.
+ </para>
+ <figure id="concurrency">
+ <title>Concurrent paths of execution</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.concurrency.png"/></imageobject></mediaobject>
+ </figure>
+ <para>There is a billing and a shipping path of execution. In this case, the
+ flat bar nodes represent nodes that fork and join. The execution shows a three
+ executions. The main path of execution is inactive (represented as gray) and the
+ billing and shipping paths of execution are active and point to the node
+ <literal>bill</literal> and <literal>ship</literal> respectively.
+ </para>
+ <para>It's up to the node behaviour implementations how they want to use this
+ execution structure. Suppose that multiple tasks have to be completed before the
+ execution is to proceed. The node behaviour can spawn a series of child executions
+ for this. Or alternatively, the task component could support task groups that
+ are associated to one single execution. In that case, the task component becomes
+ responsible for synchronizing the tasks, thereby moving this responsibility
+ outside the scope of the execution tree structure.
+ </para>
+ </section>
+
+ <!-- ### EXCEPTION HANDLERS ############################################# -->
+ <section>
+ <title>Exception handlers</title>
+ <para>In all the <link linkend="delegationclasses">code that is associated to a process</link>
+ like Activity's, Actions and Conditions, it's possible to include try-catch blocks in
+ the method implementations to handle exceptions. But in order to build more reusable building
+ blocks for both the delegation classes and the exception handling logic, exception handlers are
+ added to the core process model.
+ </para>
+ <para>An exception handler can be associated to any process element. When an exception
+ occurs in a delegation class, a matching exception handler will be searched for. If
+ such an exception handler is found, it will get a chance to handle the exception.
+ </para>
+ <para>If an exception handler completes without problems, then the exception is considered
+ handled and the execution resumes right after the delegation code that was called. For example,
+ a transition has three actions and the second action throws an exception that is handled
+ by an exception handler, then
+ </para>
+ <para>Writing automatic activities that are exception handler aware is easy. The
+ default is to proceed anyway. No method needs to be called on the execution. So
+ if an automatic activity throws an exception that is handled by an exception handler,
+ the execution will just proceed after that activity. It becomes a big more difficult
+ for control flow activities. They might have to include try-finally blocks to
+ invoke the proper methods on the execution before an exception handler gets a
+ chance to handle the exception. For example, if an activity is a wait state and
+ an exception occurs, then there is a risk that the thread jumps over the
+ invocation of <literal>execution.waitForSignal()</literal>, causing the execution
+ to proceed after the activity.
+ </para>
+ <para>TODO: exceptionhandler.isRethrowMasked</para>
+ <para>TODO: transactional exception handlers</para>
+ <para>TODO: we never catch errors</para>
+ </section>
+
+ <!-- ### PROCESS MODIFICATIONS ########################################## -->
+ <section>
+ <title>Process modifications</title>
+ <para>TODO: process modifications</para>
+ </section>
+
+ <!-- ### LOCKING AND EXECUTION STATE #################################### -->
+ <section>
+ <title>Locking and execution state</title>
+ <para>The state of an execution is either active or locked. An active
+ execution is either executing or waiting for an external trigger. If an
+ execution is not in STATE_ACTIVE, then it is locked. A locked execution
+ is read only.
+ </para>
+ <para>When a new execution is created, it is in STATE_ACTIVE. To change
+ the state to a locked state, use lock(String). Some STATE_* constants
+ are provided that represent the most commonly used locked states. But
+ the state '...' in the picture indicates that any string can be provided
+ as the state in the lock method.
+ </para>
+ <figure id="execution.states">
+ <title>States of an execution</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.execution.states.png"/></imageobject></mediaobject>
+ </figure>
+ <para>If an execution is locked, methods that change the execution will
+ throw a PvmException and the message will reference the actual locking state.
+ Firing events, updating variables, updating priority and adding comments
+ are not considered to change an execution. Also creation and removal of child
+ executions are unchecked, which means that those methods can be invoked by
+ external API clients and node behaviour methods, even while the execution
+ is in a locked state.
+ </para>
+ <para>Make sure that comparisons between getState() and the STATE_* constants
+ are done with .equals and not with '==' because if executions are loaded
+ from persistent storage, a new string is created instead of the constants.
+ </para>
+ <para>An execution implementation will be locked:
+ </para>
+ <itemizedlist>
+ <listitem>When it is ended</listitem>
+ <listitem>When it is suspended</listitem>
+ <listitem>During asynchronous continuations</listitem>
+ </itemizedlist>
+ <para>Furthermore, locking can be used by Activity implementations to make
+ executions read only during wait states hen responsibility for the execution is
+ transferred to an external entity such as:
+ </para>
+ <itemizedlist>
+ <listitem>A human task</listitem>
+ <listitem>A service invocation</listitem>
+ <listitem>A wait state that ends when a scanner detects that a file appears</listitem>
+ </itemizedlist>
+ <para>In these situations the strategy is that the external entity should get
+ full control over the execution because it wants to control what is allowed
+ and what not. To get that control, they lock the execution so that all interactions
+ have to go through the external entity.
+ </para>
+ <para>One of the main reasons to create external entities is that they can live
+ on after the execution has already proceeded. For example, in case
+ of a service invocation, a timer could cause the execution to take the timeout transition.
+ When the response arrives after the timeout, the service invocation entity should
+ make sure it doesn't signal the execution. So the service invocation can be
+ seen as a node instance (aka activity instance) and is unique for every execution
+ of the node.
+ </para>
+ <para>External entities themselves are responsible for managing the execution
+ lock. If the timers and client applications are consequent in addressing the
+ external entities instead of the execution directly, then locking is in theory
+ unnecessary. It's up to the node behaviour implementations whether they want
+ to take the overhead of locking and unlocking.
+ </para>
+ </section>
+
+</chapter>
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch07-Variables.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Variables.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch07-Variables.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch07-Variables.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,4 @@
+<chapter id="variables">
+ <title>Variables</title>
+ <para>TODO</para>
+</chapter>
\ No newline at end of file
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch08-Timers.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Timers.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch08-Timers.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch08-Timers.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,4 @@
+<chapter id="timers">
+ <title>Timers</title>
+ <para>TODO</para>
+</chapter>
\ No newline at end of file
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch09-AsynchronousContinuations.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AsynchronousContinuations.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch09-AsynchronousContinuations.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch09-AsynchronousContinuations.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,4 @@
+<chapter id="asynchronouscontinuations">
+ <title>Asynchronous continuations</title>
+ <para>TODO</para>
+</chapter>
Copied: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch10-SoftwareLogging.xml (from rev 2276, jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-SoftwareLogging.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch10-SoftwareLogging.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch10-SoftwareLogging.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -0,0 +1,99 @@
+<chapter id="softwarelogging">
+ <title>Software logging</title>
+
+ <section>
+ <title>Configuration</title>
+ <para>PVM can use JDK logging (java.util.logging) or log4j. When the first message is
+ logged, PVM logging will make the selection with following procedure:
+ <orderedlist>
+ <listitem>If a <literal>logging.properties</literal> resource is found
+ on the classpath (using the context classloader), then JDK logging will
+ be used and that file will be used to initialize the JDK logging.
+ </listitem>
+ <listitem>If log4j is found on the classpath, then log4j will be used.
+ The check for log4j will be done by checking availability of class
+ <literal>org.apache.log4j.LogManager</literal> with the context classloader.
+ </listitem>
+ <listitem>If none of the above, JDK logging will be used.</listitem>
+ </orderedlist>
+ </para>
+ </section>
+
+ <section>
+ <title>Categories</title>
+ <para>The PVM classes use their class name as the category for the logger.
+ </para>
+ <para>To have a basic understanding of what the PVM classes are doing,
+ turning on the <literal>debug</literal> level is great. Level
+ <literal>trace</literal> might be spitting out too much for that
+ purpose.
+ </para>
+ </section>
+
+ <section>
+ <title>JDK logging</title>
+ <para>In JDK logging, <literal>debug</literal>maps to <literal>fine</literal>
+ and <literal>trace</literal> maps to <literal>finest</literal>.
+ Level <literal>finer</literal> is not used.
+ </para>
+ <para><literal>org.jbpm.pvm.internal.log.LogFormatter</literal> is part of
+ the pvm library and it can create a nice one-line output for log messages.
+ It also has a neat feature that creates a unique indentation per thread.
+ To configure it, this is a typical <literal>logging.properties</literal>
+ </para>
+ <programlisting>handlers = java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = org.jbpm.pvm.internal.log.LogFormatter
+
+# For example, set the com.xyz.foo logger to only log SEVERE messages:
+# com.xyz.foo.level = SEVERE
+
+.level = SEVERE
+org.jbpm.level=FINE
+org.jbpm.tx.level=FINE
+org.jbpm.pvm.internal.wire.level=FINE</programlisting>
+
+<!--
+ <para>For production usage, jBPM also includes an error triggered log handler. This is
+ a log handler that will only keep the most recent log messages in
+ memory and these will only be flushed to a file in case an error occurs.
+ </para>
+ <para>to configure it, add <literal>org.jbpm.util.ErrorTriggeredFileHandler</literal>
+ to the handlers in the logging properties like this:
+ </para>
+ <programlisting>handlers = java.util.logging.ConsoleHandler org.jbpm.util.ErrorTriggeredFileHandler</programlisting>
+ <para>Next snippet shows how in the same logging.properties, the error
+ triggered file handler can be configured. The given values are the default
+ values.
+ </para>
+ <programlisting>org.jbpm.util.ErrorTriggeredFileHandler.size = 500
+org.jbpm.util.ErrorTriggeredFileHandler.push = SEVERE
+org.jbpm.util.ErrorTriggeredFileHandler.pattern = %h/jbpm%u.log</programlisting>
+ <para>Alternatively to using the org.jbpm.util.ErrorTriggeredFileHandler, the
+ JDK handlers FileHandler and MemoryHandler can used in combination to get
+ similar results with a bit more configuration.
+ </para>
+
+-->
+ </section>
+
+ <section>
+ <title>Debugging persistence</title>
+ <para>When testing the persistence, following logging configurations can be
+ valuable. Category <literal>org.hibernate.SQL</literal> shows the SQL statement that is executed
+ and category <literal>org.hibernate.type</literal> shows the values of the parameters that are
+ set in the queries.
+ </para>
+ <programlisting>org.hibernate.SQL.level=FINEST
+org.hibernate.type.level=FINEST</programlisting>
+ <para>And in case you get a failed batch as a cause in a hibernate exception,
+ you might want to set the batch size to 0 like this in the hibernate properties:
+ </para>
+ <programlisting>hibernate.jdbc.batch_size = 0</programlisting>
+ <para>Also in the hibernate properties, the following properties allow for
+ detailed logs of the SQL that hibernate spits out:</para>
+ <programlisting>hibernate.show_sql = true
+hibernate.format_sql = true
+hibernate.use_sql_comments = true</programlisting>
+ </section>
+</chapter>
\ No newline at end of file
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AdvancedGraphExecution.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AdvancedGraphExecution.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AdvancedGraphExecution.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,324 +0,0 @@
-<chapter id="advancedgraphexecution">
- <title>Advanced graph execution</title>
-
- <!-- ### LOOPS ########################################################## -->
- <section>
- <title>Loops</title>
- <para>Loops can be based on transitions or on node composition. Loops can contain wait
- states.
- </para>
- <para>To support high numbers of automatic loop executions, the Process Virtual Machine
- tranformed the propagation of execution from tail recursion to a while loop. This means
- that all the methods in the <literal>Execution</literal> class that propagate the
- execution like <literal>take</literal> or <literal>execute</literal> will not be
- executed when you call them. Instead, the method invocations will be appended to a list.
- The first invocation of such a method will start a loop that will execute all invocations
- till that list is empty. These invocations are called atomic operations.
- </para>
- </section>
-
- <!-- ### SUB PROCESSES ################################################## -->
- <section>
- <title>Sub processes</title>
- <para>TODO: sub processes</para>
- </section>
-
- <!-- ### DEFAULT PROCEED BEHAVIOUR ###################################### -->
- <section id="defaultproceedbehaviour">
- <title>Default proceed behaviour</title>
- <para>When an <literal>Activity</literal> is used as node behaviour, it can
- explicitely propagate the execution with following methods:
- </para>
- <itemizedlist>
- <listitem><literal>waitForSignal()</literal></listitem>
- <listitem><literal>take(Transition)</literal></listitem>
- <listitem><literal>end(*)</literal></listitem>
- <listitem><literal>execute(Node)</literal></listitem>
- <listitem><literal>createExecution(*)</literal></listitem>
- </itemizedlist>
- <para>When <literal>Activity</literal> implementations used for node behviour
- don't call any of the following execution propagation methods, then, after
- the activity is executed, the execution will just proceed.
- </para>
- <para>By default proceeding will perform the first action that applies
- in the following list:</para>
- <itemizedlist>
- <listitem>If the current node has a default outgoing transition, take it.</listitem>
- <listitem>If the current node has a parent node, move back to the parent node.</listitem>
- <listitem>Otherwise, end this execution.</listitem>
- </itemizedlist>
- <para>Process languages can overwrite the default proceed behaviour
- by overriding the <literal>proceed</literal> method in
- <literal>ExecutionImpl</literal>.
- </para>
- </section>
-
- <!-- ### FUNCTIONAL ACTIVITIES ################################ -->
- <section id="functionalactivities">
- <title>Functional activities</title>
- <para>Activities that also can be used as event listeners are called functional
- activities. Examples of automatic activities are sending an email, doing a database
- update, generating a pdf, calculating an average, etc. All of these are automatic
- activities that do not change the execution flow. Here's how such activities can
- be implemented:
- </para>
- <programlisting>public class FunctionalActivity implements Activity, EventListener {
- public void execute(ActivityExecution execution) {
- perform(execution);
- }
- public void notify(EventListenerExecution execution) {
- perform(execution);
- }
- void perform(OpenExecution execution) {
- ...do functional work...
- }
- }</programlisting>
- <para>None of these methods actually invoke execution propagation methods.
- So after the perform method is completed, the execution will
- <link linkend="defaultproceedbehaviour">proceed in the default way</link>.
- </para>
- </section>
-
-
- <!-- ### EXECUTION AND THREADS ########################################## -->
- <section id="executionandthreads">
- <title>Execution and threads</title>
- <para>This section explains how the Process Virtual Machine boroughs the thread
- from the client to bring an execution from one wait state to another.
- </para>
- <para>When a client invokes a method (like e.g. the signal method) on an execution,
- by default, the Process Virtual Machine will use that thread to progress the execution
- until it reached a wait state. Once the next wait state has been reached, the
- method returns and the client gets the thread back. This is the default way
- for the Process Virtual Machine to operate. Two more levels of asynchonous
- execution complement this default behaviour:
- <link linkend="asynchronouscontinuations">Asynchronous continuations</link>
- and the <link linkend="architecture">asynchronous command service</link>.
- </para>
- <para>The next process will show the basics concretely. It has three wait states
- and four automatic nodes.
- </para>
- <figure id="automatic">
- <title>Process with many sequential automatic activities.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.png"/></imageobject></mediaobject>
- </figure>
- <para>Here's how to build the process:</para>
- <programlisting>ProcessDefinition processDefinition = ProcessFactory.build("automatic")
- .<emphasis role="bold">node("wait 1").initial()</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
- .transition().to("automatic 1")
- .<emphasis role="bold">node("automatic 1")</emphasis>.behaviour(new <emphasis role="bold">Display("one")</emphasis>)
- .transition().to("wait 2")
- .<emphasis role="bold">node("wait 2")</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
- .transition().to("automatic 2")
- .<emphasis role="bold">node("automatic 2")</emphasis>.behaviour(new <emphasis role="bold">Display("two")</emphasis>)
- .transition().to("automatic 3")
- .<emphasis role="bold">node("automatic 3")</emphasis>.behaviour(new <emphasis role="bold">Display("three")</emphasis>)
- .transition().to("automatic 4")
- .<emphasis role="bold">node("automatic 4")</emphasis>.behaviour(new <emphasis role="bold">Display("four")</emphasis>)
- .transition().to("wait 3")
- .<emphasis role="bold">node("wait 3")</emphasis>.behaviour(new <emphasis role="bold">WaitState</emphasis>())
-.done();</programlisting>
- <para>Let's walk you through one execution of this process.
- </para>
- <programlisting>Execution execution = processDefinition.startExecution();</programlisting>
- <para>Starting a new execution means that the initial node is executed. So if an automatic
- activity would be configured as the behaviour in the initial node, the process will start executing
- immediatly in the startExecution. In this case however, the initial node is a wait state. So
- the startExecution method returns immediately and the execution will be positioned in the initial
- node 'wait 1'.
- </para>
- <figure id="automatic.wait1">
- <title>A new execution will be positioned in 'wait 1'.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait1.png"/></imageobject></mediaobject>
- </figure>
- <para>Then an external trigger is given with the signal method.</para>
- <programlisting>execution.signal();</programlisting>
- <para>As explained above when introducing the WaitState, that signal will cause the default transition to be taken. The
- transition will move the execution to node <literal>automatic 1</literal> and execute it. The execute method
- of the <literal>Display</literal> activity in <literal>automatic 1</literal> print a line to the console and it
- will <emphasis role="bold">not</emphasis> call <literal>execution.waitForSignal()</literal>. Therefore, the execution
- will proceed by taking the default transition out of <literal>automatic 1</literal>. The signal method is still blocking
- cause this action and the transitions are taken
- by that same thread. Then the execution arrives in <literal>wait 2</literal> and executes the <literal>WaitState</literal>
- activity. That method will invoke the <literal>execution.waitForSignal()</literal>, which will cause the signal method
- to return. That is when the thread is given back to the client that invoked the signal method.
- </para>
- <para>So when the signal method returns, the execution is positioned in <literal>wait 2</literal>.</para>
- <figure id="automatic.wait2">
- <title>One signal brought the execution from 'initial' to 'wait 2'.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait2.png"/></imageobject></mediaobject>
- </figure>
- <para>Then the execution is now waiting for an external trigger just as an object (more precisely an object graph) in
- memory until the next external trigger is given with the signal method.
- </para>
- <programlisting>execution.signal();</programlisting>
- <para>This second invocation of signal will take the execution similarly all the way to <literal>wait 3</literal> before
- it returns.
- </para>
- <figure id="automatic.wait3">
- <title>The second signal brought the execution all the way to 'wait 3'.</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.automatic.wait3.png"/></imageobject></mediaobject>
- </figure>
- <para>To make executable processes, developers need to know exactly what the automatic activities,
- what the wait states are and which threads will be allocated to the process execution. For business
- analysts that draw the analysis process, things are a bit simpler. For the
- activities they draw, they usually know whether it's a human or a system that is responsible.
- But they typically don't not how this translates to threads and transactions.
- </para>
- <para>So for the developer, the first job is to analyse what needs to be executed
- within the thread of control of the process and what is outside. Looking for the external
- triggers can be a good start to find the wait states in a process, just like verbs and nouns
- can be the rule of thumb in building UML class diagrams.
- </para>
- </section>
-
- <!-- ### PROCESS CONCURRENCY ############################################ -->
- <section>
- <title>Process concurrency</title>
- <para>To model process concurrency, there is a parent-child tree structure on the
- execution. The idea is that the main path of execution is the root of that tree.
- This implies that on the level of the Process Virtual Machine, there is no differentiation
- between complete process instances and paths of execution within a process instance.
- One of the main motivations for this design is that the API actually is not made more
- complex then necessary for simple processes with only one single path of execution.
- </para>
- <figure id="execution.structure">
- <title>UML class diagram of the basic execution structure</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.execution.structure.classes.png"/></imageobject></mediaobject>
- </figure>
- <para>To extablish multiple concurrent paths of execution, child executions can be
- created. Only leaf executions can be active. Non-leave executions should be
- inactive. This tree structure of executions doesn't enforce a particular type of
- concurrency or join behaviour. It's up to the forks or and-splits and to the joins
- or and-merges to use the execution tree structure in any way they want to define
- the wanted concurrency behaviour. Here you see an example
- of concurrent executions.
- </para>
- <figure id="concurrency">
- <title>Concurrent paths of execution</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.concurrency.png"/></imageobject></mediaobject>
- </figure>
- <para>There is a billing and a shipping path of execution. In this case, the
- flat bar nodes represent nodes that fork and join. The execution shows a three
- executions. The main path of execution is inactive (represented as gray) and the
- billing and shipping paths of execution are active and point to the node
- <literal>bill</literal> and <literal>ship</literal> respectively.
- </para>
- <para>It's up to the node behaviour implementations how they want to use this
- execution structure. Suppose that multiple tasks have to be completed before the
- execution is to proceed. The node behaviour can spawn a series of child executions
- for this. Or alternatively, the task component could support task groups that
- are associated to one single execution. In that case, the task component becomes
- responsible for synchronizing the tasks, thereby moving this responsibility
- outside the scope of the execution tree structure.
- </para>
- </section>
-
- <!-- ### EXCEPTION HANDLERS ############################################# -->
- <section>
- <title>Exception handlers</title>
- <para>In all the <link linkend="delegationclasses">code that is associated to a process</link>
- like Activity's, Actions and Conditions, it's possible to include try-catch blocks in
- the method implementations to handle exceptions. But in order to build more reusable building
- blocks for both the delegation classes and the exception handling logic, exception handlers are
- added to the core process model.
- </para>
- <para>An exception handler can be associated to any process element. When an exception
- occurs in a delegation class, a matching exception handler will be searched for. If
- such an exception handler is found, it will get a chance to handle the exception.
- </para>
- <para>If an exception handler completes without problems, then the exception is considered
- handled and the execution resumes right after the delegation code that was called. For example,
- a transition has three actions and the second action throws an exception that is handled
- by an exception handler, then
- </para>
- <para>Writing automatic activities that are exception handler aware is easy. The
- default is to proceed anyway. No method needs to be called on the execution. So
- if an automatic activity throws an exception that is handled by an exception handler,
- the execution will just proceed after that activity. It becomes a big more difficult
- for control flow activities. They might have to include try-finally blocks to
- invoke the proper methods on the execution before an exception handler gets a
- chance to handle the exception. For example, if an activity is a wait state and
- an exception occurs, then there is a risk that the thread jumps over the
- invocation of <literal>execution.waitForSignal()</literal>, causing the execution
- to proceed after the activity.
- </para>
- <para>TODO: exceptionhandler.isRethrowMasked</para>
- <para>TODO: transactional exception handlers</para>
- <para>TODO: we never catch errors</para>
- </section>
-
- <!-- ### PROCESS MODIFICATIONS ########################################## -->
- <section>
- <title>Process modifications</title>
- <para>TODO: process modifications</para>
- </section>
-
- <!-- ### LOCKING AND EXECUTION STATE #################################### -->
- <section>
- <title>Locking and execution state</title>
- <para>The state of an execution is either active or locked. An active
- execution is either executing or waiting for an external trigger. If an
- execution is not in STATE_ACTIVE, then it is locked. A locked execution
- is read only.
- </para>
- <para>When a new execution is created, it is in STATE_ACTIVE. To change
- the state to a locked state, use lock(String). Some STATE_* constants
- are provided that represent the most commonly used locked states. But
- the state '...' in the picture indicates that any string can be provided
- as the state in the lock method.
- </para>
- <figure id="execution.states">
- <title>States of an execution</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/ch04.execution.states.png"/></imageobject></mediaobject>
- </figure>
- <para>If an execution is locked, methods that change the execution will
- throw a PvmException and the message will reference the actual locking state.
- Firing events, updating variables, updating priority and adding comments
- are not considered to change an execution. Also creation and removal of child
- executions are unchecked, which means that those methods can be invoked by
- external API clients and node behaviour methods, even while the execution
- is in a locked state.
- </para>
- <para>Make sure that comparisons between getState() and the STATE_* constants
- are done with .equals and not with '==' because if executions are loaded
- from persistent storage, a new string is created instead of the constants.
- </para>
- <para>An execution implementation will be locked:
- </para>
- <itemizedlist>
- <listitem>When it is ended</listitem>
- <listitem>When it is suspended</listitem>
- <listitem>During asynchronous continuations</listitem>
- </itemizedlist>
- <para>Furthermore, locking can be used by Activity implementations to make
- executions read only during wait states hen responsibility for the execution is
- transferred to an external entity such as:
- </para>
- <itemizedlist>
- <listitem>A human task</listitem>
- <listitem>A service invocation</listitem>
- <listitem>A wait state that ends when a scanner detects that a file appears</listitem>
- </itemizedlist>
- <para>In these situations the strategy is that the external entity should get
- full control over the execution because it wants to control what is allowed
- and what not. To get that control, they lock the execution so that all interactions
- have to go through the external entity.
- </para>
- <para>One of the main reasons to create external entities is that they can live
- on after the execution has already proceeded. For example, in case
- of a service invocation, a timer could cause the execution to take the timeout transition.
- When the response arrives after the timeout, the service invocation entity should
- make sure it doesn't signal the execution. So the service invocation can be
- seen as a node instance (aka activity instance) and is unique for every execution
- of the node.
- </para>
- <para>External entities themselves are responsible for managing the execution
- lock. If the timers and client applications are consequent in addressing the
- external entities instead of the execution directly, then locking is in theory
- unnecessary. It's up to the node behaviour implementations whether they want
- to take the overhead of locking and unlocking.
- </para>
- </section>
-
-</chapter>
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AsynchronousContinuations.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AsynchronousContinuations.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-AsynchronousContinuations.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,3 +0,0 @@
-<chapter id="asynchronouscontinuations">
- <title>Asynchronous continuations</title>
-</chapter>
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-SoftwareLogging.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-SoftwareLogging.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-SoftwareLogging.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,99 +0,0 @@
-<chapter id="softwarelogging">
- <title>Software logging</title>
-
- <section>
- <title>Configuration</title>
- <para>PVM can use JDK logging (java.util.logging) or log4j. When the first message is
- logged, PVM logging will make the selection with following procedure:
- <orderedlist>
- <listitem>If a <literal>logging.properties</literal> resource is found
- on the classpath (using the context classloader), then JDK logging will
- be used and that file will be used to initialize the JDK logging.
- </listitem>
- <listitem>If log4j is found on the classpath, then log4j will be used.
- The check for log4j will be done by checking availability of class
- <literal>org.apache.log4j.LogManager</literal> with the context classloader.
- </listitem>
- <listitem>If none of the above, JDK logging will be used.</listitem>
- </orderedlist>
- </para>
- </section>
-
- <section>
- <title>Categories</title>
- <para>The PVM classes use their class name as the category for the logger.
- </para>
- <para>To have a basic understanding of what the PVM classes are doing,
- turning on the <literal>debug</literal> level is great. Level
- <literal>trace</literal> might be spitting out too much for that
- purpose.
- </para>
- </section>
-
- <section>
- <title>JDK logging</title>
- <para>In JDK logging, <literal>debug</literal>maps to <literal>fine</literal>
- and <literal>trace</literal> maps to <literal>finest</literal>.
- Level <literal>finer</literal> is not used.
- </para>
- <para><literal>org.jbpm.pvm.internal.log.LogFormatter</literal> is part of
- the pvm library and it can create a nice one-line output for log messages.
- It also has a neat feature that creates a unique indentation per thread.
- To configure it, this is a typical <literal>logging.properties</literal>
- </para>
- <programlisting>handlers = java.util.logging.ConsoleHandler
-java.util.logging.ConsoleHandler.level = FINEST
-java.util.logging.ConsoleHandler.formatter = org.jbpm.pvm.internal.log.LogFormatter
-
-# For example, set the com.xyz.foo logger to only log SEVERE messages:
-# com.xyz.foo.level = SEVERE
-
-.level = SEVERE
-org.jbpm.level=FINE
-org.jbpm.tx.level=FINE
-org.jbpm.pvm.internal.wire.level=FINE</programlisting>
-
-<!--
- <para>For production usage, jBPM also includes an error triggered log handler. This is
- a log handler that will only keep the most recent log messages in
- memory and these will only be flushed to a file in case an error occurs.
- </para>
- <para>to configure it, add <literal>org.jbpm.util.ErrorTriggeredFileHandler</literal>
- to the handlers in the logging properties like this:
- </para>
- <programlisting>handlers = java.util.logging.ConsoleHandler org.jbpm.util.ErrorTriggeredFileHandler</programlisting>
- <para>Next snippet shows how in the same logging.properties, the error
- triggered file handler can be configured. The given values are the default
- values.
- </para>
- <programlisting>org.jbpm.util.ErrorTriggeredFileHandler.size = 500
-org.jbpm.util.ErrorTriggeredFileHandler.push = SEVERE
-org.jbpm.util.ErrorTriggeredFileHandler.pattern = %h/jbpm%u.log</programlisting>
- <para>Alternatively to using the org.jbpm.util.ErrorTriggeredFileHandler, the
- JDK handlers FileHandler and MemoryHandler can used in combination to get
- similar results with a bit more configuration.
- </para>
-
--->
- </section>
-
- <section>
- <title>Debugging persistence</title>
- <para>When testing the persistence, following logging configurations can be
- valuable. Category <literal>org.hibernate.SQL</literal> shows the SQL statement that is executed
- and category <literal>org.hibernate.type</literal> shows the values of the parameters that are
- set in the queries.
- </para>
- <programlisting>org.hibernate.SQL.level=FINEST
-org.hibernate.type.level=FINEST</programlisting>
- <para>And in case you get a failed batch as a cause in a hibernate exception,
- you might want to set the batch size to 0 like this in the hibernate properties:
- </para>
- <programlisting>hibernate.jdbc.batch_size = 0</programlisting>
- <para>Also in the hibernate properties, the following properties allow for
- detailed logs of the SQL that hibernate spits out:</para>
- <programlisting>hibernate.show_sql = true
-hibernate.format_sql = true
-hibernate.use_sql_comments = true</programlisting>
- </section>
-</chapter>
\ No newline at end of file
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Timers.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Timers.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Timers.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,3 +0,0 @@
-<chapter id="timers">
- <title>Timers</title>
-</chapter>
\ No newline at end of file
Deleted: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Variables.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Variables.xml 2008-09-18 07:25:16 UTC (rev 2278)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/chxx-Variables.xml 2008-09-18 13:55:29 UTC (rev 2279)
@@ -1,3 +0,0 @@
-<chapter id="variables">
- <title>Variables</title>
-</chapter>
\ No newline at end of file
More information about the jbpm-commits
mailing list