[jboss-user] [jBPM] - Re: How to make a process instance go on with jBPM5?

Esteban Aliverti do-not-reply at jboss.com
Sat Apr 16 11:01:15 EDT 2011

Esteban Aliverti [http://community.jboss.org/people/eaa] created the discussion

"Re: How to make a process instance go on with jBPM5?"

To view the discussion, visit: http://community.jboss.org/message/600431#600431

In jBPM5, when you start a process, it executes all the nodes it can. If you don't have any wait-state, then the process will be completed when the session.startProcess() method returns. 
There are 3 ways (somebody please correct me if I'm forgeting someone) to define wait-points:
1. Asyncronous WorkItemHandlers in your Service Task Nodes:
When you define a Service Task in your process, you need to assign a handler for it. This handler could be synchronous or asynchronous. It will be synchronous only if you invoque workItemManager.completeWorkItem() inside handler's executeWorkItem() method. The only difference with asynchnornous handlers is that they don't complete the work item inside. They delegate this behaviour to an external mechanism. 
When the process finds a Service Task Node, its executes the associated handler. If the handler conpletes the work item, the execution continues. If the handler doesn't complete the work item, the process reaches a wait-state (if there are no more parallel paths to continue with). When the process reaches a wait-state, it state is persisted (if you are using persistence, of course  :p ).
Asynchronous work item handlers are good for (time) expensive calls to external systems. If you don't know how long the external sytem will take to respond, then you could use an asynchronous work item handler. The process will call the external system, everythng is going to be persisted and you can even dispose you ksession and stop the Thread that performed the startProcess() call. You still need to have a mechanism for continue the execution of the process when the external system ends. You will need at least the id of the ksession and the id of the work item to be able to restore you ksession ( JPAKnowledgeService.loadStatefulKnowledgeSession() ) and to complete the work item ( ksession.getWorkItemManager().completeWorkItem()). The completeWorkItem() method wil execute as many nodes as it can until it reaches a new wait-point or until the process finishes.
2. Human Task Nodes: Human tasks are handled like asynchronous Work Items by jBPM5. jBPM5 already comes with a WorkItemHandler implementation for Human Tasks: WSHumanTaskHandler. This handler will communicate with a Task Service (also provided by jBPM5) and create a new Task in it. Then, it will wait for someone (using Human Client API) to complete/cancel the task.
3. External Events: You can define external events handlers in your process using an intermediateCatchEvent. Then, from outside your process you can signal the event using ksession.signalEvent() method. If you combine a intermediateCatchEvent with a converging parallel gateway, you get a wait-state.

I have a set of simple tests that show some of the things I have mentioned here. You can download and try them from here:
 https://github.com/esteban-aliverti/JBPM-Samples https://github.com/esteban-aliverti/JBPM-Samples

Best Regards,

Reply to this message by going to Community

Start a new discussion in jBPM at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110416/321f1060/attachment.html 

More information about the jboss-user mailing list