mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
feature #I4GS07 代码动态组件装配的特性
This commit is contained in:
@@ -17,12 +17,18 @@ public class LiteFlowChainBuilder {
|
||||
|
||||
private Chain chain;
|
||||
|
||||
//声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载
|
||||
//虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List
|
||||
//所以在这里做一个缓存,等conditionList全部build完毕后,再去一次性替换chain里面的conditionList
|
||||
private final List<Condition> conditionList;
|
||||
|
||||
public static LiteFlowChainBuilder createChain(){
|
||||
return new LiteFlowChainBuilder();
|
||||
}
|
||||
|
||||
public LiteFlowChainBuilder(){
|
||||
chain = new Chain();
|
||||
conditionList = new ArrayList<>();
|
||||
}
|
||||
|
||||
//在parser中chain的build是2段式的,因为涉及到依赖问题,以前是递归parser
|
||||
@@ -44,6 +50,7 @@ public class LiteFlowChainBuilder {
|
||||
}
|
||||
|
||||
public void build(){
|
||||
this.chain.setConditionList(this.conditionList);
|
||||
FlowBus.addChain(this.chain);
|
||||
}
|
||||
|
||||
@@ -52,29 +59,29 @@ public class LiteFlowChainBuilder {
|
||||
//对于then来说,相邻的2个then会合并成一个condition
|
||||
//对于when来说,相同组的when会合并成一个condition,不同组的when还是会拆开
|
||||
if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_PRE)) {
|
||||
this.chain.getConditionList().add(new PreCondition(condition));
|
||||
this.conditionList.add(new PreCondition(condition));
|
||||
} else if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_THEN)) {
|
||||
if (this.chain.getConditionList().size() >= 1 &&
|
||||
CollectionUtil.getLast(this.chain.getConditionList()) instanceof ThenCondition) {
|
||||
CollectionUtil.getLast(this.chain.getConditionList()).getNodeList().addAll(condition.getNodeList());
|
||||
if (this.conditionList.size() >= 1 &&
|
||||
CollectionUtil.getLast(this.conditionList) instanceof ThenCondition) {
|
||||
CollectionUtil.getLast(this.conditionList).getNodeList().addAll(condition.getNodeList());
|
||||
} else {
|
||||
this.chain.getConditionList().add(new ThenCondition(condition));
|
||||
this.conditionList.add(new ThenCondition(condition));
|
||||
}
|
||||
} else if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_WHEN)) {
|
||||
if (this.chain.getConditionList().size() > 1 &&
|
||||
CollectionUtil.getLast(this.chain.getConditionList()) instanceof WhenCondition &&
|
||||
CollectionUtil.getLast(this.chain.getConditionList()).getGroup().equals(condition.getGroup())) {
|
||||
CollectionUtil.getLast(this.chain.getConditionList()).getNodeList().addAll(condition.getNodeList());
|
||||
if (this.conditionList.size() > 1 &&
|
||||
CollectionUtil.getLast(this.conditionList) instanceof WhenCondition &&
|
||||
CollectionUtil.getLast(this.conditionList).getGroup().equals(condition.getGroup())) {
|
||||
CollectionUtil.getLast(this.conditionList).getNodeList().addAll(condition.getNodeList());
|
||||
} else {
|
||||
this.chain.getConditionList().add(new WhenCondition(condition));
|
||||
this.conditionList.add(new WhenCondition(condition));
|
||||
}
|
||||
} else if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_FINALLY)) {
|
||||
this.chain.getConditionList().add(new FinallyCondition(condition));
|
||||
this.conditionList.add(new FinallyCondition(condition));
|
||||
}
|
||||
|
||||
//每一次build之后,对conditionList进行排序,pre最前面,finally最后
|
||||
//这里为什么要排序,因为在声明的时候,哪怕有人不把pre放最前,finally放最后,但最终也要确保是正确的顺序
|
||||
CollectionUtil.sort(this.chain.getConditionList(), (o1, o2) -> {
|
||||
CollectionUtil.sort(this.conditionList, (o1, o2) -> {
|
||||
if (o1.getConditionType().equals(ConditionTypeEnum.TYPE_PRE) || o2.getConditionType().equals(ConditionTypeEnum.TYPE_FINALLY)){
|
||||
return -1;
|
||||
} else if (o2.getConditionType().equals(ConditionTypeEnum.TYPE_PRE) || o1.getConditionType().equals(ConditionTypeEnum.TYPE_FINALLY)){
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptSpiException;
|
||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||
import com.yomahub.liteflow.util.SpringAware;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
@@ -61,14 +62,18 @@ public class FlowBus {
|
||||
return chainMap.get(id);
|
||||
}
|
||||
|
||||
public static void addChain(Chain chain) {
|
||||
if (chainMap.containsKey(chain.getChainName()) && CollectionUtil.isEmpty(chain.getConditionList())){
|
||||
chainMap.get(chain.getChainName()).setConditionList(chain.getConditionList());
|
||||
}else{
|
||||
chainMap.put(chain.getChainName(), chain);
|
||||
//这一方法主要用于第一阶段chain的预装载
|
||||
public static void addChain(String chainName){
|
||||
if (!chainMap.containsKey(chainName)){
|
||||
chainMap.put(chainName, new Chain(chainName));
|
||||
}
|
||||
}
|
||||
|
||||
//这个方法主要用于第二阶段的替换chain
|
||||
public static void addChain(Chain chain) {
|
||||
chainMap.put(chain.getChainName(), chain);
|
||||
}
|
||||
|
||||
public static boolean containChain(String chainId) {
|
||||
return chainMap.containsKey(chainId);
|
||||
}
|
||||
@@ -172,7 +177,6 @@ public class FlowBus {
|
||||
}catch (ScriptSpiException ignored){}
|
||||
}
|
||||
|
||||
//目前这种方式刷新不完全平滑
|
||||
public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception {
|
||||
if (type.equals(FlowParserTypeEnum.TYPE_XML)) {
|
||||
new LocalXmlFlowParser().parse(content);
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class JsonFlowParser extends FlowParser {
|
||||
//先在元数据里放上chain
|
||||
chainArray.forEach(o -> {
|
||||
JSONObject innerJsonObject = (JSONObject)o;
|
||||
FlowBus.addChain(new Chain(innerJsonObject.getString("name")));
|
||||
FlowBus.addChain(innerJsonObject.getString("name"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public abstract class XmlFlowParser extends FlowParser {
|
||||
List<Element> chainList = document.getRootElement().elements("chain");
|
||||
|
||||
//先在元数据里放上chain
|
||||
chainList.forEach(e -> FlowBus.addChain(new Chain(e.attributeValue("name"))));
|
||||
chainList.forEach(e -> FlowBus.addChain(e.attributeValue("name")));
|
||||
});
|
||||
|
||||
for (Document document : documentList) {
|
||||
|
||||
Reference in New Issue
Block a user