Académique Documents
Professionnel Documents
Culture Documents
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 >
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
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 " ? >
< ! -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 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 >
< / 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.