From a58e3da8db7a329c16b30ad48c1d79e36e2b3e4d Mon Sep 17 00:00:00 2001 From: daiqi <466608943@qq.com> Date: Tue, 18 Jan 2022 01:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/FlowExecutor.java | 6 ++++ .../yomahub/liteflow/entity/data/AbsSlot.java | 9 ++++++ .../test/privateDelivery/cmp/ACmp.java | 19 ++++++++++-- .../test/privateDelivery/cmp/BCmp.java | 30 ++++++++++++++----- .../test/privateDelivery/cmp/DCmp.java | 21 +++++++++++++ .../test/resources/privateDelivery/flow.xml | 15 +++------- 6 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index bc0d05f0d..99777f69b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -13,6 +13,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; +import com.yomahub.liteflow.entity.flow.Node; import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.exception.*; import com.yomahub.liteflow.parser.*; @@ -266,6 +267,11 @@ public class FlowExecutor { this.execute(chainId, param, slotClazz, slotIndex, true); } + public void invoke(String nodeId, Integer slotIndex) throws Exception { + Node node = FlowBus.getNode(nodeId); + node.execute(slotIndex); + } + public DefaultSlot execute(String chainId) throws Exception { return this.execute(chainId, null, DefaultSlot.class, null, false); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java index e9061327e..ebdc4f261 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java @@ -127,6 +127,15 @@ public abstract class AbsSlot implements Slot { } } + public Queue getPrivateDeliveryQueue(String nodeId){ + String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId; + if(dataMap.containsKey(privateDKey)){ + return (Queue) dataMap.get(privateDKey); + }else{ + return null; + } + } + public T getPrivateDeliveryData(String nodeId){ String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId; if(dataMap.containsKey(privateDKey)){ diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index 26fe58c6e..88aa64dd8 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -8,23 +8,36 @@ package com.yomahub.liteflow.test.privateDelivery.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.Slot; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.HashSet; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; @LiteflowComponent("a") public class ACmp extends NodeComponent { - + @Autowired + private FlowExecutor flowExecutor; @Override public void process() { System.out.println("ACmp executed!"); Slot slot = getSlot(); slot.setData("testSet", new HashSet<>()); - for (int i = 0; i < 100; i++) { - this.sendPrivateDeliveryData("b",i+1); + try { + Queue queue = new ConcurrentLinkedQueue<>(); + for (int i = 1; i <= 100; i++) { + queue.add(i); + } + flowExecutor.execute2Resp("chain2", queue); + + }catch (Exception e) { + e.printStackTrace(); } } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 6a0cfbb5e..d3c9b4997 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -1,26 +1,42 @@ /** *

Title: liteflow

*

Description: 轻量级的组件式流程框架

+ * * @author Bryan.Zhang * @email weenyc31@163.com * @Date 2020/4/1 */ package com.yomahub.liteflow.test.privateDelivery.cmp; +import cn.hutool.core.collection.CollUtil; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; +import java.util.Queue; import java.util.Set; @LiteflowComponent("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BCmp executed!"); - Integer value = this.getPrivateDeliveryData(); - Set testSet = this.getSlot().getData("testSet"); - testSet.add(value); - } + @Override + public boolean isAccess() { + Queue values = this.getSlot().getRequestData(); + System.out.println("BCmp executed! values.size" + values.size()); + if (CollUtil.isEmpty(values)) { + return false; + } + Integer value = values.poll(); + if (value == null) { + return false; + } + this.sendPrivateDeliveryData(this.getNodeId(), value); + return true; + } + + @Override + public void process() { + Integer value = getPrivateDeliveryData(); + System.out.println("BCmp executed!" + value); + } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java new file mode 100644 index 000000000..a17ad9bb6 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/privateDelivery/flow.xml b/liteflow-testcase-springboot/src/test/resources/privateDelivery/flow.xml index bf7146217..37ce81f4a 100644 --- a/liteflow-testcase-springboot/src/test/resources/privateDelivery/flow.xml +++ b/liteflow-testcase-springboot/src/test/resources/privateDelivery/flow.xml @@ -2,17 +2,10 @@ - - - - - - - - - - - + +
+        
+    
 
\ No newline at end of file