[jboss-user] [JBoss jBPM] - EventListener does not get executed?

showmanlkz do-not-reply at jboss.com
Tue Jul 21 08:37:54 EDT 2009


I am using jBPM 4.0, jdk1.5.0_19, and try to run a simple process contains a event listener inside a state node.

When I run the test case, it seems that the process executes that state node (GetFromStock) and move to the next, but the attached Event listener does not run (i.e. the variable does not get updated).

process file
<?xml version="1.0" encoding="UTF-8"?>
  | 
  | <process name="order" xmlns="http://jbpm.org/4.0/jpdl">
  |    <swimlane assignee="alex" name="buyer"/>
  |    <swimlane assignee="peter" name="deliverDepartment"/>
  |    <start g="236,49,48,48" name="start">
  |       <transition g="-88,-22" name=" Start to PlaceOrder" to="PlaceOrder"/>
  |    </start>
  |    <task g="218,155,92,52" name="PlaceOrder" swimlane="buyer">
  |       <transition g="-121,-22" name="Order to Check" to="CheckAvailability"/>
  |    </task>
  |    <decision g="245,273,48,48" name="CheckAvailability">
  |       <handler class="org.jbpm.order.VerifyOrder" />
  |       <transition g="447,297:-110,-22" name="Check to Stock" to="GetFromStock"/>
  |       <transition g="-63,-22" name="Check to Deliver" to="Deliver"/>
  |    </decision>
  |    <state g="394,377,110,52" name="GetFromStock">
  |       <on event="FillStock">
  |          <event-listener class="org.jbpm.order.GetFromStockListener"/>
  |       </on>
  |       <transition g="-121,-22" name="Stock to Check" to="CheckAvailability"/>
  |    </state>
  |    <task g="83,382,92,52" name="Deliver" swimlane="deliverDepartment">
  |       <transition g="-45,-22" name="to end" to="end"/>
  |    </task>
  |    <end g="106,538,48,48" name="end"/>
  | </process>

Event Listener
/**
  |  * 
  |  */
  | package org.jbpm.order;
  | 
  | import org.jbpm.api.listener.EventListener;
  | import org.jbpm.api.listener.EventListenerExecution;
  | 
  | public class GetFromStockListener implements EventListener {
  | 
  | 	public void notify(EventListenerExecution execution) throws Exception {
  | 		
  | 		Integer newStock = 300;
  | 		
  | 		execution.setVariable("goodsInStock", newStock);
  | 		
  | 		System.out.println("New stock: " + newStock);
  | 	}
  | }
  | 

Test case
	public void testOrder() throws Exception {
  | 		
  | 		HashMap<String, Object> vars = new HashMap<String, Object>();
  | 		vars.put("goodsOrdered", new Integer(100));
  | 		vars.put("goodsInStock", new Integer(50));
  | 		
  | 		ProcessInstance pi = executionService
  | 				.startProcessInstanceByKey("order", vars);
  | 		String pid = pi.getId();
  | 
  | 		assertTrue(pi.isActive("PlaceOrder"));
  | 
  | 		List tasks = taskService.findPersonalTasks("alex");
  | 		Task task = (Task) tasks.get(0);
  | 		taskService.completeTask(task.getId());
  | 
  | 		pi = executionService.findProcessInstanceById(pid);
  | 		assertTrue(pi.isActive("GetFromStock"));
  | 		
  | 		String exeId = pi.findActiveExecutionIn("GetFromStock").getId();
  | 		assertNotNull(exeId);
  | 		// 
  |                 executionService.signalExecutionById(exeId, "Stock to Check");
  | 		assertEquals(300, executionService.getVariable(exeId, "goodsInStock"));
  | 	}

Thanks in advanced

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244963#4244963

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244963



More information about the jboss-user mailing list