Vous êtes sur la page 1sur 7

Sponsored by:

This story appeared on JavaWorld at http://www.javaworld.com/javaworld/jw-05-2006/jw-0522-jbpm.html

Manage your business processes with JBoss jBPM


Get started using JBoss's business process management tool
By Jeff Hanson, JavaWorld.com, 05/22/06 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, domainspecific 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 as jPDL.

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:
i m p o r to r g . j b p m . g r a p h . d e f . * ; i m p o r to r g . j b p m . g r a p h . e x e . * ;

p u b l i cc l a s sM y A c t i o n H a n d l e r i m p l e m e n t sA c t i o n H a n d l e r { p u b l i cv o i de x e c u t e ( E x e c u t i o n C o n t e x te x e c u t i o n C o n t e x t ) { S y s t e m . o u t . p r i n t l n ( " M y A c t i o n H a n d l e rh a se x e c u t e d :"+e x e c u t i o n C o n t e x t ) ; } }

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 processdefinition.xml file is illustrated in the following example:
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " U T F 8 " ? > < ! D O C T Y P Ep r o c e s s d e f i n i t i o nP U B L I C" / / j b p m / j B P MM a p p i n gD T D2 . 0 / / E N "" h t t p : / / j B P M . o r g / d t d / p r o c e s s d e f i n i t i o n 2 . 0 . d t d " > < p r o c e s s d e f i n i t i o nn a m e = " p u r c h a s ep r o c e s s " > < ! . . . > < ! -S T A R T S T A T E> < s t a r t s t a t en a m e = " r e q u e s tap u r c h a s e " > < t r a n s i t i o nt o = " e v a l u a t i n g " / > < / s t a r t s t a t e >

< ! -N O D E S> < s t a t en a m e = " e v a l u a t i n g " > < ! . . . > < t r a n s i t i o nn a m e = " a p p r o v e " t o = " p u r c h a s ea p p r o v e d " / > < t r a n s i t i o nn a m e = " d i s a p p r o v e " t o = " d o n e " / > < / s t a t e > < f o r kn a m e = " p u r c h a s ea p p r o v e d " > < t r a n s i t i o nt o = " d e c r e m e n ti n v e n t o r y "/ > < t r a n s i t i o nt o = " i n c r e m e n tr e v e n u e "/ > < / f o r k >

< s t a t en a m e = " d e c r e m e n ti n v e n t o r y " > < ! . . . > < t r a n s i t i o nt o = " j o i n "/ > < / s t a t e >

< s t a t en a m e = " i n c r e m e n tr e v e n u e " > < ! . . . > < t r a n s i t i o nt o = " j o i n "/ > < / s t a t e > < j o i nn a m e = " j o i n " > < t r a n s i t i o nt o = " d o n e "/ > < / j o i n >

< ! -E N D S T A T E> < e n d s t a t en a m e = " d o n e "/ > < / p r o c e s s d e f i n i t i o n >

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 p a rAnt 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:
< ? x m lv e r s i o n = " 1 . 0 " ? >

< p r o c e s s d e f i n i t i o nn a m e = " w e b s a l e " x m l n s = " u r n : j b p m . o r g : j p d l 3 . 1 " >

< ! -S W I M L A N E S( =p r o c e s sr o l e s )>

< s w i m l a n en a m e = " b u y e r "/ > < s w i m l a n en a m e = " s a l e s m a n " > < a s s i g n m e n te x p r e s s i o n = " u s e r ( e r n i e ) "/ > < / s w i m l a n e > < s w i m l a n en a m e = " a c c o u n t a n t " > < a s s i g n m e n te x p r e s s i o n = " u s e r ( b e r t ) "/ > < / s w i m l a n e > < s w i m l a n en a m e = " s h i p p e r " > < a s s i g n m e n te x p r e s s i o n = " u s e r ( g r o v e r ) "/ > < / s w i m l a n e > < ! -N O D E S>

