原创作者: chenjin   阅读:4122次   评论:0条   更新时间:2011-05-26    
xml 代码
 
  1. <process-definition>  
  2.     <start-state name='start'>  
  3.         <transition to='fork' />  
  4.     <!--</span-->start-state>  
  5.     <fork name='fork'>  
  6.         <transition name='first' to='one' />  
  7.         <transition name='second' to='two' />  
  8.     <!--</span-->fork>  
  9.     <state name='one'>  
  10.         <transition to='join' />  
  11.     <!--</span-->state>  
  12.     <state name='two'>  
  13.         <transition to='join' />  
  14.     <!--</span-->state>  
  15.     <join name='join'>  
  16.         <transition to='end' />  
  17.     <!--</span-->join>  
  18.     <end-state name='end' />  
  19. <!--</span-->process-definition>  


其中testSynchronizationFirstTokenFirst()

节点执行顺序为

    start --> fork --> one --> join(先) --> end
                          --> two --> join(后)

    其中  firstToken.signal() 后 one --> join 先执行.
    在   two --> join 执行技术之前  join --> end 不会执行

testSynchronizationSecondTokenFirst() 与上面方法类似, 只是one 和 two 互换.

testSynchronizationNested()

中createNestedSynchronizationProcessDefinition()
创建如下流程

xml 代码
 
  1. <process-definition>  
  2.     <start-state name='start'>  
  3.         <transition to='fork' />  
  4.     <!--</span-->start-state>  
  5.     <fork name='fork'>  
  6.         <transition name='first' to='fork1' />  
  7.         <transition name='second' to='fork2' />  
  8.     <!--</span-->fork>  
  9.     <fork name='fork1'>  
  10.         <transition name='first' to='state1.1' />  
  11.         <transition name='second' to='state1.2' />  
  12.     <!--</span-->fork>  
  13.     <fork name='fork2'>  
  14.         <transition name='first' to='state2.1' />  
  15.         <transition name='second' to='state2.2' />  
  16.     <!--</span-->fork>  
  17.     <state name='state1.1'>  
  18.         <transition to='join1' />  
  19.     <!--</span-->state>  
  20.     <state name='state1.2'>  
  21.         <transition to='join1' />  
  22.     <!--</span-->state>  
  23.     <state name='state2.1'>  
  24.         <transition to='join2' />  
  25.     <!--</span-->state>  
  26.     <state name='state2.2'>  
  27.         <transition to='join2' />  
  28.     <!--</span-->state>  
  29.     <join name='join'>  
  30.         <transition to='end' />  
  31.     <!--</span-->join>  
  32.     <join name='join1'>  
  33.         <transition to='join' />  
  34.     <!--</span-->join>  
  35.     <join name='join2'>  
  36.         <transition to='join' />  
  37.     <!--</span-->join>  
  38.     <end-state name='end' />  
  39. <!--</span-->process-definition>  



节点执行顺序:


    start --> fork --> fork1 --> state1.1 --> join1 --> join --> end
                                          --> state1.2 --> join1
                          --> fork2 --> state2.1 --> join2 --> join
                                          --> state2.2 --> join2

    token11.signal()   token11 到 join1
 
    token12.signal()   token12 到 join1 , token1到join

    token21.signal()   token21 到 join2

     token22.signal()  token22 到 join2 , token2到join


排它选择(Exclusive Choice)


Description:     A point in the workow process where a single thread of control splits into
multiple threads of control which can be executed in parallel, thus allowing activities to be
executed simultaneously or in any order.

描述:    在流程的某一点,依据工作流控制数据, 从多个分支路径中选定一个路径

同义词: XOR-split, conditional routing, switch, decision.


