solon-flow - 控制组合示例
以下示例采用脚本任务风格
1、if 控制示意
节点(活动节点)任务内控制
id: "c1"
layout:
- task: |
if (order.getAmount() >= 100) {
order.setScore(0);
}
使用节点(活动节点)任务条件
id: "c1"
layout:
- { when: "order.getAmount() >= 100", task: "order.setScore(0);"}
使用排它网关
id: "c1"
layout:
- {type: "exclusive", link: [{when: "order.getAmount() >= 100", nextId: "do"}]}
- {id: "do", task: "order.setScore(0);"}
2、for/while 控制示意
节点(活动节点)任务内控制
id: "c1"
layout:
- task: |
for(int i=0; i<10; i++) {
System.out.println(i); //打印
}
id: c1
layout:
- task: |
import java.util.stream.Stream;
Stream.of(1,2,3).parallel().forEach(i -> {
context.runTask(node, "#demo2"); //运行任务描述(#子链)
});
使用排它网关+计数器
id: c1
layout:
- type: start
- id: do
task: |
System.out.println(context.counter().get("demo"));
- type: "exclusive"
link:
- nextId: do
condition: 'context.counter().incr("demo") < 10'
3、switch 控制示意
节点(活动节点)任务内控制
id: "c1"
layout:
- task: |
switch(type) {
case 1: ...
case 2: ...
}
使用包容网关
id: c1
layout:
- {type: inclusive, link: [{when: "type == 1", nextId: "do1"}, {when: "type == 2", nextId: "do2"}]}
- {id: do1, task: ...}
- {id: do2, task: ...}