diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index 0fffaf78b..c2fe5c3e2 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -9,7 +9,7 @@ com.yomahub liteflow - 2.7.1 + 2.7.2 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 d716bc8e3..636e249ca 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 @@ -370,7 +370,6 @@ public class FlowExecutor { if (ObjectUtil.isNotNull(param)){ slot.setRequestData(param); } - slot.setChainName(chainId); } else { if (ObjectUtil.isNotNull(param)){ slot.setChainReqData(chainId, param); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index b994c6ad6..46571ebcb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -296,6 +296,10 @@ public abstract class NodeComponent{ return getSlot().getRequestData(); } + public T getSubChainReqData(){ + return getSlot().getChainReqData(this.getChainName()); + } + public String getChainName(){ return getSlot().getChainName(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java index 5bce26970..c1fe63e38 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java @@ -31,15 +31,8 @@ public class Chain implements Executable { private String chainName; - //主体Condition private List conditionList = new ArrayList<>(); - //前置处理Condition,用来区别主体的Condition - private List preConditionList = new ArrayList<>(); - - //后置处理Condition,用来区别主体的Condition - private List finallyConditionList = new ArrayList<>(); - public Chain(String chainName){ this.chainName = chainName; } @@ -51,57 +44,6 @@ public class Chain implements Executable { this.conditionList = conditionList; } - //执行chain的主方法 - @Override - public void execute(Integer slotIndex) throws Exception { - if (CollUtil.isEmpty(conditionList)) { - throw new FlowSystemException("no conditionList in this chain[" + chainName + "]"); - } - try { - //执行前置 - this.executePre(slotIndex); - //执行主体Condition - for (Condition condition : conditionList) { - condition.execute(slotIndex); - } - }catch (ChainEndException e){ - //这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 - //是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 - throw e; - }catch (Exception e){ - //这里事先取到exception set到slot里,为了方便finally取到exception - Slot slot = DataBus.getSlot(slotIndex); - slot.setException(e); - throw e; - }finally { - //执行后置 - this.executeFinally(slotIndex); - } - } - - // 执行pre节点 - private void executePre(Integer slotIndex) throws Exception { - for (Condition condition : this.preConditionList){ - condition.execute(slotIndex); - } - } - - private void executeFinally(Integer slotIndex) throws Exception { - for (Condition condition : this.finallyConditionList){ - condition.execute(slotIndex); - } - } - - @Override - public ExecuteTypeEnum getExecuteType() { - return ExecuteTypeEnum.CHAIN; - } - - @Override - public String getExecuteName() { - return chainName; - } - public List getConditionList() { return conditionList; } @@ -118,19 +60,174 @@ public class Chain implements Executable { this.chainName = chainName; } - public List getPreConditionList() { - return preConditionList; + //执行chain的主方法 + @Override + public void execute(Integer slotIndex) throws Exception { + if (CollUtil.isEmpty(conditionList)) { + throw new FlowSystemException("no conditionList in this chain[" + chainName + "]"); + } + Slot slot = DataBus.getSlot(slotIndex); + try { + //执行前置 + this.executePre(slotIndex); + //执行主体Condition + for (Condition condition : conditionList) { + condition.execute(slotIndex); + } + }catch (ChainEndException e){ + //这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 + //是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 + throw e; + }catch (Exception e){ + //这里事先取到exception set到slot里,为了方便finally取到exception + slot.setException(e); + throw e; + }finally { + //执行后置 + this.executeFinally(slotIndex); + //流程结束后,需要把当前的chainName从stack结构中移出 + //里面的逻辑判断了当只剩根chainName的时候,不移除 + slot.popChainName(); + } } - public void setPreConditionList(List preConditionList) { - this.preConditionList = preConditionList; + // 执行pre节点 + public void executePre(Integer slotIndex) throws Exception { + doExecuteForPointConditionType(slotIndex, ConditionTypeEnum.TYPE_PRE); } - public List getFinallyConditionList() { - return finallyConditionList; + public void executeFinally(Integer slotIndex) throws Exception { + doExecuteForPointConditionType(slotIndex, ConditionTypeEnum.TYPE_FINALLY); } - public void setFinallyConditionList(List finallyConditionList) { - this.finallyConditionList = finallyConditionList; + // 执行指定的conditionType的节点 + private void doExecuteForPointConditionType(Integer slotIndex, ConditionTypeEnum conditionTypeEnum) throws Exception { + //先把指定condition类型的节点过滤出来 + List conditions =filterCondition(conditionTypeEnum); + for (Condition condition : conditions){ + for(Executable executableItem : condition.getNodeList()){ + executableItem.execute(slotIndex); + } + } + } + + // 根据节点condition类型过去出节点列表 + private List filterCondition(ConditionTypeEnum conditionTypeEnum) { + assert conditionTypeEnum != null; + return conditionList.stream().filter(condition -> + condition.getConditionType().equals(conditionTypeEnum)).collect(Collectors.toList()); + } + + @Override + public ExecuteTypeEnum getExecuteType() { + return ExecuteTypeEnum.CHAIN; + } + + @Override + public String getExecuteName() { + return chainName; + } + + //使用线程池执行when并发流程 + //这块涉及到挺多的多线程逻辑,所以注释比较详细,看到这里的童鞋可以仔细阅读 + private void executeAsyncCondition(WhenCondition condition, Integer slotIndex) throws Exception{ + Slot slot = DataBus.getSlot(slotIndex); + + //此方法其实只会初始化一次Executor,不会每次都会初始化。Executor是唯一的 + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(condition.getThreadExecutorClass()); + + //获得liteflow的参数 + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + + //定义是否中断参数 + //这里为什么要定义成数组呢,因为后面lambda要用到,根据final不能修改引用的原则,这里用了数组对象 + final boolean[] interrupted = {false}; + + //这里主要是做了封装CompletableFuture对象,用lumbda表达式做了很多事情,这句代码要仔细理清 + //1.根据condition.getNodeList()的集合进行流处理,用map进行把executable对象转换成List> + //2.在转的过程中,套入CompletableFutureTimeout方法进行超时判断,如果超时则用WhenFutureObj.timeOut返回超时的对象 + //3.第2个参数是主要的本体CompletableFuture,传入了ParallelSupplier和线程池对象 + List> completableFutureList = condition.getNodeList().stream().filter(executable -> { + try { + return executable.isAccess(slotIndex); + }catch (Exception e){ + LOG.error("there was an error when executing the when component isAccess",e); + return false; + } + }).map(executable -> CompletableFutureTimeout.completeOnTimeout( + WhenFutureObj.timeOut(executable.getExecuteName()), + CompletableFuture.supplyAsync(new ParallelSupplier(executable, slotIndex), parallelExecutor), + liteflowConfig.getWhenMaxWaitSeconds(), + TimeUnit.SECONDS + )).collect(Collectors.toList()); + + + CompletableFuture resultCompletableFuture; + + //这里判断执行方式 + //如果any为false,说明这些异步任务全部执行好或者超时,才返回 + //如果any为true,说明这些异步任务只要任意一个执行完成,就返回 + if(condition.isAny()){ + //把这些CompletableFuture通过anyOf合成一个CompletableFuture + resultCompletableFuture = CompletableFuture.anyOf(completableFutureList.toArray(new CompletableFuture[]{})); + }else{ + //把这些CompletableFuture通过allOf合成一个CompletableFuture + resultCompletableFuture = CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[]{})); + } + + try { + //进行执行,这句执行完后,就意味着所有的任务要么执行完毕,要么超时返回 + resultCompletableFuture.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("there was an error when executing the CompletableFuture",e); + interrupted[0] = true; + } + + //拿到已经完成的CompletableFuture + //如果any为false,那么所有任务都已经完成 + //如果any为true,那么这里拿到的是第一个完成的任务 + //这里过滤和转换一起用lumbda做了 + List allCompletableWhenFutureObjList = completableFutureList.stream().filter(f -> { + //过滤出已经完成的,没完成的就直接终止 + if (f.isDone()){ + return true; + }else{ + f.cancel(true); + return false; + } + }).map(f -> { + try { + return f.get(); + } catch (InterruptedException | ExecutionException e) { + interrupted[0] = true; + return null; + } + }).collect(Collectors.toList()); + + //判断超时,上面已经拿到了所有已经完成的CompletableFuture + //那我们只要过滤出超时的CompletableFuture + List timeOutWhenFutureObjList = allCompletableWhenFutureObjList.stream().filter(WhenFutureObj::isTimeout).collect(Collectors.toList()); + + //输出超时信息 + timeOutWhenFutureObjList.forEach(whenFutureObj -> + LOG.warn("requestId [{}] executing thread has reached max-wait-seconds, thread canceled.Execute-item: [{}]", slot.getRequestId(), whenFutureObj.getExecutorName())); + + //当配置了errorResume = false,出现interrupted或者!f.get()的情况,将抛出WhenExecuteException + if (!condition.isErrorResume()) { + if (interrupted[0]) { + throw new WhenExecuteException(StrUtil.format("requestId [{}] when execute interrupted. errorResume [false].", slot.getRequestId())); + } + + //循环判断CompletableFuture的返回值,如果异步执行失败,则抛出相应的业务异常 + for(WhenFutureObj whenFutureObj : allCompletableWhenFutureObjList){ + if (!whenFutureObj.isSuccess()){ + LOG.info(StrUtil.format("requestId [{}] when-executor[{}] execute failed. errorResume [false].", whenFutureObj.getExecutorName(), slot.getRequestId())); + throw whenFutureObj.getEx(); + } + } + } else if (interrupted[0]) { + // 这里由于配置了errorResume,所以只打印warn日志 + LOG.warn("requestId [{}] executing when condition timeout , but ignore with errorResume.", slot.getRequestId()); + } } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java index 1c7cc3dc4..f0bdc1a98 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java @@ -15,6 +15,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Iterator; import java.util.Queue; +import java.util.Stack; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -63,6 +64,10 @@ public class Slot{ this.contextBean = contextBean; } + private boolean hasMetaData(String key){ + return metaDataMap.containsKey(key); + } + private void putMetaDataMap(String key, T t) { if (ObjectUtil.isNull(t)) { //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException @@ -152,12 +157,33 @@ public class Slot{ return (T) metaDataMap.get(COND_NODE_PREFIX + key); } - public void setChainName(String chainName) { - putMetaDataMap(CHAIN_NAME, chainName); + public void pushChainName(String chainName) { + if (this.hasMetaData(CHAIN_NAME)){ + Stack stack = (Stack)metaDataMap.get(CHAIN_NAME); + stack.push(chainName); + }else{ + Stack stack = new Stack<>(); + stack.push(chainName); + this.putMetaDataMap(CHAIN_NAME, stack); + } + } + + public void popChainName(){ + if (this.hasMetaData(CHAIN_NAME)){ + Stack stack = (Stack)metaDataMap.get(CHAIN_NAME); + if (stack.size() > 1){ + stack.pop(); + } + } } public String getChainName() { - return (String) metaDataMap.get(CHAIN_NAME); + try{ + Stack stack = (Stack)metaDataMap.get(CHAIN_NAME); + return stack.peek(); + }catch (Exception e){ + return null; + } } public void addStep(CmpStep step){ diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java index 459eeee29..e4996129c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java @@ -19,7 +19,7 @@ public class LOGOPrinter { str.append(" | | | | | | | _| _____| |_ | | | | | \\ \\ /\\ / / \n"); str.append(" | |___ | | | | | |__|_____| _| | |__| |_| |\\ V V / \n"); str.append(" |_____|___| |_| |_____| |_| |_____\\___/ \\_/\\_/ \n\n"); - str.append(" Version: v2.7.1\n"); + str.append(" Version: v2.7.2\n"); str.append(" 轻量且强大的规则引擎框架。\n"); str.append(" Small but powerful rules engine.\n"); str.append("================================================================================================\n"); diff --git a/liteflow-script-common/pom.xml b/liteflow-script-common/pom.xml index a3dffa8bc..77677ed97 100644 --- a/liteflow-script-common/pom.xml +++ b/liteflow-script-common/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-script-groovy/pom.xml b/liteflow-script-groovy/pom.xml index 6fb669b16..006dcec18 100644 --- a/liteflow-script-groovy/pom.xml +++ b/liteflow-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-script-qlexpress/pom.xml b/liteflow-script-qlexpress/pom.xml index eee133efe..5c64d438a 100644 --- a/liteflow-script-qlexpress/pom.xml +++ b/liteflow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml index b95c2efd0..37873d036 100644 --- a/liteflow-spring-boot-starter/pom.xml +++ b/liteflow-spring-boot-starter/pom.xml @@ -10,7 +10,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 diff --git a/liteflow-spring/pom.xml b/liteflow-spring/pom.xml index 44a8b8645..6c0d48e40 100644 --- a/liteflow-spring/pom.xml +++ b/liteflow-spring/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-declare-component/pom.xml b/liteflow-testcase-declare-component/pom.xml index aea858db0..6cbb90793 100644 --- a/liteflow-testcase-declare-component/pom.xml +++ b/liteflow-testcase-declare-component/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java index ea9af06fc..fa014d723 100644 --- a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java @@ -45,5 +45,7 @@ public class ImplicitSubFlowSpringbootTest extends BaseTest { Assert.assertEquals(1, RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + //requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest")); } } diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index d8c5eebf6..7f2f79b5a 100644 --- a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -4,6 +4,7 @@ import com.yomahub.liteflow.annotation.LiteflowCmpDefine; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; @@ -14,6 +15,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU public class HCmp{ @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) throws Exception { + String requestData = bindCmp.getSubChainReqData(); + DefaultContext context = bindCmp.getContextBean(); + context.setData("innerRequest", requestData); RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); diff --git a/liteflow-testcase-nospring/pom.xml b/liteflow-testcase-nospring/pom.xml index 27cf19d95..13ef63435 100644 --- a/liteflow-testcase-nospring/pom.xml +++ b/liteflow-testcase-nospring/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java index 20f649af5..e633a0f74 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java @@ -42,5 +42,7 @@ public class ImplicitSubFlowTest extends BaseTest { Assert.assertEquals(1, RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + //requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest")); } } diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index fd78c1068..68926cd43 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -1,12 +1,17 @@ package com.yomahub.liteflow.test.subflow.cmp2; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; public class HCmp extends NodeComponent { @Override public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getContextBean(); + context.setData("innerRequest", requestData); RUN_TIME_SLOT.add(this.getSlot().getRequestId()); diff --git a/liteflow-testcase-script-groovy/pom.xml b/liteflow-testcase-script-groovy/pom.xml index 464dab8d2..5cb568db7 100644 --- a/liteflow-testcase-script-groovy/pom.xml +++ b/liteflow-testcase-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-script-qlexpress/pom.xml b/liteflow-testcase-script-qlexpress/pom.xml index d77ce0fa1..168215101 100644 --- a/liteflow-testcase-script-qlexpress/pom.xml +++ b/liteflow-testcase-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-springboot/pom.xml b/liteflow-testcase-springboot/pom.xml index e6030a3bb..7bad97049 100644 --- a/liteflow-testcase-springboot/pom.xml +++ b/liteflow-testcase-springboot/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java index ea9af06fc..fa014d723 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java @@ -45,5 +45,7 @@ public class ImplicitSubFlowSpringbootTest extends BaseTest { Assert.assertEquals(1, RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + //requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest")); } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 29c8122a4..292ccd825 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -11,9 +11,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU public class HCmp extends NodeComponent { @Override public void process() throws Exception { + String requestData = this.getSubChainReqData(); DefaultContext context = this.getContextBean(); - String str = context.getData("innerRequestData"); - System.out.println(str); + context.setData("innerRequest", requestData); RUN_TIME_SLOT.add(this.getSlot().getRequestId()); diff --git a/liteflow-testcase-springnative/pom.xml b/liteflow-testcase-springnative/pom.xml index 8d954e892..e4ac2cda2 100644 --- a/liteflow-testcase-springnative/pom.xml +++ b/liteflow-testcase-springnative/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.1 + 2.7.2 4.0.0 diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java index f4b712a8c..7889d7cb2 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java @@ -39,5 +39,7 @@ public class ImplicitSubFlowSpringTest extends BaseTest { Assert.assertEquals(1, RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + //requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest")); } } diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 84688b17c..1d05d7501 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -1,6 +1,7 @@ package com.yomahub.liteflow.test.subflow.cmp2; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TIME_SLOT; @@ -10,6 +11,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TI public class HCmp extends NodeComponent { @Override public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getContextBean(); + context.setData("innerRequest", requestData); RUN_TIME_SLOT.add(this.getSlot().getRequestId()); diff --git a/pom.xml b/pom.xml index 14f3adf5d..41e2d2b5e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yomahub liteflow pom - 2.7.1 + 2.7.2 liteflow a lightweight and practical micro-process framework https://github.com/bryan31/liteflow