mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
将chain中的pre节点剥离至flowExecutor
This commit is contained in:
@@ -383,7 +383,8 @@ public class FlowExecutor {
|
|||||||
String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), chainId);
|
String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), chainId);
|
||||||
throw new ChainNotFoundException(errorMsg);
|
throw new ChainNotFoundException(errorMsg);
|
||||||
}
|
}
|
||||||
|
// 执行前置
|
||||||
|
chain.executePre(slotIndex);
|
||||||
// 执行chain
|
// 执行chain
|
||||||
chain.execute(slotIndex);
|
chain.execute(slotIndex);
|
||||||
} catch (ChainEndException e) {
|
} catch (ChainEndException e) {
|
||||||
|
|||||||
@@ -80,11 +80,7 @@ public class Chain implements Executable {
|
|||||||
throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
|
throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
|
||||||
}
|
}
|
||||||
for (Condition condition : conditionList) {
|
for (Condition condition : conditionList) {
|
||||||
if (condition instanceof PreCondition){
|
if (condition instanceof ThenCondition) {
|
||||||
for (Executable executableItem : condition.getNodeList()) {
|
|
||||||
executableItem.execute(slotIndex);
|
|
||||||
}
|
|
||||||
} else if (condition instanceof ThenCondition) {
|
|
||||||
for (Executable executableItem : condition.getNodeList()) {
|
for (Executable executableItem : condition.getNodeList()) {
|
||||||
executableItem.execute(slotIndex);
|
executableItem.execute(slotIndex);
|
||||||
}
|
}
|
||||||
@@ -94,10 +90,20 @@ public class Chain implements Executable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行pre节点
|
||||||
|
public void executePre(Integer slotIndex) throws Exception {
|
||||||
|
//先把pre的节点过滤出来
|
||||||
|
List<Condition> preConditionList =filterCondition(ConditionTypeEnum.TYPE_PRE);
|
||||||
|
for (Condition finallyCondition : preConditionList){
|
||||||
|
for(Executable executableItem : finallyCondition.getNodeList()){
|
||||||
|
executableItem.execute(slotIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void executeFinally(Integer slotIndex) throws Exception {
|
public void executeFinally(Integer slotIndex) throws Exception {
|
||||||
//先把finally的节点过滤出来
|
//先把finally的节点过滤出来
|
||||||
List<Condition> finallyConditionList = conditionList.stream().filter(condition ->
|
List<Condition> finallyConditionList =filterCondition(ConditionTypeEnum.TYPE_FINALLY);
|
||||||
condition.getConditionType().equals(ConditionTypeEnum.TYPE_FINALLY)).collect(Collectors.toList());
|
|
||||||
for (Condition finallyCondition : finallyConditionList){
|
for (Condition finallyCondition : finallyConditionList){
|
||||||
for(Executable executableItem : finallyCondition.getNodeList()){
|
for(Executable executableItem : finallyCondition.getNodeList()){
|
||||||
executableItem.execute(slotIndex);
|
executableItem.execute(slotIndex);
|
||||||
@@ -105,6 +111,13 @@ public class Chain implements Executable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据节点condition类型过去出节点列表
|
||||||
|
private List<Condition> filterCondition(ConditionTypeEnum conditionTypeEnum) {
|
||||||
|
assert conditionTypeEnum != null;
|
||||||
|
return conditionList.stream().filter(condition ->
|
||||||
|
condition.getConditionType().equals(conditionTypeEnum)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExecuteTypeEnum getExecuteType() {
|
public ExecuteTypeEnum getExecuteType() {
|
||||||
return ExecuteTypeEnum.CHAIN;
|
return ExecuteTypeEnum.CHAIN;
|
||||||
|
|||||||
Reference in New Issue
Block a user