[jboss-user] [jBPM] New message: "Re: Exception handling in JBPM4 ?"
Hernan Rodriguez
do-not-reply at jboss.com
Tue Mar 2 15:32:47 EST 2010
User development,
A new message was posted in the thread "Exception handling in JBPM4 ?":
http://community.jboss.org/message/529477#529477
Author : Hernan Rodriguez
Profile : http://community.jboss.org/people/HernanRodriguez
Message:
--------------------------------------------------------------
My solution for the problem is:
Define a abstract class, implementing ExternalActivityBehaviour.
package cl.pred.cmh.bpm.events.controller;
import java.util.Map;
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.activity.ExternalActivityBehaviour;
public abstract class ControllerAbstract implements ExternalActivityBehaviour {
@Override
public void signal(ActivityExecution activityExecution, String arg1, Map<String, ?> arg2)
throws Exception {
execute(activityExecution);
}
@Override
public void execute(ActivityExecution activityExecution) throws Exception {
try {
procesar();
activityExecution.takeDefaultTransition();
} catch (Exception e) {
activityExecution.waitForSignal();
}
}
protected abstract void procesar() throws Exception;
}
Then, define a Controller Class extending the abstract class.
public class Controller extends ControllerAbstract {
@Override
protected void procesar() throws Exception {
BusinessHelper.doSomething();
}
}
I defined three custom nodes in my model. These nodes were associated to the Controller Class.
<?xml version="1.0" encoding="UTF-8"?>
<process name="test" xmlns="http://jbpm.org/4.2/jpdl">
<start name="start1" g="28,32,48,48">
<transition name="to custom1" to="custom1" g="-10,-27"/>
</start>
<custom name="custom1" g="84,104,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController" >
<transition name="to custom2" to="custom2" g="9,-16"/>
</custom>
<custom name="custom2" g="166,176,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController">
<transition name="to custom3" to="custom3" g="-3,-25"/>
</custom>
<custom name="custom3" g="258,258,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController">
<transition name="to end1" to="end1" g="30,-36"/>
</custom>
<end name="end1" g="354,325,48,48"/>
</process>
For example, if BusinessHelper.doSomething() throw an Exception in custom 2 node, the "activityExecution.waitForSignal()" method will be invoked. This method commit the transaction and stops the execution.
Then, if we need resume the process, we can use the "executionService.signalExecutionById(processKey)" method from a Web Service, Servlet, EJB, Helper, Timer or whatever.
This example, with some variations, works for me ... and very good.
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/529477#529477
More information about the jboss-user
mailing list