鉴别器(Discriminator)
Description : The discriminator is a point in a workow process that waits for one of the
incoming branches to complete before activating the subsequent activity. From that moment on
it waits for all remaining branches to complete and \ignores" them. Once all incoming branches
have been triggered, it resets itself so that it can be triggered again (which is important
otherwise it could not really be used in the context of a loop).
描述:多分支汇聚的时候,只有一个分支可以激活所属任务,这个任务激活以后,其他分支的
到来都会被忽略。
java 代码
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- package org.jbpm.jpdl.patterns;
-
- import junit.framework.TestCase;
-
- import org.jbpm.graph.def.ProcessDefinition;
- import org.jbpm.graph.exe.Token;
- import org.jbpm.graph.node.Join;
-
-
-
-
- public class Wfp09DiscriminatorTest extends TestCase {
-
- private static ProcessDefinition discriminatorProcessDefinition = createDiscriminatorProcessDefinition();
-
- public static ProcessDefinition createDiscriminatorProcessDefinition() {
- ProcessDefinition pd = createSynchronizingDiscriminatorProcessDefinition();
-
-
- Join join = (Join) pd.getNode("discriminator");
- join.setDiscriminator(true);
-
- return pd;
- }
-
- private static ProcessDefinition synchronizingdiscriminatorProcessDefinition = createSynchronizingDiscriminatorProcessDefinition();
-
- public static ProcessDefinition createSynchronizingDiscriminatorProcessDefinition() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='start'>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <state name='a'>" +
- " <transition to='multichoice' />" +
- " </state>" +
- " <fork name='multichoice'>" +
- " <script>" +
- " <variable name='transitionNames' access='write' />" +
- " <expression>" +
- " transitionNames = new ArrayList();" +
- " if ( scenario == 1 ) {" +
- " transitionNames.add( \"to b\" );" +
- " } else if ( scenario == 2 ) {" +
- " transitionNames.add( \"to c\" );" +
- " } else if ( scenario >= 3 ) {" +
- " transitionNames.add( \"to b\" );" +
- " transitionNames.add( \"to c\" );" +
- " }" +
- " </expression>" +
- " </script>" +
- " <transition name='to b' to='b' />" +
- " <transition name='to c' to='c' />" +
- " </fork>" +
- " <state name='b'>" +
- " <transition to='discriminator' />" +
- " </state>" +
- " <state name='c'>" +
- " <transition to='discriminator' />" +
- " </state>" +
- " <join name='discriminator'>" +
- " <transition to='d' />" +
- " </join>" +
- " <state name='d' />" +
- "</process-definition>"
- );
-
- return processDefinition;
- }
-
- public void testDiscriminatorScenario1() {
- ProcessDefinition pd = discriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,1);
- Token tokenB = root.getChild("to b");
-
- tokenB.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- }
-
- public void testDiscriminatorScenario2() {
- ProcessDefinition pd = discriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,2);
- Token tokenC = root.getChild("to c");
-
- tokenC.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
- }
-
- public void testDiscriminatorScenario3() {
- ProcessDefinition pd = discriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
- Token tokenB = root.getChild("to b");
- Token tokenC = root.getChild("to c");
-
- tokenB.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("c"), tokenC.getNode() );
-
- tokenC.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
- }
-
- public void testDiscriminatorScenario4() {
- ProcessDefinition pd = discriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,4);
- Token tokenB = root.getChild("to b");
- Token tokenC = root.getChild("to c");
-
- tokenC.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("b"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
-
- tokenB.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
- }
-
- public void testDiscriminatorScenario5() {
- ProcessDefinition pd = synchronizingdiscriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,5);
- Token tokenB = root.getChild("to b");
- Token tokenC = root.getChild("to c");
-
- tokenB.signal();
- assertSame( pd.getNode("multichoice"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("c"), tokenC.getNode() );
-
- tokenC.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
- }
-
- public void testDiscriminatorScenario6() {
- ProcessDefinition pd = synchronizingdiscriminatorProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
- Token tokenB = root.getChild("to b");
- Token tokenC = root.getChild("to c");
-
- tokenC.signal();
- assertSame( pd.getNode("multichoice"), root.getNode() );
- assertSame( pd.getNode("b"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
-
- tokenB.signal();
- assertSame( pd.getNode("d"), root.getNode() );
- assertSame( pd.getNode("discriminator"), tokenB.getNode() );
- assertSame( pd.getNode("discriminator"), tokenC.getNode() );
- }
- }
流程定义文件
xml 代码
- <process-definition>
- <start-state name='start'>
- <transition to='a' />
- </start-state>
- <state name='a'>
- <transition to='multichoice' />
- </state>
- <fork name='multichoice'>
- <script>
- <variable name='transitionNames' access='write' />
- <expression>
- transitionNames = new ArrayList();
- if ( scenario == 1 ) {
- transitionNames.add( \"to b\" );
- } else if ( scenario == 2 ) {
- transitionNames.add( \"to c\" );
- } else if ( scenario >= 3 ) {
- transitionNames.add( \"to b\" );
- transitionNames.add( \"to c\" );
- }
- </expression>
- </script>
- <transition name='to b' to='b' />
- <transition name='to c' to='c' />
- </fork>
- <state name='b'>
- <transition to='discriminator' />
- </state>
- <state name='c'>
- <transition to='discriminator' />
- </state>
- <join name='discriminator'>
- <transition to='d' />
- </join>
- <state name='d' />
- </process-definition>
testDiscriminatorScenario1()
节点执行顺序
start --> a --> multichoice --> b --> discriminator --> d
testDiscriminatorScenario2()
节点执行顺序
start --> a --> multichoice --> c --> discriminator --> d
testDiscriminatorScenario3()
节点执行顺序
start --> a --> multichoice --> b --> discriminator --> d
multichoice --> c --> discriminator(废弃)
testDiscriminatorScenario4()
节点执行顺序
start --> a --> multichoice --> b --> discriminator(废弃) --> d
multichoice --> c --> discriminator
testDiscriminatorScenario5()
节点执行顺序
start --> a --> multichoice --> b --> discriminator --> d
multichoice --> c --> discriminator
testDiscriminatorScenario6()
节点执行顺序
start --> a --> multichoice --> b --> discriminator --> d
multichoice --> c --> discriminator