Monday, December 23, 2013



Manage your business processes with JBoss jBPM


By
 Jeff HansonGet started using JBoss's business process management tool




Enterprises have searched diligently for a structured approach for designing business actions/transactions and executing them preferably using automated processes. Business process management (BPM) and workflow management offer a solution to this problem using concepts such as actions, tasks, and flows.

This article introduces BPM and discusses techniques and tools to empower enterprise systems with BPM and workflow management using JBoss jBPM.
The term business process management typically refers to a set of activities enterprises can employ to automate and optimize business processes in a manner adaptable to dynamically changing environments. These activities usually seek help from software engineering and tools; therefore, the term BPM is often used directly to refer to the engineering techniques and tools.
BPM is embodied in three distinct practices:
  1. Process design: The task of designing existing and new processes
  2. Process execution: The execution of an automated sequence of related events involving software processes and/or human activities
  3. Process monitoring: Observance and auditing of the state of individual processes so that the statistics and performance of these processes can be recorded, reported, and optimized
BPM seeks to allow software engineers to share the same concepts and frameworks as business analysts; consequentially, software vendors have attempted to create tools that will allow enterprises to capture, design, and optimize business processes through the employment of graphical modeling tools, domain-specific languages, and proprietary applications.
JBoss jBPM 3.0 delivers the capability of developing new automated business processes and workflows with industry-standard orchestration using Business Process Execution Language (BPEL), a flexible and pluggable API, a native process definition language, and a graphical modeling tool.
JBoss jBPM is an open source (LGPL license) framework of Java APIs, tools, and a definition language that can operate as a Web application or a standalone Java application. JBoss jBPM acts as an intermediary between business analysts and developers by giving them a common process definition language referred to asjPDL.

Overview of the JBoss jBPM architecture

JBoss jBPM defines process definitions within files written using the JBoss process definition language. jPDL is a graphic-oriented programming (GOP) language based on a model of nodes, transitions, and actions. In this model, nodes are commands executed as they are encountered during the flow of a process definition. Transitions direct the flow of execution of a process definition, and actions perform specific logic as a node or transition event occurs.In jBPM, process definitions are packaged as process archives. A process archive is passed to the jPDL process engine for execution. The jPDL process engine traverses a process graph, executes defined actions, maintains process state, and logs all process events.
JBoss jBPM is encapsulated within the following components:
  • Process engine: This component executes defined process actions, maintains process state, and logs all process events via the following delegate components:
    • A request handler
    • A state manager
    • A log manager
    • A definition loader
    • An execution service
  • Process monitor: This module tracks, audits, and reports the state of processes as they execute
  • Process language: The process definition language (jPDL) is based on GOP
  • Interaction services: These services expose legacy applications as functions or data to be used in process executions
The relationships between these components are illustrated in Figure 1.

Figure 1. Component relationships of JBoss jBPM. Click on thumbnail to view full-sized image.

As shown in Figure 1, jBPM process definitions containing action handlers are loaded and executed by the jBPM process engine. When the process engine encounters a node in the process definition that has an action associated with it, all related action handlers are invoked. Action handlers are instances of Java code that interact with external systems when executed.
The following is an example of a simple action handler:
 
import org.jbpm.graph.def.*; import org.jbpm.graph.exe.*;
public class MyActionHandler implements ActionHandler { public void execute(ExecutionContext executionContext) { System.out.println("MyActionHandler has executed: " + executionContext); } }
The PDL file in a process archive is named process-definition.xml. This file contains the formal description of the processes. An example of a process-definition.xml file is illustrated in the following example:
 
xml version="1.0" encoding="UTF-8"?> name="purchase process"> name="request a purchase"> to="evaluating"/>
name="evaluating"> name="approve" to="purchase approved"/> name="disapprove" to="done"/> name="purchase approved"> to="decrement inventory" /> to="increment revenue" />
name="decrement inventory"> to="join" />
name="increment revenue"> to="join" /> name="join"> to="done" />
name="done" />


A process definition is based on a directed graph. The graph is composed of nodes, transitions, one start state, and one end state. The type of each node defines the runtime behavior for the node. While a process definition executes, the following entities come into play:
  • Process instance: A process instance is one execution of a process definition.
  • Token: A token is one path of execution. A token is the runtime concept that maintains a pointer to a node in the graph. When a process instance is created, a token is created for the main path of execution. This token is called the process instance's root token and is positioned in the process definition's start state.
  • Signal: A signal instructs a token to continue graph execution by transition out of a node.
  • Node: Nodes are responsible for the continuation of a graph execution. When a token enters a node, the node executes. A node that does not propagate execution is regarded as a state.
  • Action: Actions are instances of Java code executed when events occur in a process execution. The primary event types are "entering a node," "leaving a node," and "taking a transition."
Process definitions can be created easily with the jBPM graphical modeling designer. The designer is currently installed as an Eclipse plug-in. Figure 2 illustrates a sample screen from the graphical modeling designer.

Figure 2. The jBPM graphical modeling designer. Click on thumbnail to view full-sized image.

The graphical designer can be used to create process definitions, attach action handlers to events, edit definition source, create process archives, test process definitions, and so on.

Deploying JBoss jBPM

