feature #IAY66T 修改配置项名称

This commit is contained in:
DaleLee
2025-07-26 23:25:09 +08:00
parent f062ada31b
commit 7714ddf37e
38 changed files with 166 additions and 153 deletions

View File

@@ -23,7 +23,7 @@ import com.yomahub.liteflow.exception.*;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.lifecycle.PostProcessChainExecuteLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.element.Rollbackable;
@@ -106,9 +106,9 @@ public class FlowExecutor {
}
// 规则缓存
if (isStart && liteflowConfig.getRuleCacheEnabled()) {
if (isStart && liteflowConfig.getChainCacheEnabled()) {
// 放到解析节点后,是因为要根据节点数量判断缓存大小设置是否合理
initRuleCache();
initChainCache();
}
String ruleSource = liteflowConfig.getRuleSource();
@@ -239,8 +239,8 @@ public class FlowExecutor {
}
// 初始化或reload时评估规则缓存容量大小
if (liteflowConfig.getRuleCacheEnabled()) {
evaluateRuleCacheCapacity();
if (liteflowConfig.getChainCacheEnabled()) {
evaluateChainCacheCapacity();
}
}
@@ -678,40 +678,42 @@ public class FlowExecutor {
return resultSlotList;
}
private void initRuleCache() {
private void initChainCache() {
// 启动chain缓存必须使用 PARSE_ONE_ON_FIRST_EXEC 模式
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
LOG.warn("The parse mode is not PARSE_ONE_ON_FIRST_EXE, so the chain cache cannot be enabled.");
return;
}
// 容量不能小于等于0
Integer capacity = liteflowConfig.getRuleCacheCapacity();
Integer capacity = liteflowConfig.getChainCacheCapacity();
if (ObjectUtil.isNull(capacity) || capacity <= 0) {
throw new ConfigErrorException("The rule cache capacity must be greater than 0");
throw new ConfigErrorException("The chain cache capacity must be greater than 0");
}
// 添加规则缓存生命周期
List<PostProcessChainExecuteLifeCycle> lifeCycleList = LifeCycleHolder.getPostProcessChainExecuteLifeCycleList();
boolean exist = lifeCycleList.stream()
.anyMatch(lifeCycle -> lifeCycle instanceof RuleCacheLifeCycle);
.anyMatch(lifeCycle -> lifeCycle instanceof ChainCacheLifeCycle);
if (!exist) {
boolean success = RuleCacheLifeCycle.initIfAbsent(capacity);
boolean success = ChainCacheLifeCycle.initIfAbsent(capacity);
if (!success) {
throw new FlowExecutorNotInitException("Initialization of RuleCacheLifeCycle failed");
throw new FlowExecutorNotInitException("Initialization of ChainCacheLifeCycle failed");
}
LifeCycleHolder.addLifeCycle(RuleCacheLifeCycle.getLifeCycle());
}
// 执行时才解析chain
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
liteflowConfig.setParseMode(ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC);
LOG.warn("The rule cache is enabled, so the parse mode is forcibly set to PARSE_ONE_ON_FIRST_EXE.");
LifeCycleHolder.addLifeCycle(ChainCacheLifeCycle.getLifeCycle());
}
}
// 评估规则缓存容量
private void evaluateRuleCacheCapacity() {
Integer capacity = liteflowConfig.getRuleCacheCapacity();
private void evaluateChainCacheCapacity() {
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
return;
}
Integer capacity = liteflowConfig.getChainCacheCapacity();
// 容量不足chain总数的30%给予警告
int chainNum = FlowBus.getChainMap().size();
double threshold = chainNum * 0.3;
if (capacity < threshold) {
LOG.warn("The rule cache capacity {} is too small, the current total number of chains is {}, "
LOG.warn("The chain cache capacity {} is too small, the current total number of chains is {}, "
+"it is recommended to be greater than 30% of the number of chains", capacity, chainNum);
}
}

View File

@@ -17,11 +17,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
/**
* Chain 缓存处理
* Chain 缓存生命周期
* @author DaleLee
* @since 2.13.3
*/
public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
public class ChainCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
/**
* 缓存
*/
@@ -30,9 +30,9 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
/**
* 实例
*/
private static RuleCacheLifeCycle INSTANCE;
private static ChainCacheLifeCycle INSTANCE;
private RuleCacheLifeCycle(int capacity) {
private ChainCacheLifeCycle(int capacity) {
this.cache = Caffeine.newBuilder()
.maximumSize(capacity)
.evictionListener(new ChainRemovalListener())
@@ -149,7 +149,7 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
*/
public synchronized static boolean initIfAbsent(int capacity) {
if (ObjectUtil.isNull(INSTANCE)) {
INSTANCE = new RuleCacheLifeCycle(capacity);
INSTANCE = new ChainCacheLifeCycle(capacity);
return true;
}
return false;
@@ -159,7 +159,7 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
* 获取生命周期实例
* @return lifeCycle
*/
public static RuleCacheLifeCycle getLifeCycle() {
public static ChainCacheLifeCycle getLifeCycle() {
return INSTANCE;
}
}

View File

@@ -116,11 +116,11 @@ public class LiteflowConfig {
// instance id 生成器
private String instanceIdGeneratorClass;
// 是否启用规则缓存
private Boolean ruleCacheEnabled;
// 是否启用chain缓存
private Boolean chainCacheEnabled;
// 规则缓存容量
private Integer ruleCacheCapacity;
// chain缓存容量
private Integer chainCacheCapacity;
public Boolean getEnableMonitorFile() {
return enableMonitorFile;
@@ -502,22 +502,25 @@ public class LiteflowConfig {
this.instanceIdGeneratorClass = instanceIdGeneratorClass;
}
public Boolean getRuleCacheEnabled() {
if (ObjectUtil.isNull(ruleCacheEnabled)) {
public Boolean getChainCacheEnabled() {
if (ObjectUtil.isNull(chainCacheEnabled)) {
return Boolean.FALSE;
}
return ruleCacheEnabled;
return chainCacheEnabled;
}
public void setRuleCacheEnabled(Boolean ruleCacheEnabled) {
this.ruleCacheEnabled = ruleCacheEnabled;
public void setChainCacheEnabled(Boolean chainCacheEnabled) {
this.chainCacheEnabled = chainCacheEnabled;
}
public Integer getRuleCacheCapacity() {
return ruleCacheCapacity;
public Integer getChainCacheCapacity() {
if (ObjectUtil.isNull(chainCacheCapacity)) {
return 10000;
}
return chainCacheCapacity;
}
public void setRuleCacheCapacity(Integer ruleCacheCapacity) {
this.ruleCacheCapacity = ruleCacheCapacity;
public void setChainCacheCapacity(Integer chainCacheCapacity) {
this.chainCacheCapacity = chainCacheCapacity;
}
}