1 Reply Latest reply on Jan 19, 2006 8:18 AM by Ravi Prakash Reddy Ummadi

    Query regarding forking

    Ani Chou Newbie

      Hi,
      Created a workflow definition having fork node..
      Check the XML at the end of the message....

      After creating the processInstance, I am calling signal in while loop.

      while (!pi.hasEnded()) {
      root.signal();
      }

      Following are the problems..

      1. The ExitHandler for "stage2" and "stage3" doesn't get executed. Where as the EntryHandler get executed properly.

      2. The "Stage2" get executed twice. Not getting why the "Stage2" get executed twice. Do I have to call "Signal" for fork child token in "while" loop?

      Waiting for reply.

      thanks
      ani






      ===============================================================
      Here is the XML..

      
      
       "<process-definition name='workflow:DefaultWorkflowService_wkf_fork'>" +
      
       "<!-- START-STATE -->" +
       "<start-state name='start'>" +
       "<transition to='stage1'>" +
       "</transition>" +
      
       "<!-- NODES -->" +
       "<state name='stage1'>" +
       "<event type='node-enter'>" +
       "<action class='WorkflowEntryActionHandler'/>" +
       "</event>" +
       "<transition to='forkstage'/>" +
       "<event type='node-leave'>" +
       "<action class='WorkflowExitActionHandler'/>" +
       "</event>" +
       "</state>" +
      
      
       "<fork name='forkstage'>" +
       "<transition name ='first' to='stage2'/>" +
       "<transition name='second' to='stage3'/>" +
       "</fork>" +
      
      
       "<!-- NODES -->" +
       "<state name='stage2'>" +
       "<event type='node-enter'>" +
       "<action class='WorkflowEntryActionHandler'/>" +
       "</event>" +
      
       "<transition to='joinStage'/>" +
       "<event type='node-leave'>" +
       "<action class='WorkflowExitActionHandler'/>" +
       "</event>" +
       "</state>" +
      
      
       "<!-- NODES -->" +
       "<state name='stage3'>" +
       "<event type='node-enter'>" +
       "<action class='WorkflowEntryActionHandler'/>" +
       "</event>" +
       "<transition to='joinStage'/>" +
      
       "<event type='node-leave'>" +
       "<action class='WorkflowExitActionHandler'/>" +
       "</event>" +
       "</state>" +
      
      
       "<join name='joinStage'>" +
       "<action event-type='join-every-enter'>" +
       "<delegation class='JoinEnterAction'/>" +
       "</action>" +
       "<transition to='end'/>" +
       "</join>" +
      
       "<end-state name='end'>" +
       "</end-state>" +
      
       "</process-definition>"

      ===============================================================

        • 1. Re: Query regarding forking
          Ravi Prakash Reddy Ummadi Newbie

          Hi,

          You should be using token.getChildren() to access forked nodes.
          here is the working code for your sample.

          
          import java.util.Iterator;
          import java.util.Map;
          import org.jbpm.graph.def.ProcessDefinition;
          import org.jbpm.graph.exe.ProcessInstance;
          import org.jbpm.graph.exe.Token;
          
          public class ForkTest {
          
           public static void main(String args[]) {
           String procDef = "<process-definition name='workflow:DefaultWorkflowService_wkf_fork'>" +
           "<!-- START-STATE -->" +
           "<start-state name='start'>" +
           "<transition to='stage1'>" +
           "</transition>" +
           "</start-state>" +
          
           "<!-- NODES -->" +
          
           "<state name='stage1'>" +
           "<event type='node-enter'>" +
           "<script> System.out.println(\"this script is entering node \"+node);
           </script>"+
           "</event>" +
           "<transition to='forkstage'/>" +
           "<event type='node-leave'>" +
           "<script> System.out.println(\"this script is leaving node \"+node);
           </script>"+
           "</event>" +
           "</state>" +
          
           "<fork name='forkstage'>" +
           "<transition name ='first' to='stage2'/>" +
           "<transition name='second' to='stage3'/>" +
           "</fork>" +
          
           "<!-- NODES -->" +
           "<state name='stage2'>" +
           "<event type='node-enter'>" +
           "<script> System.out.println(\"this script is entering node \"+node);
           </script>"+
           "</event>" +
           "<transition to='joinStage'/>" +
           "<event type='node-leave'>" +
           "<script> System.out.println(\"this script is leaving node \"+node);
           </script>"+
           "</event>" +
           "</state>" +
          
           "<!-- NODES -->" +
           "<state name='stage3'>" +
           "<event type='node-enter'>" +
           "<script> System.out.println(\"this script is entering node \"+node);
           </script>"+
           "</event>" +
           "<transition to='joinStage'/>" +
           "<event type='node-leave'>" +
           "<script> System.out.println(\"this script is leaving node \"+node);
           </script>"+
           "</event>" +
           "</state>" +
          
           "<join name='joinStage'>" +
           "<event type='node-enter'>" +
           "<script> System.out.println(\"this script is entering node \"+node);
           </script>"+
           "</event>" +
           "<action event-type='join-every-enter'>" +
           "</action>" +
           "<event type='node-leave'>" +
           "<script> System.out.println(\"this script is leaving node \"+node);
           </script>"+
           "</event>" +
           "<transition to='end'/>" +
           "</join>" +
          
           "<end-state name='end'>" +
           "</end-state>" +
          
           "</process-definition>" ;
          
           ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(procDef);
           ProcessInstance processInstance = new ProcessInstance(processDefinition);
          
           Token token = processInstance.getRootToken();
           token.signal();
           token.signal();
           Map map = token.getChildren();
           Iterator itr = map.values().iterator();
           while(itr.hasNext()) {
           Token t = (Token)itr.next();
           System.out.println( "child token name " + t.getName() );
           t.signal();
           }
          
           }
          }
          



          -Ravi Prakash Reddy