JBoss series thirty-nine: jBPM5 example of Multiple Instance Sub-Process

Multiple Instance sub-process jBPM5 is more specific sub-process, which allows the sub-process contains several execution, when there is a collection element is present, then the subprocess execution cycle, until the set is empty elements, sub-process execution End. As follows Multiple Instance sub-process flow schematic:


As shown, the main flow starts when we pass a queue, the queue including a series of integers, each sub-process run queue is determined whether the integer is divisible by 2 (odd number), it will not be added if the integer corresponding to the error list, note that the number of sub-processes run is equal to the size of the queue. Run the end of the process error list printout.

Will start running org.jbpm.quickstarts.subprocess.MultipleNodeInstanceProcessStart Multiple Instance sub-process flow, MultipleNodeInstanceProcessStart class code as follows:

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 flow operating results:

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]

The results above show that the odd-numbered queue 13 and 7.

Reproduced in: https: //my.oschina.net/iwuyang/blog/197242

Guess you like

Origin blog.csdn.net/weixin_34007879/article/details/91897336