enhancement #I4T9I1 增加可以自己构造Node执行器的扩展

This commit is contained in:
bryan31
2022-02-11 11:11:25 +08:00
parent 553d821431
commit 6ee5429cea
4 changed files with 17 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.entity.executor;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
@@ -50,14 +51,14 @@ public class NodeExecutorHelper {
* @return
*/
public NodeExecutor buildNodeExecutor(Class<? extends NodeExecutor> nodeExecutorClass) {
// 高频操作-采取apache判空操作-效率高于hotool的isBlank将近3倍
if (nodeExecutorClass == null) {
// 高频操作-采取apache判空操作-效率高于hutool的isBlank将近3倍
if (ObjectUtil.isNull(nodeExecutorClass)) {
// 此处使用默认的节点执行器进行执行
nodeExecutorClass = DefaultNodeExecutor.class;
}
NodeExecutor nodeExecutor = nodeExecutorMap.get(nodeExecutorClass);
// 此处无需使用同步锁进行同步-因为即使同时创建了两个实例,但是添加到缓存中的只会存在一个且不会存在并发问题-具体是由ConcurrentMap保证
if (nodeExecutor == null) {
if (ObjectUtil.isNull(nodeExecutor)) {
// 获取重试执行器实例
nodeExecutor = ReflectUtil.newInstance(nodeExecutorClass);
// 缓存

View File

@@ -265,7 +265,11 @@ public class LiteflowConfig {
}
public String getNodeExecutorClass() {
return nodeExecutorClass;
if (StrUtil.isBlank(nodeExecutorClass)){
return "com.yomahub.liteflow.entity.executor.DefaultNodeExecutor";
}else{
return nodeExecutorClass;
}
}
public void setNodeExecutorClass(String nodeExecutorClass) {

View File

@@ -78,6 +78,13 @@
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty",
"defaultValue": 0
},
{
"name": "liteflow.node-executor-class",
"type": "java.lang.String",
"description": "Executor class of node.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty",
"defaultValue": 0
},
{
"name": "liteflow.monitor.enable-log",
"type": "java.lang.Boolean",

View File

@@ -9,8 +9,8 @@ liteflow.when-queue-limit=512
liteflow.parse-on-start=true
liteflow.retry-count=0
liteflow.support-multiple-type=false
liteflow.node-executor-class=com.yomahub.liteflow.entity.executor.DefaultNodeExecutor
liteflow.monitor.enable-log=false
liteflow.monitor.queue-limit=200
liteflow.monitor.delay=300000
liteflow.monitor.period=300000
liteflow.node-executor-class=com.yomahub.liteflow.entity.executor.DefaultNodeExecutor