mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
调整class生成
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||
import com.yomahub.liteflow.entity.executor.NodeExecutor;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
@@ -54,8 +55,18 @@ public class ComponentInitializer {
|
||||
} else {
|
||||
nodeComponent.setRetryCount(liteflowConfig.getRetryCount());
|
||||
}
|
||||
nodeComponent.setNodeExecutorClass(liteflowConfig.getNodeExecutorClass());
|
||||
nodeComponent.setNodeExecutorClass(buildNodeExecutorClass(liteflowConfig));
|
||||
|
||||
return nodeComponent;
|
||||
}
|
||||
|
||||
private Class<? extends NodeExecutor> buildNodeExecutorClass(LiteflowConfig liteflowConfig) {
|
||||
Class<?> nodeExecutorClass;
|
||||
try {
|
||||
nodeExecutorClass = Class.forName(liteflowConfig.getNodeExecutorClass());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
return (Class<? extends NodeExecutor>) nodeExecutorClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class NodeComponent{
|
||||
private Class<? extends Exception>[] retryForExceptions = new Class[]{Exception.class};
|
||||
|
||||
/** 节点执行器的类全名 */
|
||||
private String nodeExecutorClass = DefaultNodeExecutor.class.getName();
|
||||
private Class<? extends NodeExecutor> nodeExecutorClass = DefaultNodeExecutor.class;
|
||||
|
||||
|
||||
//是否结束整个流程,这个只对串行流程有效,并行流程无效
|
||||
@@ -234,11 +234,11 @@ public abstract class NodeComponent{
|
||||
this.retryForExceptions = retryForExceptions;
|
||||
}
|
||||
|
||||
public String getNodeExecutorClass() {
|
||||
public Class<? extends NodeExecutor> getNodeExecutorClass() {
|
||||
return nodeExecutorClass;
|
||||
}
|
||||
|
||||
public void setNodeExecutorClass(String nodeExecutorClass) {
|
||||
public void setNodeExecutorClass(Class<? extends NodeExecutor> nodeExecutorClass) {
|
||||
this.nodeExecutorClass = nodeExecutorClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class NodeExecutorHelper {
|
||||
* key - 节点执行器类Class全名
|
||||
* value - 节点执行器对象
|
||||
*/
|
||||
private final Map<String, NodeExecutor> nodeExecutorMap;
|
||||
private final Map<Class<? extends NodeExecutor>, NodeExecutor> nodeExecutorMap;
|
||||
|
||||
private NodeExecutorHelper() {
|
||||
nodeExecutorMap = Maps.newConcurrentMap();
|
||||
@@ -49,11 +49,11 @@ public class NodeExecutorHelper {
|
||||
* @param nodeExecutorClass : 节点执行器的Class
|
||||
* @return
|
||||
*/
|
||||
public NodeExecutor buildNodeExecutor(String nodeExecutorClass) {
|
||||
public NodeExecutor buildNodeExecutor(Class<? extends NodeExecutor> nodeExecutorClass) {
|
||||
// 高频操作-采取apache判空操作-效率高于hotool的isBlank将近3倍
|
||||
if (StringUtils.isBlank(nodeExecutorClass)) {
|
||||
if (nodeExecutorClass == null) {
|
||||
// 此处使用默认的节点执行器进行执行
|
||||
nodeExecutorClass = DefaultNodeExecutor.class.getName();
|
||||
nodeExecutorClass = DefaultNodeExecutor.class;
|
||||
}
|
||||
NodeExecutor nodeExecutor = nodeExecutorMap.get(nodeExecutorClass);
|
||||
// 此处无需使用同步锁进行同步-因为即使同时创建了两个实例,但是添加到缓存中的只会存在一个且不会存在并发问题-具体是由ConcurrentMap保证
|
||||
|
||||
@@ -12,4 +12,5 @@ liteflow.support-multiple-type=false
|
||||
liteflow.monitor.enable-log=false
|
||||
liteflow.monitor.queue-limit=200
|
||||
liteflow.monitor.delay=300000
|
||||
liteflow.monitor.period=300000
|
||||
liteflow.monitor.period=300000
|
||||
liteflow.node-executor-class=com.yomahub.liteflow.entity.executor.DefaultNodeExecutor
|
||||
Reference in New Issue
Block a user