2 Replies Latest reply on Jan 11, 2007 8:55 AM by asmo

    Transaction demarcation, callculation of the next process st

    asmo

      Hello all!

      I want to use asynchron process execution.
      Therefore, i have an action in a node, in which the thread waits 10 seconds to simulate a long calculation.

      Without the asynchron execution, i call the signal method on a state, the processinstance enters the node and after 10 seconds, the processinstance leaves the node and the processinstance is in the next state element.

      As far as i understand the tutorial, with asynchron execution, the processinstance should at once enter the state after the asynchron node, without waiting for the execution of the action.


      Note that the jbpm client code can now commit the transaction. The sending of the message should be done in the same transaction as the process updates. So the net result of the transaction is that the token has moved to the next node (which has not yet been executed) and a org.jbpm.command.ExecuteNodeCommand-message has been sent on the asynchronous messaging system to the jBPM Command Executor.


      But i have the situtation, that the client thread doesn't wait for the callculation but regardless the processinstance is in the tooken has not moved to the next state. the tooken still is in the asynchron node.

      here is the code i used ( which runs without problems, if i use synchron execution and also if i use asynchron execution, there are no errors. i just wonder, why the token does not move...) :
      
      //get the processinstance and so on....
      
       processInstance.signal("created");
      
       jbpmContext.save(processInstance);
       processInstance = null;
      
       newTransaction();
      
       processInstance = jbpmContext.loadProcessInstance(processId.longValue());
      
      
       //at this point i thougt, by asynchron execution the tooken has to
       //be in the state element after the asynchron node, but the
       //tooken is still in the node.
      
       logger.info("the processinstance is in : " + processInstance.getRootToken().getNode().getName());
      
      //doing stuff like close the context....
      
      
      
      protected void newTransaction() {
       try {
       commitAndCloseSession();
       beginSessionTransaction();
       } catch (Throwable t) {
       throw new RuntimeException("couldn't commit and start new transaction", t);
       }
       }
      public void commitAndCloseSession() {
       jbpmContext.close();
       resetMembers();
       }
      
      protected void initializeMembers() {
       session = jbpmContext.getSession();
       graphSession = jbpmContext.getGraphSession();
       taskMgmtSession = jbpmContext.getTaskMgmtSession();
       loggingSession = jbpmContext.getLoggingSession();
       schedulerSession = jbpmContext.getSchedulerSession();
       contextSession = jbpmContext.getContextSession();
       messagingSession = jbpmContext.getMessagingSession();
       }
      
      protected void resetMembers() {
       session = null;
       graphSession = null;
       taskMgmtSession = null;
       loggingSession = null;
       schedulerSession = null;
       contextSession = null;
       messagingSession = null;
       }
       public void beginSessionTransaction() {
       jbpmContext = MyJbpmConfigurationLoader.getConfiguration().createJbpmContext();
       initializeMembers();
       logger.info("--- starting new transaction -------------------------------------------------");
       }
      
      }
      


      Is there something wrong with my code or does the asynchron execution behave in that way like i thought? I am using the starterkit 3.1.1 and jpdl 3.1.

      Thanks,
      asmo

        • 1. Re: Transaction demarcation, callculation of the next proces
          koen.aers

          I don't see what the problem is exactly. Can you post the code of your action handler, your process definition and your application client?

          Regards,
          Koen

          • 2. Re: Transaction demarcation, callculation of the next proces
            asmo

            Thanks for the reply!

            Here is my processdefinition.

            <?xml version="1.0" encoding="UTF-8"?>
            
            <process-definition
             xmlns="urn:jbpm.org:jpdl-3.1"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://jbpm.org/3/jpdl http://jbpm.org/xsd/jpdl-3.1.xsd"
             name="test">
             <start-state name="start">
             <transition name="toFirstState" to="FirstState"></transition>
             </start-state>
             <state name="FirstState">
             <transition name="toNode" to="node1"></transition>
            
             </state>
             <end-state name="end1"></end-state>
             <node async="false" name="node1">
             <action name="test" class="de.uniSiegen.crm.server.workflow.action.TestActivity" />
            
             <transition name="toSecondState" to="SecondState"></transition>
             </node>
             <state name="SecondState">
             <transition name="toEnd" to="end1"></transition>
             </state>
            </process-definition>
            
            


            And this is my actionhandler, which just should simulate a long process calculation.

            public class TestActivity implements ActionHandler {
             Logger logger = ServiceLocator.getLogger(WorkflowBean.class);
             public void execute(ExecutionContext arg0) throws Exception {
             // TODO Auto-generated method stub
            
             Node node = arg0.getNode();
             node.leave(arg0);
            
             Object o = new Object();
             synchronized (o) {
             o.wait(10000);
            
             }
             logger.info("###########################################################################");
             logger.info("# TESTACTIVITY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#");
             logger.info("###########################################################################");
            
             }
            
            }



            If behavior of the process without async = "true" is :
            processinstance.signal("toNode");
            

            after calling the signal, the client waits 10 seconds until the node has executed the action...
            In the next step i ask the processinstance for the name of the actual node.
            System.out.println("Node of the process :" + processinstance.getRootToken().getNode().getName() );
            

            After waiting 10 seconds, the output ist : SecondState
            So, the process has needed 10 seconds for the execution and automatically enter the SecondState.
            That is exactly, what i have expected.

            If i change the processdefinition for asynchron execution ( async = "true" ) the behavior is this:

            processintance.signal("toNode");

            the token enters the node.


            System.out.println("Node of the process : " + processinstance.getRootToken().getNode().getName());

            at once, without waiting 10 seconds for the execution of the node, the name of the node is released.
            So, the client thread does not wait for the execution.
            But the output of the system.out is: node1
            After reading this part of the documentation:

            Note that the jbpm client code can now commit the transaction. The sending of the message should be done in the same transaction as the process updates. So the net result of the transaction is that the token has moved to the next node (which has not yet been executed) and a org.jbpm.command.ExecuteNodeCommand-message has been sent on the asynchronous messaging system to the jBPM Command Executor.

            i thought, that the processinstance should at once move to the SecondState, without waiting for the action of the node, and therefore i expected SecondState as output of the System.out.

            My question:
            Have i understood the documentation wrong and the output: node1
            is, right?
            Or is there an error in my code and the actual node of the processinstance should be SecondState?

            Thanks
            asmo