< s t a r t s t a t en a m e = " c r e a t en e ww e bs a l eo r d e r " > < t a s ks w i m l a n e = " b u y e r " > < c o n t r o l l e r > < v a r i a b l en a m e = " i t e m " / > < v a r i a b l en a m e = " q u a n t i t y " / > < v a r i a b l en a m e = " a d d r e s s " / > < / c o n t r o l l e r > < / t a s k > < t r a n s i t i o nt o = " e v a l u a t ew e bo r d e r "/ > < / s t a r t s t a t e > < t a s k n o d en a m e = " e v a l u a t ew e bo r d e r " > < t a s ks w i m l a n e = " s a l e s m a n " > < t i m e rd u e d a t e = " 2 0s e c o n d s "r e p e a t = " 1 0s e c o n d s " > < a c t i o nc l a s s = " o r g . j b p m . w e b s a l e . R e m i n d A c t o r " > < s w i m l a n e N a m e > s a l e s m a n < / s w i m l a n e N a m e > < / a c t i o n > < / t i m e r > < c o n t r o l l e r > < v a r i a b l en a m e = " i t e m "a c c e s s = " r e a d " / > < v a r i a b l en a m e = " q u a n t i t y "a c c e s s = " r e a d " / > < v a r i a b l en a m e = " a d d r e s s "a c c e s s = " r e a d " / > < v a r i a b l en a m e = " c o m m e n t " / > < / c o n t r o l l e r > < / t a s k > < t r a n s i t i o nn a m e = " o k "t o = " s a l e f o r k "/ >

< t r a n s i t i o nn a m e = " m o r ei n f on e e d e d "t o = " f i xw e bo r d e rd a t a "/ > < / t a s k n o d e >

< t a s k n o d en a m e = " f i xw e bo r d e rd a t a " > < t a s ks w i m l a n e = " b u y e r " > < c o n t r o l l e r > < v a r i a b l en a m e = " c o m m e n t "a c c e s s = " r e a d " / > < v a r i a b l en a m e = " i t e m "/ > < v a r i a b l en a m e = " q u a n t i t y "/ > < v a r i a b l en a m e = " a d d r e s s "/ > < / c o n t r o l l e r > < / t a s k > < t r a n s i t i o nt o = " e v a l u a t ew e bo r d e r "/ > < / t a s k n o d e >

< f o r kn a m e = " s a l e f o r k " > < t r a n s i t i o nn a m e = " p a y m e n t " t o = " w a i tf o rm o n e y "/ > < t r a n s i t i o nn a m e = " s h i p p i n g "t o = " s h i pi t e m "/ > < / f o r k > < t a s k n o d en a m e = " w a i tf o rm o n e y " > < t a s ks w i m l a n e = " a c c o u n t a n t " > < c o n t r o l l e r > < v a r i a b l en a m e = " i t e m "a c c e s s = " r e a d "/ > < v a r i a b l en a m e = " q u a n t i t y "a c c e s s = " r e a d "/ > < v a r i a b l en a m e = " a d d r e s s "a c c e s s = " r e a d "/ > < v a r i a b l en a m e = " m o n e yr e c e i v e d "/ > < / c o n t r o l l e r > < / t a s k > < t r a n s i t i o nt o = " u p d a t eb o o k s "/ > < / t a s k n o d e > < n o d en a m e = " u p d a t eb o o k s " > < a c t i o nc l a s s = " o r g . j b p m . w e b s a l e . U p d a t e B o o k s " > < m s g > a c c o u n t a n c ya p p l i c a t i o ni sn o wi n f o r m e do ft h ep a y m e n t < / m s g > < / a c t i o n > < t r a n s i t i o nt o = " s a l e j o i n "/ > < / n o d e > < n o d en a m e = " s h i pi t e m " > < a c t i o nc l a s s = " o r g . j b p m . w e b s a l e . S h i p I t e m " > < s w i m l a n e N a m e > s h i p p e r < / s w i m l a n e N a m e > < m s g > $ { s h i p p e r }n o ws h i p s$ { i t e m }t o$ { a d d r e s s } < / m s g > < / a c t i o n > < t r a n s i t i o nt o = " s a l e j o i n "/ > < / n o d e > < j o i nn a m e = " s a l e j o i n " > < t r a n s i t i o nt o = " e n d "/ > < / j o i n >

< e n d s t a t en a m e = " e n d "/ >

< / p r o c e s s d e f i n i t i o n >

Once the Create New Web Sale Order page is loaded, fill out the Item and Quantity form fields with cookie as the item and 1 as 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.

About the author


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.
All contents copyright 1995-2013 Java World, Inc. http://www.javaworld.com

Vous aimerez peut-être aussi