-
1. Re: Jbpm 4.3 Event Listeners
sebastian.s Feb 15, 2010 4:45 AM (in response to tony2010)Please post a full unit-test for this. -
2. Re: Jbpm 4.3 Event Listeners
tony2010 Feb 15, 2010 5:17 AM (in response to sebastian.s)I dont have the unit test case but the basic code is below:
Sample Workflow:
<?xml version="1.0" encoding="UTF-8"?>
<process name="TEST" xmlns="http://jbpm.org/4.3/jpdl">
<start g="0,0,80,40">
<transition to="theEnd" />
</start>
<end g="135,72,80,40" name="theEnd" /><on event="start">
<event-listener class="WorkflowStatusEvent">
<field name="transactionId" cache="disabled">
<object expr="#{id}" />
</field>
<field name="status" >
<string value="IN_PROGRESS" />
</field>
<field name="tcn" cache="disabled">
<object expr="#{param1}" />
</field>
</event-listener>
</on>
<on event="end">
<event-listener class="WorkflowStatusEvent">
<field name="transactionId" cache="disabled">
<object expr="#{id}" />
</field>
<field name="status">
<string value="COMPLETED" />
</field>
<field name="tcn" cache="disabled">
<object expr="#{param1}" />
</field>
</event-listener>
</on>
</process>Event Listener Code:
public class WorkflowStatusEvent implements EventListener {
Logger log = Logger.getLogger(WorkflowStatusEvent.class);
//value gets injected from process definition
String transactionId;
String status;
String tcn;
public void notify(EventListenerExecution execution) {
log.info( transactionId+" -- " + status);
log.info(tcn);
}
}Code starting the business process:
for (i = 0 ; i < 2 ; i++) {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("param1", Integer.toString(i));
parameters.put("param2", Integer.toString(i));
parameters.put("id", Integer.toString(i));
executionService.startProcessInstanceByKey("TEST",parameters);
}The SOPL in the Event listener displays the value of first cycle event if the value of i = 2.
-
3. Re: Jbpm 4.3 Event Listeners
swiderski.maciej Feb 15, 2010 5:41 AM (in response to tony2010)Hi,
I think it can have something to do with caching mechanism. I have encountered similar issues when working with java activities.
It works fine for the first time since new instance of a class is created and members of that class are properly set. Afterwards this class is cached.
The idea behind is that such items (java activity) should be stateless and should not rely on class members. In case of java activity solution was to use arguments that will be passed to method. If it comes to event listeners you have access to process variables inside notify method (using execution object).
Could be good to get a confirmation of this from more experienced jBPM user. Any way I hope it will be useful.
Cheers,
Maciej
-
4. Re: Jbpm 4.3 Event Listeners
tony2010 Feb 15, 2010 6:05 AM (in response to swiderski.maciej)Thanks for the reply. It worked with execution.getVariable("var") inside the notify method.
Is there any way i can disable the caching of the objects.
-
5. Re: Jbpm 4.3 Event Listeners
swiderski.maciej Feb 15, 2010 6:41 AM (in response to tony2010)According to Dev guide you can use attribute
cache="disabled"
to prevent user code be cached.
Please check out following chapters in user and dev guide for details:
User guide - http://http://docs.jboss.com/jbpm/v4/userguide/html_single/#usercodeclassloading
Dev guide - http://docs.jboss.com/jbpm/v4/devguide/html_single/#d0e1360
/Maciej