feature #I7HJFX 添加parallel关键字及其解析方式,为LoopCondition添加parallel属性

This commit is contained in:
zy
2023-07-01 16:46:57 +08:00
parent f3bb3f8b6c
commit 897efe674f
4 changed files with 89 additions and 60 deletions

View File

@@ -78,6 +78,7 @@ public class LiteFlowChainELBuilder {
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DO, Object.class, new DoOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.BREAK, Object.class, new BreakOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DATA, Object.class, new DataOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.PARALLEL, Object.class, new ParallelOperator());
}
public static LiteFlowChainELBuilder createChain() {

View File

@@ -0,0 +1,25 @@
package com.yomahub.liteflow.builder.el.operator;
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
import com.yomahub.liteflow.flow.element.condition.LoopCondition;
/**
* EL规则中的parallel的操作符
*
* @author zhhhhy
* @since 2.10.5
*/
public class ParallelOperator extends BaseOperator<LoopCondition> {
@Override
public LoopCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
LoopCondition loopCondition = OperatorHelper.convert(objects[0], LoopCondition.class);
Boolean parallel = OperatorHelper.convert(objects[1], Boolean.class);
loopCondition.setParallel(parallel);
return loopCondition;
}
}

View File

@@ -6,6 +6,7 @@ package com.yomahub.liteflow.common;
* @author tangkc
*/
public interface ChainConstant {
String PARALLEL = "parallel";
String CHAIN = "chain";

View File

@@ -12,73 +12,75 @@ import com.yomahub.liteflow.flow.element.Node;
* @since 2.9.0
*/
public abstract class LoopCondition extends Condition {
//判断循环是否并行执行默认为false
private boolean parallel = false;
protected Executable getBreakItem() {
return this.getExecutableOne(ConditionKey.BREAK_KEY);
}
protected Executable getBreakItem() {
return this.getExecutableOne(ConditionKey.BREAK_KEY);
}
public void setBreakItem(Executable breakNode) {
this.addExecutable(ConditionKey.BREAK_KEY, breakNode);
}
public void setBreakItem(Executable breakNode) {
this.addExecutable(ConditionKey.BREAK_KEY, breakNode);
}
protected Executable getDoExecutor() {
return this.getExecutableOne(ConditionKey.DO_KEY);
}
protected Executable getDoExecutor() {
return this.getExecutableOne(ConditionKey.DO_KEY);
}
public void setDoExecutor(Executable executable) {
this.addExecutable(ConditionKey.DO_KEY, executable);
}
public void setDoExecutor(Executable executable) {
this.addExecutable(ConditionKey.DO_KEY, executable);
}
protected void setLoopIndex(Executable executableItem, int index) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(condition -> setLoopIndex(condition, index));
}
else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(executable -> setLoopIndex(executable, index)));
}
else if (executableItem instanceof Node) {
((Node) executableItem).setLoopIndex(index);
}
}
protected void setLoopIndex(Executable executableItem, int index) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(condition -> setLoopIndex(condition, index));
} else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(executable -> setLoopIndex(executable, index)));
} else if (executableItem instanceof Node) {
((Node) executableItem).setLoopIndex(index);
}
}
protected void setCurrLoopObject(Executable executableItem, Object obj) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(condition -> setCurrLoopObject(condition, obj));
}
else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(executable -> setCurrLoopObject(executable, obj)));
}
else if (executableItem instanceof Node) {
((Node) executableItem).setCurrLoopObject(obj);
}
}
protected void setCurrLoopObject(Executable executableItem, Object obj) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(condition -> setCurrLoopObject(condition, obj));
} else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(executable -> setCurrLoopObject(executable, obj)));
} else if (executableItem instanceof Node) {
((Node) executableItem).setCurrLoopObject(obj);
}
}
protected void removeLoopIndex(Executable executableItem){
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(this::removeLoopIndex);
}
else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(this::removeLoopIndex));
}
else if (executableItem instanceof Node) {
((Node) executableItem).removeLoopIndex();
}
}
protected void removeLoopIndex(Executable executableItem) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(this::removeLoopIndex);
} else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(this::removeLoopIndex));
} else if (executableItem instanceof Node) {
((Node) executableItem).removeLoopIndex();
}
}
protected void removeCurrLoopObject(Executable executableItem){
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(this::removeCurrLoopObject);
}
else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(this::removeCurrLoopObject));
}
else if (executableItem instanceof Node) {
((Node) executableItem).removeCurrLoopObject();
}
}
protected void removeCurrLoopObject(Executable executableItem) {
if (executableItem instanceof Chain) {
((Chain) executableItem).getConditionList().forEach(this::removeCurrLoopObject);
} else if (executableItem instanceof Condition) {
((Condition) executableItem).getExecutableGroup()
.forEach((key, value) -> value.forEach(this::removeCurrLoopObject));
} else if (executableItem instanceof Node) {
((Node) executableItem).removeCurrLoopObject();
}
}
public boolean isParallel() {
return parallel;
}
public void setParallel(boolean parallel) {
this.parallel = parallel;
}
}