bug FlowExecutor.execute2RespWithEL 封装异常结果,尽量避免异常直接抛出;移除 LiteFlowChainELBuilder.setElMd5 方法;调整 elMd5Map 存储结构

This commit is contained in:
luoyi
2025-07-09 18:34:48 +08:00
parent e56960cb8e
commit bb9ca71a80
4 changed files with 30 additions and 31 deletions

View File

@@ -275,11 +275,6 @@ public class LiteFlowChainELBuilder {
}
}
public LiteFlowChainELBuilder setElMd5(String md5) {
this.chain.setElMd5(md5);
return this;
}
public void build() {
this.chain.setRouteItem(this.route);
this.chain.setConditionList(this.conditionList);

View File

@@ -266,9 +266,8 @@ public class FlowExecutor {
*
* @param elStr EL 表达式
* @return LiteflowResponse
* @throws ELParseException
*/
public LiteflowResponse execute2RespWithEL(String elStr) throws Exception {
public LiteflowResponse execute2RespWithEL(String elStr) {
return this.execute2RespWithEL(elStr, null, null, DefaultContext.class);
}
@@ -278,9 +277,8 @@ public class FlowExecutor {
* @param elStr EL 表达式
* @param param 入参
* @return LiteflowResponse
* @throws ELParseException
*/
public LiteflowResponse execute2RespWithEL(String elStr, Object param) throws Exception {
public LiteflowResponse execute2RespWithEL(String elStr, Object param) {
return this.execute2RespWithEL(elStr, param, null, DefaultContext.class);
}
@@ -292,9 +290,8 @@ public class FlowExecutor {
* @param requestId 请求 ID
* @param contextBeanClazzArray 上下文 Class
* @return LiteflowResponse
* @throws ELParseException
*/
public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class<?>... contextBeanClazzArray) throws Exception {
public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class<?>... contextBeanClazzArray) {
return this.execute2RespWithEL(elStr, param, requestId, contextBeanClazzArray, null);
}
@@ -306,9 +303,8 @@ public class FlowExecutor {
* @param requestId 请求 ID
* @param contextBeanArray 上下文对象
* @return LiteflowResponse
* @throws ELParseException
*/
public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Object... contextBeanArray) throws Exception {
public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Object... contextBeanArray) {
return this.execute2RespWithEL(elStr, param, requestId, null, contextBeanArray);
}
@@ -321,9 +317,8 @@ public class FlowExecutor {
* @param contextBeanClazzArray 上下文 Class 数组
* @param contextBeanArray 上下文对象数组
* @return LiteflowResponse
* @throws ELParseException
*/
private LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class<?>[] contextBeanClazzArray, Object[] contextBeanArray) throws Exception {
private LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class<?>[] contextBeanClazzArray, Object[] contextBeanArray) {
// 规范化 el 表达式
String normalizedEl = ElRegexUtil.normalize(elStr);
@@ -332,7 +327,7 @@ public class FlowExecutor {
if (!validationResp.isSuccess()) {
// 实际封装的是 ELParseException 类型
throw validationResp.getCause();
return LiteflowResponse.newMainResponse(validationResp.getCause());
}
// 计算 EL MD5 值,并检查对应的 chain 是否已加载到内存中
@@ -346,7 +341,6 @@ public class FlowExecutor {
LiteFlowChainELBuilder.createChain()
.setChainId(chainId)
.setEL(normalizedEl)
.setElMd5(elMd5)
.build();
}

View File

@@ -45,6 +45,7 @@ import com.yomahub.liteflow.spi.holder.DeclComponentParserHolder;
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@@ -81,7 +82,7 @@ public class FlowBus {
chainMap = new CopyOnWriteHashMap<>();
nodeMap = new CopyOnWriteHashMap<>();
fallbackNodeMap = new CopyOnWriteHashMap<>();
elMd5Map = new CopyOnWriteHashMap<>();
elMd5Map = new ConcurrentHashMap<>();
}
}

View File

@@ -5,9 +5,10 @@ import com.yomahub.liteflow.exception.LiteFlowException;
import com.yomahub.liteflow.flow.entity.CmpStep;
import com.yomahub.liteflow.slot.Slot;
import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
/**
* 执行结果封装类
@@ -35,6 +36,12 @@ public class LiteflowResponse {
return newResponse(slot, slot.getException());
}
public static LiteflowResponse newMainResponse(Exception exception) {
LiteflowResponse response = new LiteflowResponse();
response.setExceptionParams(exception);
return response;
}
public static LiteflowResponse newInnerResponse(String chainId, Slot slot) {
return newResponse(slot, slot.getSubException(chainId));
}
@@ -42,20 +49,22 @@ public class LiteflowResponse {
private static LiteflowResponse newResponse(Slot slot, Exception e) {
LiteflowResponse response = new LiteflowResponse();
response.setChainId(slot.getChainId());
if (e != null) {
response.setSuccess(false);
response.setCause(e);
response.setMessage(response.getCause().getMessage());
response.setCode(response.getCause() instanceof LiteFlowException
? ((LiteFlowException) response.getCause()).getCode() : null);
}
else {
response.setSuccess(true);
}
response.setExceptionParams(e);
response.setSlot(slot);
return response;
}
private void setExceptionParams(Exception exception) {
if (exception != null) {
this.setSuccess(false);
this.setCause(exception);
this.setMessage(exception.getMessage());
this.setCode(exception instanceof LiteFlowException ? ((LiteFlowException) exception).getCode() : null);
} else {
this.setSuccess(true);
}
}
public boolean isSuccess() {
return success;
}