原创作者: chenjin
阅读:4153次
评论:0条
更新时间:2011-05-26
xml 代码
- <process-definition>
- <start-state name='start'>
- <transition to='fork' />
- <!--</span-->start-state>
- <fork name='fork'>
- <transition name='first' to='one' />
- <transition name='second' to='two' />
- <!--</span-->fork>
- <state name='one'>
- <transition to='join' />
- <!--</span-->state>
- <state name='two'>
- <transition to='join' />
- <!--</span-->state>
- <join name='join'>
- <transition to='end' />
- <!--</span-->join>
- <end-state name='end' />
- <!--</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 代码
- <process-definition>
- <start-state name='start'>
- <transition to='fork' />
- <!--</span-->start-state>
- <fork name='fork'>
- <transition name='first' to='fork1' />
- <transition name='second' to='fork2' />
- <!--</span-->fork>
- <fork name='fork1'>
- <transition name='first' to='state1.1' />
- <transition name='second' to='state1.2' />
- <!--</span-->fork>
- <fork name='fork2'>
- <transition name='first' to='state2.1' />
- <transition name='second' to='state2.2' />
- <!--</span-->fork>
- <state name='state1.1'>
- <transition to='join1' />
- <!--</span-->state>
- <state name='state1.2'>
- <transition to='join1' />
- <!--</span-->state>
- <state name='state2.1'>
- <transition to='join2' />
- <!--</span-->state>
- <state name='state2.2'>
- <transition to='join2' />
- <!--</span-->state>
- <join name='join'>
- <transition to='end' />
- <!--</span-->join>
- <join name='join1'>
- <transition to='join' />
- <!--</span-->join>
- <join name='join2'>
- <transition to='join' />
- <!--</span-->join>
- <end-state name='end' />
- <!--</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 代码
- /*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
- package org.jbpm.jpdl.patterns;
- import junit.framework.TestCase;
- import org.jbpm.context.def.ContextDefinition;
- import org.jbpm.context.exe.ContextInstance;
- import org.jbpm.graph.def.ProcessDefinition;
- import org.jbpm.graph.exe.ProcessInstance;
- import org.jbpm.graph.exe.Token;
- /**
- * http://is.tm.tue.nl/research/patterns/download/swf/pat_4.swf
- *
- *
we make a distinction in the api between process and client based
- * decisions. the first tests show the situations as described in the
- * pattern. after that a demonstration of client based decision is
- * added.
- *
- *
- *
process based
- * decisions makes use of a decision node. the node has a piece of
- * programming logic associated that calculates the leaving transition
- * name. the programming logic is executed within the calculation of
- * the next state of the process instance.
- *
- *
- *
client based decisions allow clients to select on of the multiple
- * transitions that leave the current state.
- *
- */
- public class Wfp04ExclusiveChoiceTest extends TestCase {
- static ProcessDefinition exclusiveChoiceProcessDefinition = ProcessDefinition.parseXmlString(
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- " +
- " +
- " #{scenario==1}" +
- " " +
- " +
- " #{scenario==2}" +
- " " +
- " " +
- " +
- " +
- " +
- "" );
- static {
- exclusiveChoiceProcessDefinition.addDefinition( new ContextDefinition() );
- }
- /**
- * situation 1
- */
- public void testExclusiveChoiceSituation1() {
- ProcessDefinition pd = exclusiveChoiceProcessDefinition;
- ProcessInstance pi = new ProcessInstance( pd );
- ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
- pi.signal();
- Token root = pi.getRootToken();
- assertSame( pd.getNode("a"), root.getNode() );
- ci.setVariable( "scenario", new Integer(1) );
- root.signal();
- assertSame( pd.getNode("b"), root.getNode() );
- }
- /**
- * situation 2
- */
- public void testExclusiveChoiceSituation2() {
- ProcessDefinition pd = exclusiveChoiceProcessDefinition;
- ProcessInstance pi = new ProcessInstance( pd );
- ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
- pi.signal();
- Token root = pi.getRootToken();
- assertSame( pd.getNode("a"), root.getNode() );
- ci.setVariable( "scenario", new Integer(2) );
- root.signal();
- assertSame( pd.getNode("c"), root.getNode() );
- }
- }
流程定义文件:
xml 代码
- <process-definition>
- <start-state name='start'>
- <transition to='a' />
- <!--</span-->start-state>
- <state name='a'>
- <transition to='xor' />
- <!--</span-->state>
- <decision name='xor'>
- <transition name='forget about it' to='d' />
- <transition name='urgent' to='b'>
- <condition>#{scenario==1}<!--</span-->condition>
- <!--</span-->transition>
- <transition name='dont care' to='c'>
- <condition>#{scenario==2}<!--</span-->condition>
- <!--</span-->transition>
- <!--</span-->decision>
- <state name='b' />
- <state name='c' />
- <state name='d' />
- <!--</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 条 请登录后发表评论