1 Reply Latest reply on Aug 11, 2005 11:18 PM by michaelchanin

    Questions about fork

    michaelchanin

      I'm new to JBPM and I have a few questions about Fork behavior.

      Here's the bit of code I'm playing with. All of the asserts pass.

      public void testMyFirstForkProcessDefinition() {
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition>" +
       " <start-state name='start'>" +
       " <transition to='pre fork'/>" +
       " </start-state>" +
       " <state name='pre fork'>" +
       " <transition to='fork' />" +
       " </state>" +
       " <fork name='fork'>" +
       " <transition name='branch one' to='branch one'/>" +
       " <transition name='branch two' to='branch two'/>" +
       " <transition name='branch three' to='branch three'/>" +
       " </fork>" +
       " <state name='branch one'>" +
       " <transition name='to join' to='join' />" +
       " </state>" +
       " <state name='branch two'>" +
       " <transition name='to join' to='join' />" +
       " <transition name='to pre fork' to='pre fork' />" +
       " </state>" +
       " <state name='branch three'>" +
       " <transition name='to join' to='join' />" +
       " </state>" +
       " <join name='join'>" +
       " <transition to='end' /> " +
       " </join>" +
       " <end-state name='end' />" +
       " </process-definition>"
       );
      
       ProcessInstance processInstance =
       new ProcessInstance(processDefinition);
      
       Token token = processInstance.getRootToken();
       token.signal( );
      
       assertEquals( "process is at pre fork",
       token.getNode( ).getName( ),
       "pre fork" );
      
       token.signal( );
       assertEquals( "process is at fork",
       token.getNode( ).getName( ),
       "fork" );
      
       //...signal again
       token.signal( );
      
       //see where we are
       boolean inPreFork, inBranchOne, inBranchTwo, inBranchThree;
       inPreFork =inBranchOne = inBranchTwo = inBranchThree = false;
      
       for ( Iterator i = token.getChildren( ).keySet( ).iterator( );
       i.hasNext( ); )
       {
       String nodeName = (String) i.next( );
       Token forkToken = (Token) token.getChildren( ).get( nodeName );
      
       if ( processDefinition.getNode( "pre fork" )
       == forkToken.getNode( ) )
       inPreFork = true;
      
       if ( processDefinition.getNode( "branch one" )
       == forkToken.getNode( ) )
       inBranchOne = true;
      
       if ( processDefinition.getNode( "branch two" )
       == forkToken.getNode( ) )
       inBranchTwo = true;
      
       if ( processDefinition.getNode( "branch three" )
       == forkToken.getNode( ) )
       inBranchThree = true;
       }
      
       assertFalse( "Not in pre fork after Fork", inPreFork );
       assertTrue( "In branch one after Fork", inBranchOne );
       assertTrue( "In branch two after Fork", inBranchTwo );
       assertTrue( "In branch three after Fork", inBranchThree );
      
       //"reject" from branch two back to pre-fork
       Token branchTwoToken = token.getChild( "branch two" );
       Transition rejectToPreForkTransition
       = (Transition) branchTwoToken
       .getNode( )
       .getLeavingTransitionsMap( ).get( "to pre fork" );
      
       branchTwoToken.signal( rejectToPreForkTransition );
      
       assertEquals( "Branch two token points to the pre fork node",
       branchTwoToken.getNode( ).getName( ),
       "pre fork" );
      
       //see where we are now
       inPreFork =inBranchOne = inBranchTwo = inBranchThree = false;
       for ( Iterator i = token.getChildren( ).keySet( ).iterator( );
       i.hasNext( ); )
       {
       String nodeName = (String) i.next( );
       Token forkToken = (Token) token.getChildren( ).get( nodeName );
      
       if ( processDefinition.getNode( "pre fork" )
       == forkToken.getNode( ) )
       inPreFork = true;
      
       if ( processDefinition.getNode( "branch one" )
       == forkToken.getNode( ) )
       inBranchOne = true;
      
       if ( processDefinition.getNode( "branch two" )
       == forkToken.getNode( ) )
       inBranchTwo = true;
      
       if ( processDefinition.getNode( "branch three" )
       == forkToken.getNode( ) )
       inBranchThree = true;
       }
      
       assertTrue( "In pre fork after reject", inPreFork );
       assertTrue( "In branch one after reject", inBranchOne );
       assertFalse( "Not in branch two after reject", inBranchTwo );
       assertTrue( "In branch three after reject", inBranchThree );
      }
      


      I'm interested in different behavior --

      First, I'd lke the signal from the pre-fork state to immediately enter the three branch states, and not wait at the fork. Is there a way to get the fork to behave like a node, rather than a state?

      Second, is there a way to indicate that a transition out of one of the three branch states should invalidate the others? I'd like the signalling of the 'to pre fork' transition from the branch two state to result in the removal of the branch one and branch three tokens.



        • 1. Re: Questions about fork
          michaelchanin

          Ok, I see now that my first point was wrong. I was looking, initially, at just the root token and missed that the child tokens were created when I signalled the pre fork node.

          As for my second point, I think I'm just going to attach actions to the transitions that lead to the pre fork node from the branch nodes. Does anyone have a better idea?