mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-19 18:29:42 +08:00
[I5BR5M]chain 重复的问题
This commit is contained in:
@@ -89,8 +89,6 @@ public class FlowExecutor {
|
||||
if (StrUtil.isBlank(liteflowConfig.getRuleSource())) {
|
||||
return;
|
||||
}
|
||||
// 初始化前清空缓存
|
||||
FlowBus.cleanChainMap();
|
||||
|
||||
List<String> sourceRulePathList = Lists.newArrayList(liteflowConfig.getRuleSource().split(",|;"));
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.yomahub.liteflow.core.ScriptComponent;
|
||||
import com.yomahub.liteflow.core.ScriptCondComponent;
|
||||
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ChainDuplicateException;
|
||||
import com.yomahub.liteflow.exception.ComponentCannotRegisterException;
|
||||
import com.yomahub.liteflow.flow.element.Chain;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
@@ -63,8 +62,6 @@ public class FlowBus {
|
||||
public static void addChain(String chainName) {
|
||||
if (!chainMap.containsKey(chainName)) {
|
||||
chainMap.put(chainName, new Chain(chainName));
|
||||
} else {
|
||||
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +158,7 @@ public class FlowBus {
|
||||
|
||||
nodeMap.put(nodeId, node);
|
||||
} catch (Exception e) {
|
||||
String error = StrUtil.format("component[{}][{}] register error", cmpClazz.getName(), StringUtils.isEmpty(name)?nodeId:nodeId+"("+name+")");
|
||||
String error = StrUtil.format("component[{}][{}] register error", cmpClazz.getName(), StringUtils.isEmpty(name) ? nodeId : nodeId + "(" + name + ")");
|
||||
LOG.error(error, e);
|
||||
throw new ComponentCannotRegisterException(error);
|
||||
}
|
||||
@@ -189,10 +186,6 @@ public class FlowBus {
|
||||
cleanScriptCache();
|
||||
}
|
||||
|
||||
public static void cleanChainMap(){
|
||||
chainMap.clear();
|
||||
}
|
||||
|
||||
public static void cleanScriptCache() {
|
||||
//如果引入了脚本组件SPI,则还需要清理脚本的缓存
|
||||
try {
|
||||
@@ -205,8 +198,6 @@ public class FlowBus {
|
||||
}
|
||||
|
||||
public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception {
|
||||
// 刷新前清空缓存
|
||||
cleanChainMap();
|
||||
|
||||
if (type.equals(FlowParserTypeEnum.TYPE_XML)) {
|
||||
new LocalXmlFlowParser().parse(content);
|
||||
|
||||
@@ -9,12 +9,15 @@ import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
|
||||
import com.yomahub.liteflow.builder.prop.ChainPropBean;
|
||||
import com.yomahub.liteflow.builder.prop.NodePropBean;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ChainDuplicateException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.spi.holder.ContextCmpInitHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import static com.yomahub.liteflow.common.ChainConstant.ANY;
|
||||
import static com.yomahub.liteflow.common.ChainConstant.CHAIN;
|
||||
@@ -42,6 +45,8 @@ public abstract class JsonFlowParser extends BaseFlowParser {
|
||||
|
||||
private final Logger LOG = LoggerFactory.getLogger(JsonFlowParser.class);
|
||||
|
||||
private final Set<String> CHAIN_NAME_SET = new CopyOnWriteArraySet<>();
|
||||
|
||||
public void parse(String content) throws Exception {
|
||||
parse(ListUtil.toList(content));
|
||||
}
|
||||
@@ -80,9 +85,18 @@ public abstract class JsonFlowParser extends BaseFlowParser {
|
||||
//先在元数据里放上chain
|
||||
chainArray.forEach(o -> {
|
||||
JSONObject innerJsonObject = (JSONObject) o;
|
||||
|
||||
// 校验加载的 chainName 是否有重复的
|
||||
String chainName = innerJsonObject.getString(NAME);
|
||||
if (!CHAIN_NAME_SET.add(chainName)) {
|
||||
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
|
||||
}
|
||||
|
||||
FlowBus.addChain(innerJsonObject.getString(NAME));
|
||||
});
|
||||
});
|
||||
// 清空
|
||||
CHAIN_NAME_SET.clear();
|
||||
|
||||
for (JSONObject flowJsonObject : flowJsonObjectList) {
|
||||
// 当存在<nodes>节点定义时,解析node节点
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
|
||||
import com.yomahub.liteflow.builder.prop.ChainPropBean;
|
||||
import com.yomahub.liteflow.builder.prop.NodePropBean;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ChainDuplicateException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.spi.holder.ContextCmpInitHolder;
|
||||
import org.dom4j.Document;
|
||||
@@ -17,6 +18,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import static com.yomahub.liteflow.common.ChainConstant.ANY;
|
||||
import static com.yomahub.liteflow.common.ChainConstant.CHAIN;
|
||||
@@ -43,6 +46,8 @@ public abstract class XmlFlowParser extends BaseFlowParser {
|
||||
|
||||
private final Logger LOG = LoggerFactory.getLogger(XmlFlowParser.class);
|
||||
|
||||
private final Set<String> CHAIN_NAME_SET = new CopyOnWriteArraySet<>();
|
||||
|
||||
public void parse(String content) throws Exception {
|
||||
parse(ListUtil.toList(content));
|
||||
}
|
||||
@@ -76,8 +81,19 @@ public abstract class XmlFlowParser extends BaseFlowParser {
|
||||
List<Element> chainList = document.getRootElement().elements(CHAIN);
|
||||
|
||||
//先在元数据里放上chain
|
||||
chainList.forEach(e -> FlowBus.addChain(e.attributeValue(NAME)));
|
||||
chainList.forEach(e -> {
|
||||
|
||||
// 校验加载的 chainName 是否有重复的
|
||||
String chainName = e.attributeValue(NAME);
|
||||
if (!CHAIN_NAME_SET.add(chainName)) {
|
||||
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
|
||||
}
|
||||
|
||||
FlowBus.addChain(chainName);
|
||||
});
|
||||
});
|
||||
// 清空
|
||||
CHAIN_NAME_SET.clear();
|
||||
|
||||
for (Document document : documentList) {
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SpringELSupportSpringbootTest extends BaseTest {
|
||||
//测试springEL的解析情况
|
||||
@Test
|
||||
public void testSpringELParser() {
|
||||
LiteflowResponse<DefaultContext> response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
LiteflowResponse<DefaultContext> response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
<node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
<chain name="chain11">
|
||||
<then value="a,c"/>
|
||||
<when value="b,d,e(f|g)"/>
|
||||
<then value="chain2"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
<chain name="chain12">
|
||||
<then value="c,g,f"/>
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<chain name="chain1">
|
||||
<chain name="chain21">
|
||||
<then value="a,c"/>
|
||||
<when value="b,d,e(f|g)"/>
|
||||
<then value="chain2"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain2">
|
||||
<chain name="chain32">
|
||||
<then value="c,g,f"/>
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -26,7 +26,7 @@ public class SpringELSupportSpringbootTest extends BaseTest {
|
||||
//测试springEL的解析情况
|
||||
@Test
|
||||
public void testSpringELParser() {
|
||||
LiteflowResponse<DefaultContext> response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
LiteflowResponse<DefaultContext> response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
<node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
<chain name="chain11">
|
||||
<then value="a,c"/>
|
||||
<when value="b,d,e(f|g)"/>
|
||||
<then value="chain2"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
<chain name="chain12">
|
||||
<then value="c,g,f"/>
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<chain name="chain1">
|
||||
<chain name="chain21">
|
||||
<then value="a,c"/>
|
||||
<when value="b,d,e(f|g)"/>
|
||||
<then value="chain2"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain2">
|
||||
<chain name="chain32">
|
||||
<then value="c,g,f"/>
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user