JBoss 系列三十九:jBPM5示例之 Multiple Instance Sub-Process

jBPM5中的Multiple Instance sub-process是较特殊的子流程,它允许多次执行包含的子流程,当一个集合中有元素存在,则子流程循环执行,直到集合中的元素为空,子流程执行结束。如下为Multiple Instance sub-process流程示意:

JBoss 系列三十九:jBPM5示例之 Multiple Instance Sub-Process_第1张图片

如图,在主流程启动时我们传入一个队列,队列中包括一系列整数,子流程运行每次判断队列中的整数能否被2整除(奇数),如果不能被则将相应的整数添加到错误列表,注意,子流程运行的次数等于队列的大小。流程运行结束打印输出错误列表。

  • Multiple Instance sub-process流程运行代码:https://github.com/kylinsoong/.../MultipleNodeInstanceProcessStart.java
  • Multiple Instance sub-process流程:https://github.com/kylinsoong/.../multipleNodeInstanceProcess.bpmn
运行org.jbpm.quickstarts.subprocess.MultipleNodeInstanceProcessStart将会启动Multiple Instance sub-process流程,MultipleNodeInstanceProcessStart类代码如下:

package org.jbpm.quickstarts.subprocess;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.quickstarts.QuickStartBase;

public class MultipleNodeInstanceProcessStart extends QuickStartBase {

	public static void main(String[] args) {
		new MultipleNodeInstanceProcessStart().test();
	}

	public void test() {
		StatefulKnowledgeSession ksession = createKnowledgeSession("quickstarts/multipleNodeInstanceProcess.bpmn");
		
		List<Number> numbers = new ArrayList<Number>();
        numbers.add(2);
        numbers.add(4);
        numbers.add(56);
        numbers.add(7);
        numbers.add(10);
        numbers.add(13);
        
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("numberList", numbers);
        parameters.put("errorList", new ArrayList());
        
        //Start the process using its id
        ProcessInstance process = ksession.startProcess("org.jbpm.quickstarts.multiplenodeinstanceprocess",parameters);
        List errorList = (List) ((WorkflowProcessInstance)process).getVariable("errorList");
        System.out.println("Error List: " + errorList);
	}

}

Multiple Instance sub-process流程运行结果:

Is 2 Even? true
Is 4 Even? true
Is 56 Even? true
Is 7 Even? false
Odd number found: 7
Is 10 Even? true
Is 13 Even? false
Odd number found: 13
Error List: [7, 13]

如上结果显示,队列中奇数为7和13.

你可能感兴趣的:(jboss,jbpm,instance,multiple,BPM,JBPM5,su)