JBoss jBPM stores process definitions in a database. Therefore, deploying a process into JBoss jBPM involves parsing the process-definition.xml and storing it in the JBoss jBPM database. This can be done by:
  • Using the par Ant task supplied with JBoss jBPM to create a process archive.
  • Using the deploypar utility. This utility also creates a process archive and deploys the process archive to the jBPM database. The deploypar utility takes a jBPM.properties file as an attribute. This file specifies configuration options, including the database to which the process archive is to be deployed.
  • Programmatically parsing and storing the process-definition.xml into a datastore.

Running JBoss jBPM through some simple paces

JBoss jBPM acts as an orchestration engine that sits in the middle of enterprise applications, enabling integration and coordination between different applications.
For this article, I use the sample deployment shipped with jBPM to discuss how jBPM and jPDL are used to create and modify a simple Web-enabled order processing system.

Downloading JBoss jBPM

The JBoss jBPM starter kit contains everything needed to execute JBoss jBPM, with the exception of a JDK. The JBoss Application Server in the JBoss jBPM starter kit requires J2SE 1.4 or a more recent version.
After you have downloaded the starter kit, unzip it to a directory of your choosing. Once you have unzipped the starter kit, you will have a directory structure similar to the following:
  • Jbpm-starters-kit-3.1
    • jbpm: Contains the source code for the JBoss jBPM product
    • jbpm-bpel: Contains information about the BPEL extension for JBoss jBPM
    • jbpm-db: Contains sample configurations for connecting JBoss jBPM to other databases
    • jbpm-designer: Contains the Eclipse plug-in for the JBoss jBPM Visual Process Designer
    • jbpm-server: Contains the JBoss Application Server along with the JBoss jBPM engine and the sample process

Execute the JBoss jBPM engine

To start the JBoss application server with jBPM deployed, go to the jbpm-server directory and execute the startup script found there. A command window should pop up with the jBPM console window, similar to Figure 3.

Figure 3. The jBPM console window. Click on thumbnail to view full-sized image.

Now, bring up a browser window and go to http://localhost:8080/jbpm. You will be presented with the login page for the sample Web application for JBoss jBPM, shown in Figure 4.

Figure 4. The JBoss jBPM Web application login page. Click on thumbnail to view full-sized image.

Log in as cookie monster and select the Create New Web Sale Order link. This will create a new instance of the prebuilt "Web sale" process, illustrated in Figure 5.

Figure 5. Web sale process definition. Click on thumbnail to view full-sized image.

The actual definition file, processdefinition.xml, is located in websale.par and is illustrated in the following listing:

 
xml version="1.0"?>
name="websale" xmlns="urn:jbpm.org:jpdl-3.1">
name="buyer" /> name="salesman"> expression="user(ernie)" /> name="accountant"> expression="user(bert)" /> name="shipper"> expression="user(grover)" />
name="create new web sale order"> swimlane="buyer"> name="item"/> name="quantity"/> name="address"/>
to="evaluate web order" /> name="evaluate web order"> swimlane="salesman"> duedate="20 seconds" repeat="10 seconds"> class="org.jbpm.websale.RemindActor"> salesman name="item" access="read"/> name="quantity" access="read"/> name="address" access="read"/> name="comment"/> name="ok" to="salefork" /> name="more info needed" to="fix web order data" />
name="fix web order data"> swimlane="buyer"> name="comment" access="read"/> name="item" /> name="quantity" /> name="address" />
to="evaluate web order" />
name="salefork"> name="payment" to="wait for money" /> name="shipping" to="ship item" /> name="wait for money"> swimlane="accountant"> name="item" access="read" /> name="quantity" access="read" /> name="address" access="read" /> name="money received" />
to="update books" /> name="update books"> class="org.jbpm.websale.UpdateBooks"> accountancy application is now informed of the payment to="salejoin" /> name="ship item"> class="org.jbpm.websale.ShipItem"> shipper ${shipper} now ships ${item} to ${address} to="salejoin" /> name="salejoin"> to="end" />
name="end" />



Once the Create New Web Sale Order page is loaded, fill out the Item and Quantity form fields with cookie as the item and 1as the quantity. Then select Save and Close Task to complete the Create New Web Sale Order task. The Web application will signal jBPM to move the Web sale process token to the Evaluate Web Order task and apply the data entered as process variables. At this point, the login page displays again. You will notice a message that reads, "A new task has been assigned to 'ernie'."
Now, select the Login As Another User link and log in as ernie. You will notice that the Evaluate Web Order task is highlighted. Type need address into the comment field and select the More Info Needed button. This will move the process token to the Fix Web Order Data task and return the browser to the login page.
At this point, you can log in as cookie monster and select the Fix Web Order Data link to see how the highlighted task has changed to reflect the process token's position in the execution process.
Repeat the steps for the process definition as they are presented in the browser window, logging in as the appropriate user when prompted and completing the forms for each new task. You will eventually reach the end of the process and a screen will appear telling you the process has finished.

Conclusion

JBoss jBPM provides a sophisticated platform for designing and developing workflows and business process management systems. Its framework of APIs, domain-specific language, and graphical modeling tool enables developers and business analysts to communicate and operate using a common platform.
In this article, I discussed the high-level concepts of JBoss jBPM that will give you a place to start your journey towards a workflow-oriented future with BPM and Java.

Jeff Hanson has more than 20 years of experience in the software industry, including working as senior engineer for the Windows OpenDoc project and lead architect for the Route 66 framework at Novell. Hanson is currently the chief architect for eReinsure.com, building Web service frameworks and platforms for J2EE-based reinsurance systems.

Learn more about this topic