Browse Source

隐式调用流程增加this调用的用法

everywhere.z 2 years ago
parent
commit
edb4d4c3b7

+ 9 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java

@@ -11,6 +11,7 @@ import cn.hutool.core.date.StopWatch;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.ttl.TransmittableThreadLocal;
+import com.yomahub.liteflow.flow.LiteflowResponse;
 import com.yomahub.liteflow.flow.executor.NodeExecutor;
 import com.yomahub.liteflow.flow.executor.DefaultNodeExecutor;
 import com.yomahub.liteflow.enums.NodeTypeEnum;
@@ -299,4 +300,12 @@ public abstract class NodeComponent{
 			return StrUtil.format("{}({})", this.nodeId, this.name);
 		}
 	}
+
+	public void invoke(String chainId, Object param) throws Exception {
+		FlowExecutorHolder.loadInstance().invoke(chainId, param, this.getSlotIndex());
+	}
+
+	public LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex) {
+		return FlowExecutorHolder.loadInstance().invoke2Resp(chainId, param, this.getSlotIndex());
+	}
 }

+ 1 - 6
liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -2,10 +2,8 @@ package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
 import com.yomahub.liteflow.annotation.LiteflowMethod;
-import com.yomahub.liteflow.core.FlowExecutor;
 import com.yomahub.liteflow.core.NodeComponent;
 import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT;
@@ -15,9 +13,6 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootT
 @LiteflowCmpDefine
 public class GCmp{
 
-    @Autowired
-    private FlowExecutor flowExecutor;
-
     @LiteflowMethod(LiteFlowMethodEnum.PROCESS)
     public void process(NodeComponent bindCmp) throws Exception {
 
@@ -25,6 +20,6 @@ public class GCmp{
 
         System.out.println("Gcmp executed!");
 
-        flowExecutor.invoke("chain4", "it's implicit subflow.", bindCmp.getSlotIndex());
+        bindCmp.invoke("chain4", "it's implicit subflow.");
     }
 }

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -23,6 +23,6 @@ public class GCmp extends NodeComponent {
 
 
 
-        flowExecutor.invoke("chain4", "it's implicit subflow.", this.getSlotIndex());
+        this.invoke("chain4", "it's implicit subflow.");
     }
 }

+ 1 - 7
liteflow-testcase-old/liteflow-testcase-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -2,11 +2,8 @@ package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
 import com.yomahub.liteflow.annotation.LiteflowMethod;
-import com.yomahub.liteflow.core.FlowExecutor;
 import com.yomahub.liteflow.core.NodeComponent;
 import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
-import com.yomahub.liteflow.slot.DefaultContext;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@@ -16,9 +13,6 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
 @LiteflowCmpDefine
 public class GCmp{
 
-    @Autowired
-    private FlowExecutor flowExecutor;
-
     @LiteflowMethod(LiteFlowMethodEnum.PROCESS)
     public void process(NodeComponent bindCmp) throws Exception {
 
@@ -26,6 +20,6 @@ public class GCmp{
 
         System.out.println("Gcmp executed!");
 
-        flowExecutor.invoke("chain4", "it's implicit subflow.", bindCmp.getSlotIndex());
+        bindCmp.invoke("chain4", "it's implicit subflow.");
     }
 }

+ 1 - 7
liteflow-testcase-old/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -1,9 +1,5 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
-
-import com.yomahub.liteflow.core.FlowExecutor;
-import com.yomahub.liteflow.core.FlowExecutorHolder;
 import com.yomahub.liteflow.core.NodeComponent;
-import com.yomahub.liteflow.slot.DefaultContext;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
 
@@ -17,8 +13,6 @@ public class GCmp extends NodeComponent {
 
         System.out.println("Gcmp executed!");
 
-        FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance();
-
-        flowExecutor.invoke("chain4", "it's implicit subflow.", this.getSlotIndex());
+        this.invoke("chain4", "it's implicit subflow.");
     }
 }

+ 1 - 8
liteflow-testcase-old/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -1,8 +1,6 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
-import com.yomahub.liteflow.core.FlowExecutor;
 import com.yomahub.liteflow.core.NodeComponent;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@@ -11,9 +9,6 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
 @Component("g")
 public class GCmp extends NodeComponent {
 
-    @Autowired
-    private FlowExecutor flowExecutor;
-
     @Override
     public void process() throws Exception {
 
@@ -21,8 +16,6 @@ public class GCmp extends NodeComponent {
 
         System.out.println("Gcmp executed!");
 
-
-
-        flowExecutor.invoke("chain4", "it's implicit subflow.", this.getSlotIndex());
+        this.invoke("chain4", "it's implicit subflow.");
     }
 }

+ 1 - 6
liteflow-testcase-old/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java

@@ -1,8 +1,6 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
-import com.yomahub.liteflow.core.FlowExecutor;
 import com.yomahub.liteflow.core.NodeComponent;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TIME_SLOT;
@@ -11,9 +9,6 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TI
 @Component("g")
 public class GCmp extends NodeComponent {
 
-    @Autowired
-    private FlowExecutor flowExecutor;
-
     @Override
     public void process() throws Exception {
 
@@ -21,6 +16,6 @@ public class GCmp extends NodeComponent {
 
         System.out.println("Gcmp executed!");
 
-        flowExecutor.invoke("chain4", "it's implicit subflow.", this.getSlotIndex());
+        this.invoke("chain4", "it's implicit subflow.");
     }
 }