[jboss-user] [JBoss jBPM] - Re: Token.signal() ---> 2 tokens?

pojomonkey do-not-reply at jboss.com
Thu Feb 21 11:16:32 EST 2008


"mputz" wrote : IMO, you shouldn't signal the root token once it has arrived in the fork:
  | 
  | 
  |   | 	    Token root = processInstance.getRootToken();
  |   | 	    // root token is already on the fork, signal children instead
  |   | 	    // root.signal();
  |   | 
OK, but how should the root token progress to the matching join? And what about the example I've given where on of the execuation paths forks again?

What is the logic to determine when I can signal which tokens? In my test - see below - from fork1, I would expect to be signalling token t20 - but when that arrives at fork2, should I cease signalling t20? Then how is it to join finally?

"mputz" wrote : I've found a (rejected) feature request to prevent the root token from being signaled on a fork node: http://jira.jboss.com/jira/browse/JBPM-642
I'll be reading that shortly...

It may explain why I can get the root token to the last state in the process when it's children haven't all joined yet. Seems to me that the join is operating like a discriminator..

  | package forktest;
  | 
  | import java.util.Map;
  | 
  | import junit.framework.TestCase;
  | 
  | import org.jbpm.JbpmConfiguration;
  | import org.jbpm.JbpmContext;
  | import org.jbpm.context.exe.ContextInstance;
  | import org.jbpm.graph.def.Node;
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ProcessInstance;
  | import org.jbpm.graph.exe.Token;
  | import org.jbpm.persistence.db.DbPersistenceServiceFactory;
  | import org.jbpm.svc.Services;
  | import org.jbpm.taskmgmt.exe.TaskInstance;
  | 
  | public class ForkUnitTest extends TestCase
  | {
  | 	/**
  | 	 * Some helpers
  | 	 */
  | 	JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  | 	DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
  | 
  | 	JbpmContext jbpmContext;
  | 
  | 	private ProcessInstance	processInstance;
  | 	
  | 	private long	processInstanceId;
  | 	private ContextInstance	contextInstance;
  | //	private TaskMgmtInstance	taskMgmtInstance;
  | 	
  | 	public ForkUnitTest()
  | 	{
  | 	}
  | 
  | 	/**
  | 	 * Set up the basic in-memory DB, deploy the process description and
  | 	 * set up a jBPM context.
  | 	 * @see jBPM docs wrt jbpm configuration file
  | 	 */
  | 	protected void setUp() throws Exception
  | 	{
  | 		super.setUp();
  | 		dbPersistenceServiceFactory.createSchema();
  | 		deployProcess();
  | 		jbpmConfiguration.startJobExecutor();
  | 		jbpmContext = jbpmConfiguration.createJbpmContext();
  | 	}
  | 
  | 	/**
  | 	 * Tidy up.
  | 	 */
  | 	protected void tearDown() throws Exception
  | 	{
  | 		super.tearDown();
  | 		jbpmContext.close();
  | 		dbPersistenceServiceFactory.dropSchema();
  | 		jbpmContext = null;
  | 	}
  | 
  | 	/**
  | 	 * 
  | 	 */
  | 	public void newTransaction() 
  | 	{
  | 		jbpmContext.close();
  | 		jbpmContext = jbpmConfiguration.createJbpmContext();
  | 		processInstance = jbpmContext.loadProcessInstanceForUpdate(processInstanceId);
  | //		processInstanceId = processInstance.getId();
  | 	}
  | 
  | 	/**
  | 	 * Get the process description file, parse it and deploy the
  | 	 * process definition.
  | 	 */
  | 	private void deployProcess() 
  | 	{
  | 		JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  | 		try 
  | 		{
  | 			ProcessDefinition processDefinition = 
  | 				ProcessDefinition.parseXmlResource("ForkProcess/processdefinition.xml");
  | 			jbpmContext.deployProcessDefinition(processDefinition);
  | 		} finally 
  | 		{
  | 			jbpmContext.close();
  | 		}
  | 	}
  | 
  | 	/**
  | 	 * Each subsequent test will need a new process instance
  | 	 * @return a TaskInstance, or null if there is no start task defined.
  | 	 */
  | 	private TaskInstance createNewProcessInstance() 
  | 	{
  | 		processInstance = jbpmContext.newProcessInstanceForUpdate("ForkTest");
  | 		processInstanceId = processInstance.getId();
  | 		contextInstance = processInstance.getContextInstance();
  | //		taskMgmtInstance = processInstance.getTaskMgmtInstance();
  | 		return processInstance.getTaskMgmtInstance().createStartTaskInstance();
  | 	}
  | 
  | 	public void testFork()
  | 	{
  | 		TaskInstance taskInstance = createNewProcessInstance();
  | 		contextInstance.setVariable("choice", "OptionB");
  | 		assertEquals("startstate", processInstance.getRootToken().getNode().getName());
  | 		processInstance.signal();
  | 		jbpmContext.save(processInstance);
  | 		
  | 	    newTransaction();
  | 	    
  | 		assertEquals("optionb", processInstance.getRootToken().getNode().getName());
  | 		processInstance.signal("ok");
  | 	    jbpmContext.save(processInstance);
  | 	    
  | 	    newTransaction();
  | 	    
  | 		assertEquals("nextstate", processInstance.getRootToken().getNode().getName());
  | 		processInstance.signal("ok");
  | 		jbpmContext.save(processInstance);
  | 		
  | 	    newTransaction();
  | 	    
  | 	    Token root = processInstance.getRootToken();
  | 	    root.signal();
  | 		
  | 		jbpmContext.save(processInstance);
  | 		
  | 	    newTransaction();
  | 
  | 	    root = processInstance.getRootToken();
  | 	    Map map = root.getChildren();
  | 	    assertEquals(2, map.size());
  | 	    
  | 	    Token tk_t10 = (Token) map.get("t10");
  | 		assertEquals("t10", tk_t10.getName());
  | 	    
  | 		ProcessInstance pi = tk_t10.getProcessInstance();
  | 		assertEquals(processInstanceId, pi.getId());
  | 		Node node = tk_t10.getNode();
  | 		assertEquals("track", node.getName());
  | //		tk_t10.signal("ok");
  | 		jbpmContext.save(processInstance);
  | 		
  | 	    newTransaction();
  | 	    
  | 	    root = processInstance.getRootToken();
  | 	    map = root.getChildren();
  | 	    assertEquals(2, map.size());
  | 	    
  | 	    tk_t10 = (Token) map.get("t10");
  | 		assertEquals("t10", tk_t10.getName());
  | 		
  | 	    Token tk_t20 = (Token) map.get("t20");
  | 	    assertEquals("t20", tk_t20.getName());
  | 		
  | 		pi = tk_t20.getProcessInstance();
  | 		assertEquals(processInstanceId, pi.getId());
  | 		node = tk_t20.getNode();
  | 		assertEquals("proceed", node.getName());
  | 		tk_t20.signal();
  | 		node = tk_t20.getNode();
  | 		assertEquals("fork2", node.getName());
  | 		
  | 	    map = tk_t20.getChildren();
  | 	    assertEquals(2, map.size());
  | 
  | 		assertEquals("track", processInstance.getRootToken().getNode().getName());
  | 
  | 		node = tk_t10.getNode();
  | 		assertEquals("track", node.getName());
  | 		tk_t10.signal("ok");
  | 		node = tk_t10.getNode();
  | 		assertEquals("join2", node.getName());
  | 		jbpmContext.save(processInstance);
  | 		
  | 	    newTransaction();
  | 
  | 	    root = processInstance.getRootToken();
  | 		root.signal();
  | 		assertEquals("join2", processInstance.getRootToken().getNode().getName());
  | 		
  | 		root.signal();
  | 		// FAILS on the next assert as root token is now on state 'complete'
  | 		// but shouldn't be as token t20 is still at fork2!!!
  | 		assertEquals("join2", processInstance.getRootToken().getNode().getName());
  | 	}
  | 
  | }
  | 

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

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



More information about the jboss-user mailing list