From 897efe674f18d913e7e4d710258dbfc3cfd72b8b Mon Sep 17 00:00:00 2001 From: zy <953725892@qq.com> Date: Sat, 1 Jul 2023 16:46:57 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I7HJFX=20=E6=B7=BB=E5=8A=A0parallel?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=E5=8F=8A=E5=85=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=B8=BALoopCondition=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0parallel=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 1 + .../builder/el/operator/ParallelOperator.java | 25 ++++ .../liteflow/common/ChainConstant.java | 1 + .../flow/element/condition/LoopCondition.java | 122 +++++++++--------- 4 files changed, 89 insertions(+), 60 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ParallelOperator.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index cc1e3d4db..327e5b60b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -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() { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ParallelOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ParallelOperator.java new file mode 100644 index 000000000..fda4d57b5 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ParallelOperator.java @@ -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 { + @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; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index 0cdbdce99..35037f481 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -6,6 +6,7 @@ package com.yomahub.liteflow.common; * @author tangkc */ public interface ChainConstant { + String PARALLEL = "parallel"; String CHAIN = "chain"; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java index 4f89b3ea8..2861e59c6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java @@ -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; + } }