jbpm与工作流模式 同步汇聚(Synchronizing Merge)

同步汇聚(Synchronizing Merge)


Description : A point in the workow process where multiple paths converge into one single
thread. If more than one path is taken, synchronization of the active threads needs to take place.
If only one path is taken, the alternative branches should reconverge without synchronization.
It is an assumption of this pattern that a branch that has already been activated, cannot be
activated again while the merge is still waiting for other branches to complete.
Synonyms Synchronizing join.


描述 :    流程中某点多条路径聚合成一个线程,若多于一条路径触发,则活动线程需同步;若仅
有一条路径触发,则可选分支应再收敛,无需同步.

同义词:    Synchronizing join.

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.*;  
  25.   
  26. import org.jbpm.graph.def.*;  
  27. import org.jbpm.graph.exe.*;  
  28.   
  29. public class Wfp07SynchronizingMergeTest extends TestCase {  
  30.   
  31.   private static ProcessDefinition synchronizingMergeProcessDefinition = createSynchronizingMergeProcessDefinition();  
  32.   
  33.   public static ProcessDefinition createSynchronizingMergeProcessDefinition() {  
  34.     ProcessDefinition pd = Wfp06MultiChoiceTest.createMultiChoiceProcessDefinition();  
  35.     return pd;  
  36.   }  
  37.   
  38.   public void testSynchronizingMergeScenario1() {  
  39.     ProcessDefinition pd = synchronizingMergeProcessDefinition;  
  40.   
  41.     Token root = Wfp06MultiChoiceTest.executeScenario(pd,1);  
  42.     Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions   
  43.   
  44.     tokenB.signal();  
  45.     assertSame( pd.getNode("end"), root.getNode() );  
  46.     assertSame( pd.getNode("syncmerge"), tokenB.getNode() );  
  47.   }  
  48.   
  49.   public void testSynchronizingMergeScenario2() {  
  50.     ProcessDefinition pd = synchronizingMergeProcessDefinition;  
  51.   
  52.     Token root = Wfp06MultiChoiceTest.executeScenario(pd,2);  
  53.     Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions  
  54.   
  55.     tokenC.signal();  
  56.     assertSame( pd.getNode("end"), root.getNode() );  
  57.     assertSame( pd.getNode("syncmerge"), tokenC.getNode() );  
  58.   }  
  59.   
  60.   public void testSynchronizingMergeScenario3() {  
  61.     ProcessDefinition pd = synchronizingMergeProcessDefinition;  
  62.   
  63.     Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);  
  64.     Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions   
  65.     Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions  
  66.   
  67.     tokenB.signal();  
  68.     assertSame( pd.getNode("multichoice"), root.getNode() );  
  69.     assertSame( pd.getNode("syncmerge"), tokenB.getNode() );  
  70.     assertSame( pd.getNode("c"), tokenC.getNode() );  
  71.   
  72.     tokenC.signal();  
  73.     assertSame( pd.getNode("end"), root.getNode() );  
  74.     assertSame( pd.getNode("syncmerge"), tokenB.getNode() );  
  75.     assertSame( pd.getNode("syncmerge"), tokenC.getNode() );  
  76.   }  
  77.   
  78.   public void testSynchronizingMergeScenario4() {  
  79.     ProcessDefinition pd = synchronizingMergeProcessDefinition;  
  80.   
  81.     Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);  
  82.     Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions   
  83.     Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions  
  84.   
  85.     tokenC.signal();  
  86.     assertSame( pd.getNode("multichoice"), root.getNode() );  
  87.     assertSame( pd.getNode("b"), tokenB.getNode() );  
  88.     assertSame( pd.getNode("syncmerge"), tokenC.getNode() );  
  89.   
  90.     tokenB.signal();  
  91.     assertSame( pd.getNode("end"), root.getNode() );  
  92.     assertSame( pd.getNode("syncmerge"), tokenB.getNode() );  
  93.     assertSame( pd.getNode("syncmerge"), tokenC.getNode() );  
  94.   }  
  95. }  


流程定义文件:

xml 代码
 
  1. <process-definition name="process">  
  2.     <start-state name='start'>  
  3.         <transition to='a' />  
  4.     </start-state>  
  5.     <state name='a'>  
  6.         <transition to='multichoice' />  
  7.     </state>  
  8.     <fork name='multichoice'>  
  9.         <transition name='to b' to='b'>  
  10.             <condition>#{scenario == 1} or #{scenario >= 3}</condition>  
  11.         </transition>  
  12.         <transition name='to c' to='c'>  
  13.             <condition>#{scenario == 2} or #{scenario >= 3}</condition>  
  14.         </transition>  
  15.     </fork>  
  16.     <state name='b'>  
  17.         <transition to='syncmerge' />  
  18.     </state>  
  19.     <state name='c'>  
  20.         <transition to='syncmerge' />  
  21.     </state>  
  22.     <join name='syncmerge'>  
  23.         <transition to='end' />  
  24.     </join>  
  25. </process-definition>  


testSynchronizingMergeScenario1()
   
当scenario == 1
节点流程如下:

    start --> a --> multichoice --> b --> syncmerge --> end

testSynchronizingMergeScenario2()
   
当scenario == 2
节点流程如下:

    start --> a --> multichoice --> c --> syncmerge --> end

testSynchronizingMergeScenario3()
   
当scenario == 3
节点流程如下:

    start --> a --> multichoice --> b --> syncmerge(先) --> end
                multichoice --> c --> syncmerge(后)

testSynchronizingMergeScenario4()
   
当scenario == 3
节点流程如下:

    start --> a --> multichoice --> b --> syncmerge(后) --> end
                      multichoice --> c --> syncmerge(先)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值