bug #I5C23U 子流程用getChainName取不到当前ChainName的问题

bug #I5BZW7 隐式流程的requestData获取不到的问题
This commit is contained in:
everywhere.z 2022-06-13 17:38:27 +08:00
parent 7870de68d4
commit 7a7a9ef64d
27 changed files with 92 additions and 26 deletions

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.yomahub</groupId>
<artifactId>liteflow</artifactId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<dependencies>

View File

@ -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);

View File

@ -300,6 +300,10 @@ public abstract class NodeComponent{
return getSlot().getRequestData();
}
public <T> T getSubChainReqData(){
return getSlot().getChainReqData(this.getChainName());
}
public String getChainName(){
return getSlot().getChainName();
}

View File

@ -28,6 +28,7 @@ import com.yomahub.liteflow.thread.ExecutorHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -83,14 +84,26 @@ public class Chain implements Executable {
if (CollUtil.isEmpty(conditionList)) {
throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
}
for (Condition condition : conditionList) {
if (condition instanceof ThenCondition) {
for (Executable executableItem : condition.getNodeList()) {
executableItem.execute(slotIndex);
Slot<?> slot = DataBus.getSlot(slotIndex);
try{
//在子流程或者隐式流程里slot需要取到的chainName是当前流程所以这不再是set而是push
//其底层结构是一个stack
slot.pushChainName(chainName);
//循环condition进行执行
for (Condition condition : conditionList) {
if (condition instanceof ThenCondition) {
for (Executable executableItem : condition.getNodeList()) {
executableItem.execute(slotIndex);
}
} else if (condition instanceof WhenCondition) {
executeAsyncCondition((WhenCondition) condition, slotIndex);
}
} else if (condition instanceof WhenCondition) {
executeAsyncCondition((WhenCondition) condition, slotIndex);
}
}finally {
//流程结束后需要把当前的chainName从stack结构中移出
//里面的逻辑判断了当只剩根chainName的时候不移除
slot.popChainName();
}
}

View File

@ -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<O>{
this.contextBean = contextBean;
}
private boolean hasMetaData(String key){
return metaDataMap.containsKey(key);
}
private <T> 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<O>{
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<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
stack.push(chainName);
}else{
Stack<String> stack = new Stack<>();
stack.push(chainName);
this.putMetaDataMap(CHAIN_NAME, stack);
}
}
public void popChainName(){
if (this.hasMetaData(CHAIN_NAME)){
Stack<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
if (stack.size() > 1){
stack.pop();
}
}
}
public String getChainName() {
return (String) metaDataMap.get(CHAIN_NAME);
try{
Stack<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
return stack.peek();
}catch (Exception e){
return null;
}
}
public void addStep(CmpStep step){

View File

@ -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");

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -10,7 +10,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<dependencies>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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"));
}
}

View File

@ -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());

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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"));
}
}

View File

@ -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());

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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"));
}
}

View File

@ -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.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@ -10,9 +11,7 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
public class FCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println("Fcomp executed!");
}
}

View File

@ -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.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@ -10,6 +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();
context.setData("innerRequest", requestData);
RUN_TIME_SLOT.add(this.getSlot().getRequestId());

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.1</version>
<version>2.7.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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"));
}
}

View File

@ -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());

View File

@ -5,7 +5,7 @@
<groupId>com.yomahub</groupId>
<artifactId>liteflow</artifactId>
<packaging>pom</packaging>
<version>2.7.1</version>
<version>2.7.2</version>
<name>liteflow</name>
<description>a lightweight and practical micro-process framework</description>
<url>https://github.com/bryan31/liteflow</url>