Here is an example that shows how to invoke a sub-process from a main process.
A simple example shown in the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here.
This example has a main process as shown below. It sends a couple of parameters (count and loopcondition) to the subprocess.
The sub-process goes through a loop incrementing the value of 'count'. Once the 'count' reaches the 'do until' loop condition value, it will exit the loop and return the 'count' value to the main process. The 'loopcondition' can either be set inside this sub-process or can be retrieved from the parent process. In this example, it is set as a paramter in the main process.
How to run this example?
This example has two bpmn files (sampleLoopTest.bpmn for main process and looptest777.bpmn for sub-process loop) and a test file (LoopSubProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.
Here is the sample test code. The main process 'com.sample.bpmn.looptest' is started as shown below which inturn invokes the sub-process.
public class LoopSubProcessTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = createSession(kbase);
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "test");
// Set the initial count and loopcondition
Map<String, Object> params = new HashMap<String, Object>();
params.put("count", 1);
params.put("loopcondition", 4);
//start the main process
ksession.startProcess("com.sample.bpmn.looptest", params);
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
It is important to note that both the bpmn files need to be added to the KnowledgeBuilder as shown below.
Here are the results you would see after running the test program LoopSubProcessTest.
-
LoopSubProcessTest.java.zip 1.1 KB
-
looptest777.bpmn.zip 1.3 KB
-
sampleLoopTest.bpmn.zip 1.3 KB
Comments