配置统一化,优化配置阶段代码

This commit is contained in:
bryan31
2021-03-19 02:02:51 +08:00
parent 65a217fcb5
commit 784ff51505
13 changed files with 292 additions and 140 deletions

View File

@@ -1,9 +1,11 @@
package com.yomahub.liteflow.springboot;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DataBus;
import com.yomahub.liteflow.monitor.MonitorBus;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.spring.ComponentScaner;
import com.yomahub.liteflow.util.SpringAware;
import org.apache.commons.lang3.StringUtils;
@@ -25,19 +27,28 @@ import java.util.List;
public class LiteflowAutoConfiguration {
@Bean
public ComponentScaner componentScaner(){
public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty){
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource(property.getRuleSource());
liteflowConfig.setSlotSize(property.getSlotSize());
liteflowConfig.setWhenMaxWaitSecond(property.getWhenMaxWaitSecond());
liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog());
liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit());
liteflowConfig.setDelay(liteflowMonitorProperty.getDelay());
liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod());
return liteflowConfig;
}
@Bean
public ComponentScaner componentScaner(LiteflowConfig liteflowConfig){
return new ComponentScaner();
}
@Bean
public FlowExecutor flowExecutor(LiteflowProperty property){
if(StringUtils.isNotBlank(property.getRuleSource())){
List<String> ruleList = Lists.newArrayList(property.getRuleSource().split(","));
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig){
if(StrUtil.isNotBlank(liteflowConfig.getRuleSource())){
FlowExecutor flowExecutor = new FlowExecutor();
flowExecutor.setRulePath(ruleList);
DataBus.setSlotSize(property.getSlotSize());
flowExecutor.setLiteflowConfig(liteflowConfig);
return flowExecutor;
}else{
return null;
@@ -55,7 +66,7 @@ public class LiteflowAutoConfiguration {
}
@Bean
public MonitorBus monitorBus(LiteflowMonitorProperty property){
return new MonitorBus(property.isEnableLog(), property.getQueueLimit(), property.getDelay(), property.getPeriod());
public MonitorBus monitorBus(LiteflowConfig liteflowConfig){
return new MonitorBus(liteflowConfig);
}
}

View File

@@ -9,6 +9,8 @@ public class LiteflowProperty {
private int slotSize;
private int whenMaxWaitSecond;
public String getRuleSource() {
return ruleSource;
}
@@ -24,4 +26,12 @@ public class LiteflowProperty {
public void setSlotSize(int slotSize) {
this.slotSize = slotSize;
}
public int getWhenMaxWaitSecond() {
return whenMaxWaitSecond;
}
public void setWhenMaxWaitSecond(int whenMaxWaitSecond) {
this.whenMaxWaitSecond = whenMaxWaitSecond;
}
}