将chain中的pre节点剥离至flowExecutor

This commit is contained in:
daiqi
2022-03-11 21:55:52 +08:00
parent 3fbcb61e7e
commit 072bc9c014
2 changed files with 22 additions and 8 deletions

View File

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

View File

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