原创作者: chenjin
阅读:9246次
评论:0条
更新时间:2011-05-26
工作流模式
本文以jdpl/jar/src/test/java jbpm3 关于workflow patterns 说明 jbpm 对 workflow patterns 的实现示例.
基本控制模式 (Basic Control Flow Patterns)
顺序 (sequence)
Description : An activity in a workow process is enabled after the completion of another
activity in the same process.
描述: : 同一个流程中, 一个活动在其他活动完成以后才能发生.
同义词 : Sequential routing, serial routing.
流程定义文件如下
本例中包括start , a , b ,c ,end 四个node. token.signal() 可以理解为流程中当前节点(token对应节点) 活动结束. 代码一目了然. 不需要过多解释.
并行分支(Parallet Split)
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.
描述 : 在分支点上,一个工作流程执行线程 分出多个执行线程同时并行执行, 多个分支线程可以同时以任意顺序执行.
同义词: AND-split, parallel routing, fork.
流程定义文件:
节点流程 start --> and --> a
-- > b
本例中and --a , and --> b 一定回被执行. 所以判断如下
Token firstToken = root.getChild( "first" );
assertNotNull( firstToken );
并行分支 (AND-Split ) 多以 同步聚合((Synchronization) 结束.
同步聚合(Synchronization)
Description : A point in the workow process where multiple parallel subprocesses/activities converge into one single thread of control, thus synchronizing multiple threads. It is an assumption of this pattern that each incoming branch of a synchronizer is executed only once
描述: 一个汇聚点, 多路工作流成执行线程汇聚成单个工作流执行线程. 只有汇聚线程都执行完毕,改汇聚点聚合后的单一线程才会执行.
同义词: AND-join, rendezvous, synchronizer.
本文以jdpl/jar/src/test/java jbpm3 关于workflow patterns 说明 jbpm 对 workflow patterns 的实现示例.
基本控制模式 (Basic Control Flow Patterns)
顺序 (sequence)
Description : An activity in a workow process is enabled after the completion of another
activity in the same process.
描述: : 同一个流程中, 一个活动在其他活动完成以后才能发生.
同义词 : Sequential routing, serial routing.
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.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_1.swf
- */
- public class Wfp01SequenceTest extends TestCase {
- public void testSequence() {
- // create a simple definition with 3 states in sequence
- ProcessDefinition pd = ProcessDefinition.parseXmlString(
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- ""
- );
- ProcessInstance pi = new ProcessInstance( pd );
- pi.signal();
- Token token = pi.getRootToken();
- assertSame( pd.getNode("a"), token.getNode() );
- token.signal();
- assertSame( pd.getNode("b"), token.getNode() );
- token.signal();
- assertSame( pd.getNode("c"), token.getNode() );
- token.signal();
- assertSame( pd.getNode("end"), token.getNode() );
- }
- }
流程定义文件如下
xml 代码
- <process-definition>
- <start-state name='start'>
- <transition to='a' />
- <!--</span-->start-state>
- <state name='a'>
- <transition to='b' />
- <!--</span-->state>
- <state name='b'>
- <transition to='c' />
- <!--</span-->state>
- <state name='c'>
- <transition to='end' />
- <!--</span-->state>
- <end-state name='end' />
- <!--</span-->process-definition>
本例中包括start , a , b ,c ,end 四个node. token.signal() 可以理解为流程中当前节点(token对应节点) 活动结束. 代码一目了然. 不需要过多解释.
并行分支(Parallet Split)
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.
描述 : 在分支点上,一个工作流程执行线程 分出多个执行线程同时并行执行, 多个分支线程可以同时以任意顺序执行.
同义词: AND-split, parallel routing, fork.
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.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_2.swf
- */
- public class Wfp02ParallelSplitTest extends TestCase {
- public void testParallelSplit() {
- ProcessDefinition pd = ProcessDefinition.parseXmlString(
- " " +
- " +
- " +
- " " +
- " +
- " +
- " +
- " " +
- " +
- " +
- ""
- );
- ProcessInstance pi = new ProcessInstance( pd );
- pi.signal();
- Token root = pi.getRootToken();
- assertNotNull( root );
- Token firstToken = root.getChild( "first" );
- assertNotNull( firstToken );
- assertSame( pd.getNode("a"), firstToken.getNode() );
- Token secondToken = root.getChild( "second" );
- assertNotNull( secondToken );
- assertSame( pd.getNode("b"), secondToken.getNode() );
- }
- }
流程定义文件:
xml 代码
- <process-definition>
- <start-state name='start'>
- <transition to='and' />
- <!--</span-->start-state>
- <fork name='and'>
- <transition name='first' to='a' />
- <transition name='second' to='b' />
- <!--</span-->fork>
- <state name='a' />
- <state name='b' />
- <!--</span-->process-definition>"
节点流程 start --> and --> a
-- > b
本例中and --a , and --> b 一定回被执行. 所以判断如下
Token firstToken = root.getChild( "first" );
assertNotNull( firstToken );
并行分支 (AND-Split ) 多以 同步聚合((Synchronization) 结束.
同步聚合(Synchronization)
Description : A point in the workow process where multiple parallel subprocesses/activities converge into one single thread of control, thus synchronizing multiple threads. It is an assumption of this pattern that each incoming branch of a synchronizer is executed only once
描述: 一个汇聚点, 多路工作流成执行线程汇聚成单个工作流执行线程. 只有汇聚线程都执行完毕,改汇聚点聚合后的单一线程才会执行.
同义词: AND-join, rendezvous, synchronizer.
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.*;
- import org.jbpm.graph.def.*;
- import org.jbpm.graph.exe.*;
- /**
- * http://is.tm.tue.nl/research/patterns/download/swf/pat_3.swf
- */
- public class Wfp03SynchronizationTest extends TestCase {
- public ProcessDefinition createSynchronizationProcessDefinition() {
- ProcessDefinition pd = ProcessDefinition.parseXmlString(
- " " +
- " +
- " +
- " " +
- " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- " +
- " " +
- " +
- ""
- );
- return pd;
- }
- public void testSynchronizationFirstTokenFirst() {
- ProcessDefinition pd = createSynchronizationProcessDefinition();
- ProcessInstance pi = new ProcessInstance( pd );
- pi.signal();
- Token root = pi.getRootToken();
- Token firstToken = root.getChild( "first" );
- Token secondToken = root.getChild( "second" );
- // check that the two tokens are in the states one and two respectively
- assertSame( pd.getNode("fork"), root.getNode() );
- assertSame( pd.getNode("one"), firstToken.getNode() );
- assertSame( pd.getNode("two"), secondToken.getNode() );
- firstToken.signal();
- assertSame( pd.getNode("fork"), root.getNode() );
- assertSame( pd.getNode("join"), firstToken.getNode() );
- assertSame( pd.getNode("two"), secondToken.getNode() );
- secondToken.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("join"), firstToken.getNode() );
- assertSame( pd.getNode("join"), secondToken.getNode() );
- }
- /**
- * variation of the pattern where the second token fires first.
- */
- public void testSynchronizationSecondTokenFirst() {
- ProcessDefinition pd = createSynchronizationProcessDefinition();
- ProcessInstance pi = new ProcessInstance( pd );
- pi.signal();
- Token root = pi.getRootToken();
- Token firstToken = root.getChild( "first" );
- Token secondToken = root.getChild( "second" );
- // check that the two tokens are in the states one and two respectively
- assertSame( pd.getNode("fork"), root.getNode() );
- assertSame( pd.getNode("one"), firstToken.getNode() );
- assertSame( pd.getNode("two"), secondToken.getNode() );
- secondToken.signal();
- assertSame( pd.getNode("fork"), root.getNode() );
- assertSame( pd.getNode("one"), firstToken.getNode() );
- assertSame( pd.getNode("join"), secondToken.getNode() );
- firstToken.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("join"), firstToken.getNode() );
- assertSame( pd.getNode("join"), secondToken.getNode() );
- }
- /**
- * nested form of the synchronization pattern.
- */
- public ProcessDefinition createNestedSynchronizationProcessDefinition() {
- // tip : draw this visually if you want to understand it.
- ProcessDefinition pd = new ProcessDefinition(
- new String[]{"start-state start",
- "fork fork",
- "fork fork1",
- "fork fork2",
- "state state1.1",
- "state state1.2",
- "state state2.1",
- "state state2.2",
- "join join2",
- "join join1",
- "join join",
- "end-state end"},
- new String[]{"start --> fork",
- "fork --first--> fork1",
- "fork --second--> fork2",
- "fork1 --first--> state1.1",
- "fork1 --second--> state1.2",
- "fork2 --first--> state2.1",
- "fork2 --second--> state2.2",
- "state1.1 --> join1",
- "state1.2 --> join1",
- "state2.1 --> join2",
- "state2.2 --> join2",
- "join1 --> join",
- "join2 --> join",
- "join --> end"});
- return pd;
- }
- public void testSynchronizationNested() {
- ProcessDefinition pd = createNestedSynchronizationProcessDefinition();
- ProcessInstance pi = new ProcessInstance( pd );
- pi.signal();
- Token rootToken = pi.getRootToken();
- Token token1 = rootToken.getChild( "first" );
- Token token2 = rootToken.getChild( "second" );
- Token token11 = token1.getChild( "first" );
- Token token12 = token1.getChild( "second" );
- Token token21 = token2.getChild( "first" );
- Token token22 = token2.getChild( "second" );
- assertSame( pd.getNode("fork"), rootToken.getNode() );
- assertSame( pd.getNode("fork1"), token1.getNode() );
- assertSame( pd.getNode("fork2"), token2.getNode() );
- assertSame( pd.getNode("state1.1"), token11.getNode() );
- assertSame( pd.getNode("state1.2"), token12.getNode() );
- assertSame( pd.getNode("state2.1"), token21.getNode() );
- assertSame( pd.getNode("state2.2"), token22.getNode() );
- token11.signal();
- assertSame( pd.getNode("fork"), rootToken.getNode() );
- assertSame( pd.getNode("fork1"), token1.getNode() );
- assertSame( pd.getNode("fork2"), token2.getNode() );
- assertSame( pd.getNode("join1"), token11.getNode() );
- assertSame( pd.getNode("state1.2"), token12.getNode() );
- assertSame( pd.getNode("state2.1"), token21.getNode() );
- assertSame( pd.getNode("state2.2"), token22.getNode() );
- token12.signal();
- assertSame( pd.getNode("fork"), rootToken.getNode() );
- assertSame( pd.getNode("join"), token1.getNode() );
- assertSame( pd.getNode("fork2"), token2.getNode() );
- assertSame( pd.getNode("join1"), token11.getNode() );
- assertSame( pd.getNode("join1"), token12.getNode() );
- assertSame( pd.getNode("state2.1"), token21.getNode() );
- assertSame( pd.getNode("state2.2"), token22.getNode() );
- token21.signal();
- assertSame( pd.getNode("fork"), rootToken.getNode() );
- assertSame( pd.getNode("join"), token1.getNode() );
- assertSame( pd.getNode("fork2"), token2.getNode() );
- assertSame( pd.getNode("join1"), token11.getNode() );
- assertSame( pd.getNode("join1"), token12.getNode() );
- assertSame( pd.getNode("join2"), token21.getNode() );
- assertSame( pd.getNode("state2.2"), token22.getNode() );
- token22.signal();
- assertSame( pd.getNode("end"), rootToken.getNode() );
- assertSame( pd.getNode("join"), token1.getNode() );
- assertSame( pd.getNode("join"), token2.getNode() );
- assertSame( pd.getNode("join1"), token11.getNode() );
- assertSame( pd.getNode("join1"), token12.getNode() );
- assertSame( pd.getNode("join2"), token21.getNode() );
- assertSame( pd.getNode("join2"), token22.getNode() );
- }
- }
评论 共 0 条 请登录后发表评论