5 Replies Latest reply on May 19, 2011 10:56 AM by mputz

    Jump to end state from Node

    sasir

      We have the below work flow

       

      start state->node1->node2->node3->node4->end state

       

      We are trying to jump from node2 to end state directly but still node3 and node 4 are getting executed by executuioj context. We tried setNode and other stuff but its not  working as expected

       

      EndState endState = (EndState)executionContext.getNode().getProcessDefinition().getNode("end-state");

      executionContext.getToken().setNode(endState);

       

      Can you please advise on how this can be done?

        • 1. Re: Jump to end state from Node
          mputz

          Using token.setNode(..) should work, what exactly did not work 'as expected'?

           

           

          I would, however, not recommend to use it because of the following two caveats:

          • the process execution logging becomes inconsistent, which might be relevant if audit data of the executed process instances needs to be captured
          • it is not visually clear just from looking at the process that the process execution can 'jump' at certain points.

           

          A different approach for your requirement would be to introduce super-states. This concept is basically just a group over several nodes, but with the added benefit that you can add additional outgoing transitions from the super-state. These can be called from any node inside the super-state.

           

           

          1. FastForward w/o super-state:

           

          start -> node1 -> node2 -> node3 -> node4 -> end
          

           

          With this process definition, if you want to move from node1 directly to node4, you could only use Token.setNode() with the above mentioned caveats.

           

          2. FastForward w/ super-state:

           

                     ___super-state1___
                    |                  |
          start  -> | node1 -> node2 ->| node3
                    |__________________|   |
                             |             v  
                             `---------> node4 -> end
          
          

           

          Here, you can just call the leaving transition of the super-state to node4 from any of the nodes within the super-states. This has the advantage that the logs are created properly, thus it does not break auditing, and that additional events are triggered, which could be used to set/re-set any data or variables.

           

           

          HTH,

          Martin

          1 of 1 people found this helpful
          • 2. Re: Jump to end state from Node
            sasir

            Martin,

            Thanks a lot for replying in detail

             

            We have below process definition which has Node-Enter action as shown below. As soon as we start the process it will go to Node1 and from there we want to control the execution (Jump to End state by avoid execution of Node2/Node3. However in some scenarios we want to Jump to Node3)

             

            But following code is not working as expected and its always executing all the nodes.

             

            public class AutomationHandler implements ActionHandler {

            public void execute(ExecutionContext executionContext) throws Exception

                  {

                             

                          System.out.println(new Date()+"Inside AutomationHandler::execute()");

                         

                                System.out.println("########Going to End State###########");

                                      EndState endState = (EndState)executionContext.getNode().getProcessDefinition().getNode("end-state");

                                      Token token  = executionContext.getToken();

              token.setNode(endState);

             

                                      //token.signal("trans4");

                                      //token.end();

                                         

              System.out.println(new Date()+"Inside AutomationHandler::execute()");

             

            }

            }

             

             

            Process definition xml

            ********************************

            <?xml version="1.0" encoding="UTF-8"?>

            <process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="automationtest">

            <description>
              automationtest
            </description>


            <start-state name="start-state">
              <transition to="node1" name="trans1"></transition>
              <event type="process-start">
               <script name="Allocation Event Started">
                System.out.println(&quot;Event Creation Started &quot;+node);
               </script>
              </event>
            </start-state>


            <node name="node1">
              <event type="node-enter">
               <action class="com.citi.automation.build.jbpm.handler.AutomationHandler">
                <unixCommand>
                 echo &quot;Hello World&quot;
                </unixCommand>
                <expectedRetunCodes>
                 A,B,C
                </expectedRetunCodes>
                <successCondition>
                 ExecuteCommand2
                </successCondition>
                <errorCondition>
                 End
                </errorCondition>
               </action>
              </event>
              <transition to="node2" name="trans2"></transition>
              <transition to="end-state" name="trans4"></transition>
            </node>

            <node name="node2">
              <event type="node-enter">
               <action class="com.citi.automation.build.jbpm.handler.AutomationHandler">
                <unixCommand>
                 echo &quot;sleeping&quot;; sleep 60
                </unixCommand>
                <expectedRetunCodes>
                 A,D,E
                </expectedRetunCodes>
                <successCondition>
                 ExecuteCommand3
                </successCondition>
                <errorCondition>
                 End
                </errorCondition>
               </action>
              </event>
              <transition to="node3" name="trans3"></transition>
            </node>

            <node name="node3">
              <event type="node-enter">
               <action class="com.citi.automation.build.jbpm.handler.AutomationHandler">
                <unixCommand>
                 echo &quot;Working&quot;
                </unixCommand>
                <successCondition>
                 ExecuteCommand4
                </successCondition>
                <expectedRetunCodes>
                 A,B,C
                </expectedRetunCodes>
                <errorCondition>
                 End
                </errorCondition>
               </action>
              </event>
              <transition to="end-state" name="trans4"></transition>
            </node>


            <end-state name="end-state">
              <event type="process-end">
               <script name="Event End">
                System.out.println(&quot;Event End &quot;+node);
               </script>
              </event>
            </end-state>

            </process-definition>

            ********************************

            • 3. Jump to end state from Node
              sasir

              We figured out the issue. SetNode didnt work because we were using events on node action and it was  mentioned in the documentation that it wasnt supposed to be that way

               

              ANyway, Thanks Martin for your guidance

              • 4. Jump to end state from Node
                sasir

                SetNode does not work, it always starts node after the one you set. Below is the correct code

                 

                Transition leavingTransition = new Transition(DYNAMIC_TRANSITION);

                leavingTransition.setTo(executionContext.getProcessDefinition().getNode("Nodename"));

                leavingTransition.setFrom(executionContext.getNode());

                executionContext.leaveNode(leavingTransition);

                • 5. Jump to end state from Node
                  mputz

                  But following code is not working as expected and its always executing all the nodes.

                   

                  The code should work, but the problem is that the process definition is composed of <node> elements. As these are not wait states, the process execution just continues, regardless of the ActionHandler. Change all the <node> elements in your process to <state> elements, and you should get the desired result with the AutomationHandler.