java 代码
 
  1. /* 
  2.  * JBoss, Home of Professional Open Source 
  3.  * Copyright 2005, JBoss Inc., and individual contributors as indicated 
  4.  * by the @authors tag. See the copyright.txt in the distribution for a 
  5.  * full listing of individual contributors. 
  6.  * 
  7.  * This is free software; you can redistribute it and/or modify it 
  8.  * under the terms of the GNU Lesser General Public License as 
  9.  * published by the Free Software Foundation; either version 2.1 of 
  10.  * the License, or (at your option) any later version. 
  11.  * 
  12.  * This software is distributed in the hope that it will be useful, 
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
  15.  * Lesser General Public License for more details. 
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public 
  18.  * License along with this software; if not, write to the Free 
  19.  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 
  20.  * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 
  21.  */  
  22. package org.jbpm.jpdl.patterns;  
  23.   
  24. import junit.framework.TestCase;  
  25.   
  26. import org.jbpm.context.def.ContextDefinition;  
  27. import org.jbpm.context.exe.ContextInstance;  
  28. import org.jbpm.graph.def.ProcessDefinition;  
  29. import org.jbpm.graph.exe.ProcessInstance;  
  30. import org.jbpm.graph.exe.Token;  
  31.   
  32. /** 
  33.  * http://is.tm.tue.nl/research/patterns/download/swf/pat_4.swf 
  34.  *  
  35.  * 

    we make a distinction in the api between process and client based 

     
  36.  * decisions. the first tests show the situations as described in the  
  37.  * pattern. after that a demonstration of client based decision is  
  38.  * added. 
  39.  * 

     

         
     
  40.  *  
  41.  * 

    process based 

     
  42.  * decisions makes use of a decision node.  the node has a piece of  
  43.  * programming logic associated that calculates the leaving transition 
  44.  * name.  the programming logic is executed within the calculation of  
  45.  * the next state of the process instance. 
  46.  * 

     

     
  47.  *  
  48.  * 

    client based decisions allow clients to select on of the multiple 

     
  49.  * transitions that leave the current state. 
  50.  * 

     

      
     
  51.  */  
  52. public class Wfp04ExclusiveChoiceTest extends TestCase {  
  53.     
  54.   static ProcessDefinition exclusiveChoiceProcessDefinition = ProcessDefinition.parseXmlString(  
  55.       " "  +  
  56.       "   +  
  57.       "     +  
  58.       "  " +  
  59.       "   +  
  60.       "     +  
  61.       "  " +  
  62.       "   +  
  63.       "     +  
  64.       "     +  
  65.       "      #{scenario==1}" +  
  66.       "    " +  
  67.       "     +  
  68.       "      #{scenario==2}" +  
  69.       "    " +  
  70.       "  " +  
  71.       "   +  
  72.       "   +  
  73.       "   +  
  74.       "" );  
  75.   static {  
  76.     exclusiveChoiceProcessDefinition.addDefinition( new ContextDefinition() );  
  77.   }  
  78.   
  79.   /** 
  80.    * situation 1 
  81.    */  
  82.   public void testExclusiveChoiceSituation1() {  
  83.     ProcessDefinition pd = exclusiveChoiceProcessDefinition;  
  84.   
  85.     ProcessInstance pi = new ProcessInstance( pd );  
  86.     ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );  
  87.     pi.signal();  
  88.     Token root = pi.getRootToken();  
  89.   
  90.     assertSame( pd.getNode("a"), root.getNode() );  
  91.       
  92.     ci.setVariable( "scenario"new Integer(1) );  
  93.     root.signal();  
  94.       
  95.     assertSame( pd.getNode("b"), root.getNode() );  
  96.   }  
  97.   
  98.   /** 
  99.    * situation 2 
  100.    */  
  101.   public void testExclusiveChoiceSituation2() {  
  102.     ProcessDefinition pd = exclusiveChoiceProcessDefinition;  
  103.   
  104.     ProcessInstance pi = new ProcessInstance( pd );  
  105.     ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );  
  106.     pi.signal();  
  107.     Token root = pi.getRootToken();  
  108.   
  109.     assertSame( pd.getNode("a"), root.getNode() );  
  110.       
  111.     ci.setVariable( "scenario"new Integer(2) );  
  112.     root.signal();  
  113.       
  114.     assertSame( pd.getNode("c"), root.getNode() );  
  115.   }  
  116.   
  117. }  


流程定义文件:

   
xml 代码
 
  1. <process-definition>  
  2.     <start-state name='start'>  
  3.         <transition to='a' />  
  4.     <!--</span-->start-state>  
  5.     <state name='a'>  
  6.         <transition to='xor' />  
  7.     <!--</span-->state>  
  8.     <decision name='xor'>  
  9.         <transition name='forget about it' to='d' />  
  10.         <transition name='urgent' to='b'>  
  11.             <condition>#{scenario==1}<!--</span-->condition>  
  12.         <!--</span-->transition>  
  13.         <transition name='dont care' to='c'>  
  14.             <condition>#{scenario==2}<!--</span-->condition>  
  15.         <!--</span-->transition>  
  16.     <!--</span-->decision>  
  17.     <state name='b' />  
  18.     <state name='c' />  
  19.     <state name='d' />  
  20. <!--</span-->process-definition>  




节点执行顺序:

     start --> a --> xor --> d
                             xor --> b
                             xor --> c
  其中 xor --> d , xor --> b , xor--> c 只能从中选一.
  当scenario==1 执行 xor --> b,  当 scenario==2 执行xor --> c , 其他情况(默认)执行xor --> d

    代码中根据变量scenario , 判断流程转向, 比较直观,不再详述.




简单聚合(Simple Merge)


Description :  A point in the workow process where two or more alternative branches come together
without synchronization. It is an assumption of this pattern that none of the alternative
branches is ever executed in parallel

描述: 在流程中某一点,将两个或更多可选分支聚合而不同步.

同义词: XOR-join, asynchronous join, merge.
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics