jBPM Loops Concept

Hello all, As told i will be posting jBPM tutorials from now, here is my next tutorial on jBPM loops. prior to this tutorial please download jBPM 5.x version and install the demo environment after that open the eclipse jBPM editor and code the process as shown below. just by drag and drop the BPM components.

jbpm-looping

once the process is ready please click on the empty space of the editor and edit the properties as below.

process_init_var

now click the “first log node” as shown below and open the property Palette edit the action Values as shown below.
the “kcontext” is the jBPM KnowledgeContext available inorder to access the process variables.
Edit_log1

in the process shown there are two gateways the first one is converging gateway and the second one is diverging gateway. i will post a seperate article on gateways later.click on the first gateway and assign XOR as value for the type value. now click the second log node and in the property pallete edit the properties and put the simple logic as shown below.

Edit_log2

Now click on the second gateway since it is the converging gateway, click the Condition browse button and add a condition as shown below.

ifCondition

now lets give the else logic as shown below.else

once done lets prompt the process that it is done by editing the last log node.
now its time for a test run of the process

package com.spark.jbpm.sample.loops;

import java.util.HashMap;
import java.util.Map;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * @author Sony
 *
 */
public class LoopingExample {
	
	public static final void main(String[] args) {
		try {
			// load up the knowledge base
			KnowledgeBase kbase = readKnowledgeBase();
			StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
			KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
			// start a new process instance
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("count", 5);
			ksession.startProcess("com.sample.looping", params);
			logger.close();
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

	private static KnowledgeBase readKnowledgeBase() throws Exception {
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		kbuilder.add(ResourceFactory.newClassPathResource("looping/Looping.bpmn"), ResourceType.BPMN2);
		return kbuilder.newKnowledgeBase();
	}

}

and finally u will see the O/P of your first jBPM Process.

Happy jBPM 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s