diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index 5c832939..a61ce18f 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -9,7 +9,7 @@ com.yomahub liteflow - 2.6.9 + 2.6.11 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java index 02fa6460..9c7178dd 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.builder; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.entity.flow.Chain; import com.yomahub.liteflow.entity.flow.Condition; import com.yomahub.liteflow.entity.flow.Node; @@ -10,6 +11,7 @@ import com.yomahub.liteflow.exception.ExecutableItemNotFoundException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.parser.RegexEntity; import com.yomahub.liteflow.parser.RegexNodeEntity; +import com.yomahub.liteflow.util.SpringAware; import java.util.ArrayList; @@ -85,6 +87,13 @@ public class LiteFlowConditionBuilder { Chain chain = FlowBus.getChain(item.getId()); this.condition.getNodeList().add(chain); } else { + //元数据没有的话,从spring上下文再取一遍,这部分是为了防止标有@Lazy懒加载的组件 + NodeComponent nodeComponent = SpringAware.getBean(item.getId()); + if (ObjectUtil.isNotNull(nodeComponent)){ + FlowBus.addSpringScanNode(item.getId(), nodeComponent); + return setValue(value); + } + String errorMsg = StrUtil.format("executable node[{}] is not found!", regexEntity.getItem().getId()); throw new ExecutableItemNotFoundException(errorMsg); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 90405b96..9cf85c75 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -308,15 +308,13 @@ public class FlowExecutor { return this.execute2Resp(chainId, param, slotClazz, null, false); } - private final ArrayList> notFailExceptionList = ListUtil.toList(ChainEndException.class); - public LiteflowResponse execute2Resp(String chainId, Object param, Class slotClazz, Integer slotIndex, boolean isInnerChain) { LiteflowResponse response = new LiteflowResponse<>(); T slot = doExecute(chainId, param, slotClazz, slotIndex, isInnerChain); - if (ObjectUtil.isNotNull(slot.getException()) && !notFailExceptionList.contains(slot.getException().getClass())) { + if (ObjectUtil.isNotNull(slot.getException())) { response.setSuccess(false); response.setMessage(slot.getException().getMessage()); response.setCause(slot.getException()); @@ -374,6 +372,11 @@ public class FlowExecutor { // 执行chain chain.execute(slotIndex); + } catch (ChainEndException e) { + if (ObjectUtil.isNotNull(chain)){ + String warnMsg = StrUtil.format("[{}]:chain[{}] execute end on slot[{}]", slot.getRequestId(), chain.getChainName(), slotIndex); + LOG.warn(warnMsg); + } } catch (Exception e) { if (ObjectUtil.isNotNull(chain)){ String errMsg = StrUtil.format("[{}]:chain[{}] execute error on slot[{}]", slot.getRequestId(), chain.getChainName(), slotIndex); @@ -396,5 +399,4 @@ public class FlowExecutor { public void setLiteflowConfig(LiteflowConfig liteflowConfig) { this.liteflowConfig = liteflowConfig; } - -} +} \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index d09cae0d..745cc470 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -104,18 +104,14 @@ public abstract class NodeComponent{ public abstract void process() throws Exception; - /** - * process前置处理 - */ + //process前置处理 public void beforeProcess(String nodeId, Slot slot) { if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { ComponentScanner.cmpAroundAspect.beforeProcess(nodeId, slot); } } - /** - * process后置处理 - */ + //process后置处理 public void afterProcess(String nodeId, Slot slot) { if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { ComponentScanner.cmpAroundAspect.afterProcess(nodeId, slot); @@ -123,26 +119,17 @@ public abstract class NodeComponent{ } - /** - * 是否进入该节点 - * @return boolean - */ + //是否进入该节点 public boolean isAccess(){ return true; } - /** - * 出错是否继续执行(这个只适用于串行流程,并行节点不起作用) - * @return boolean - */ + //出错是否继续执行(这个只适用于串行流程,并行节点不起作用) public boolean isContinueOnError() { return false; } - /** - * 是否结束整个流程(不往下继续执行) - * @return boolean - */ + //是否结束整个流程(不往下继续执行) public boolean isEnd() { Boolean isEnd = isEndTL.get(); if(ObjectUtil.isNull(isEnd)){ diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/DefaultNodeExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/DefaultNodeExecutor.java index 28c64d69..3bf74567 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/DefaultNodeExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/DefaultNodeExecutor.java @@ -8,13 +8,11 @@ import com.yomahub.liteflow.entity.data.Slot; * 默认的节点执行器 * * @author sikadai - * @date 2022/1/24 17:00 + * @since 2.6.9 */ public class DefaultNodeExecutor extends NodeExecutor { @Override public void execute(NodeComponent instance) throws Exception { - Slot slot = DataBus.getSlot(instance.getSlotIndex()); - slot.setData("defaultNodeExecutor", DefaultNodeExecutor.class); super.execute(instance); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutor.java index c7b4fc35..9acc9991 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutor.java @@ -14,17 +14,12 @@ import java.util.List; * 节点执行器 - 自定的执行策略需要实现该类 * * @author sikadai - * @date 2022/1/24 17:00 + * @since 2.6.9 */ public abstract class NodeExecutor { protected final Logger LOG = LoggerFactory.getLogger(this.getClass()); - /** - * 执行器执行入口-若需要更大维度的执行方式可以重写该方法 - * - * @param instance : 执行的节点实例 - * @throws Exception - */ + //执行器执行入口-若需要更大维度的执行方式可以重写该方法 public void execute(NodeComponent instance) throws Exception { int retryCount = instance.getRetryCount(); List> forExceptions = Arrays.asList(instance.getRetryForExceptions()); @@ -52,14 +47,7 @@ public abstract class NodeExecutor { } } - /** - * 执行重试逻辑 - 子类通过实现该方法进行重试逻辑的控制 - * - * @param instance : 执行的节点实例 - * @param currentRetryCount : 当前重试的次数 - * @throws Exception - */ - + //执行重试逻辑 - 子类通过实现该方法进行重试逻辑的控制 protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { Slot slot = DataBus.getSlot(instance.getSlotIndex()); LOG.info("[{}]:component[{}] performs {} retry", slot.getRequestId(), instance.getNodeId(), currentRetryCount + 1); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutorHelper.java index 219ce6af..5c3017aa 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/executor/NodeExecutorHelper.java @@ -1,7 +1,9 @@ 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 com.yomahub.liteflow.util.SpringAware; import org.apache.commons.lang.StringUtils; import java.util.Map; @@ -10,56 +12,38 @@ import java.util.Map; * 节点执行器帮助器 * * @author sikadai - * @date 2022/1/24 19:00 + * @since 2.6.9 */ public class NodeExecutorHelper { - /** - * 此处使用Map缓存线程池信息 - * key - 节点执行器类Class全名 - * value - 节点执行器对象 - */ + //此处使用Map缓存线程池信息 private final Map, NodeExecutor> nodeExecutorMap; private NodeExecutorHelper() { nodeExecutorMap = Maps.newConcurrentMap(); } - /** - * 使用静态内部类实现单例模式 - */ + //使用静态内部类实现单例模式 private static class Holder { static final NodeExecutorHelper INSTANCE = new NodeExecutorHelper(); } - /** - * 获取帮助者的实例 - */ + //获取帮助者的实例 public static NodeExecutorHelper loadInstance() { // 外围类能直接访问内部类(不管是否是静态的)的私有变量 return Holder.INSTANCE; } - /** - * 单例模式驱动-通过调用该方法构建节点执行器 - */ - /** - * 单例模式驱动-通过调用该方法构建节点执行器 - * 若nodeExecutorClass为空,则会使用默认的节点执行器 - * - * @param nodeExecutorClass : 节点执行器的Class - * @return - */ public NodeExecutor buildNodeExecutor(Class 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); + nodeExecutor = SpringAware.registerBean(nodeExecutorClass); // 缓存 nodeExecutorMap.put(nodeExecutorClass, nodeExecutor); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/parallel/CompletableFutureTimeout.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/parallel/CompletableFutureTimeout.java index 387c0fd5..49a4510f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/parallel/CompletableFutureTimeout.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/parallel/CompletableFutureTimeout.java @@ -23,9 +23,6 @@ import java.util.function.Function; * @since 2.6.4 */ public class CompletableFutureTimeout { - /** - * Singleton delay scheduler, used only for starting and * cancelling tasks. - */ static final class Delayer { static ScheduledFuture delay(Runnable command, long delay, TimeUnit unit) { return delayer.schedule(command, delay, unit); @@ -57,17 +54,13 @@ public class CompletableFutureTimeout { return result; } - /** - * 哪个先完成 就apply哪一个结果 这是一个关键的API,exceptionally出现异常后返回默认值 - */ + //哪个先完成 就apply哪一个结果 这是一个关键的API,exceptionally出现异常后返回默认值 public static CompletableFuture completeOnTimeout(T t, CompletableFuture future, long timeout, TimeUnit unit) { final CompletableFuture timeoutFuture = timeoutAfter(timeout, unit); return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t); } - /** - * 哪个先完成 就apply哪一个结果 这是一个关键的API,不设置默认值,超时后抛出异常 - */ + //哪个先完成 就apply哪一个结果 这是一个关键的API,不设置默认值,超时后抛出异常 public static CompletableFuture orTimeout(T t, CompletableFuture future, long timeout, TimeUnit unit) { final CompletableFuture timeoutFuture = timeoutAfter(timeout, unit); return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/FlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/FlowParser.java index 1c74692e..9b50230b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/FlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/FlowParser.java @@ -27,9 +27,7 @@ public abstract class FlowParser { public abstract void parse(List contentList) throws Exception; - /** - * 根据配置的ruleSource查找匹配的资源 - */ + //根据配置的ruleSource查找匹配的资源 protected Resource[] matchRuleResources(final List pathList) throws IOException { Assert.notEmpty(pathList, "rule source must not be null"); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 2c6bec48..7a4d2078 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -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) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java index 3a8e80e4..6349f7b0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java @@ -15,18 +15,7 @@ public interface ExecutorBuilder { ExecutorService buildExecutor(); - /** - *

- * 构建默认的线程池对象 - *

- * @author sikadai - * @date 2022/1/21 23:07 - * @param corePoolSize : 核心线程池数量 - * @param maximumPoolSize : 最大线程池数量 - * @param queueCapacity : 队列的容量 - * @param threadName : 线程吃名称 - * @return java.util.concurrent.ExecutorService - */ + //构建默认的线程池对象 default ExecutorService buildDefaultExecutor(int corePoolSize, int maximumPoolSize, int queueCapacity, String threadName) { return TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(corePoolSize, maximumPoolSize, diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index 8aeafb94..2bfca78c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -53,7 +53,7 @@ public class ExecutorHelper { } /** - * 使用默认的等待时间1分钟,来关闭目标线程组。 + * *

* * @param pool 需要关闭的线程组. @@ -63,6 +63,7 @@ public class ExecutorHelper { } /** + *

* 关闭ExecutorService的线程管理者 *

* @@ -85,9 +86,7 @@ public class ExecutorHelper { } } - /** - * 构建全局默认线程池 - */ + //构建全局默认线程池 public ExecutorService buildExecutor() { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); if (!executorServiceMap.containsKey(liteflowConfig.getThreadExecutorClass())) { @@ -97,16 +96,7 @@ public class ExecutorHelper { return executorServiceMap.get(liteflowConfig.getThreadExecutorClass()); } - /** - *

- * 构建线程池执行器 - 支持多个when公用一个线程池 - *

- * - * @param threadExecutorClass : 线程池构建者的Class全类名 - * @return java.util.concurrent.ExecutorService - * @author sikadai - * @date 2022/1/21 23:00 - */ + //构建线程池执行器 - 支持多个when公用一个线程池 public ExecutorService buildExecutor(String threadExecutorClass) { if (StrUtil.isBlank(threadExecutorClass)) { return buildExecutor(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SpringAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SpringAware.java index 911df22c..0131a96b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SpringAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SpringAware.java @@ -1,6 +1,7 @@ package com.yomahub.liteflow.util; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReflectUtil; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.BeanDefinition; @@ -47,11 +48,15 @@ public class SpringAware implements ApplicationContextAware { } public static T registerBean(String beanName, Class c) { - DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory(); - BeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClassName(c.getName()); - beanFactory.registerBeanDefinition(beanName, beanDefinition); - return getBean(beanName); + try{ + DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory(); + BeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClassName(c.getName()); + beanFactory.registerBeanDefinition(beanName, beanDefinition); + return getBean(beanName); + }catch (Exception e){ + return ReflectUtil.newInstance(c); + } } public static T registerBean(Class c) { diff --git a/liteflow-script-common/pom.xml b/liteflow-script-common/pom.xml index 545a26e8..d5fb52f7 100644 --- a/liteflow-script-common/pom.xml +++ b/liteflow-script-common/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-script-groovy/pom.xml b/liteflow-script-groovy/pom.xml index cb4e2ba3..7597a4f8 100644 --- a/liteflow-script-groovy/pom.xml +++ b/liteflow-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-script-qlexpress/pom.xml b/liteflow-script-qlexpress/pom.xml index 5c4f57df..a479b13c 100644 --- a/liteflow-script-qlexpress/pom.xml +++ b/liteflow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml index 0c4b6754..05057494 100644 --- a/liteflow-spring-boot-starter/pom.xml +++ b/liteflow-spring-boot-starter/pom.xml @@ -10,7 +10,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index b5b9a788..b9ef68db 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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", diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 3140e99e..01228a83 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -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 \ No newline at end of file diff --git a/liteflow-testcase-script-groovy/pom.xml b/liteflow-testcase-script-groovy/pom.xml index c5417c48..14952743 100644 --- a/liteflow-testcase-script-groovy/pom.xml +++ b/liteflow-testcase-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-testcase-script-qlexpress/pom.xml b/liteflow-testcase-script-qlexpress/pom.xml index f4937ec9..f9f15c65 100644 --- a/liteflow-testcase-script-qlexpress/pom.xml +++ b/liteflow-testcase-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-testcase-springboot/pom.xml b/liteflow-testcase-springboot/pom.xml index 1096433c..dc0c6b50 100644 --- a/liteflow-testcase-springboot/pom.xml +++ b/liteflow-testcase-springboot/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java new file mode 100644 index 00000000..a1e472e6 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.lazy; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ZipUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"}) +public class LazySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java new file mode 100644 index 00000000..9d3dacbc --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 00000000..13bfe672 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 00000000..3f45e86a --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java new file mode 100644 index 00000000..84b60247 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义默认的节点执行器 + */ +public class CustomerDefaultNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + slot.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java index b83bcb51..03940dea 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java @@ -35,10 +35,10 @@ public class LiteflowNodeExecutorSpringbootTest extends BaseTest { // 默认执行器测试 @Test - public void testDefaultExecutor() { + public void testCustomerDefaultNodeExecutor() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(DefaultNodeExecutor.class, response.getSlot().getData("defaultNodeExecutor")); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); Assert.assertEquals("a", response.getSlot().getExecuteStepStr()); } @@ -47,7 +47,7 @@ public class LiteflowNodeExecutorSpringbootTest extends BaseTest { public void testDefaultExecutorForRetry() { LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(DefaultNodeExecutor.class, response.getSlot().getData("defaultNodeExecutor")); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); Assert.assertEquals("b==>b==>b", response.getSlot().getExecuteStepStr()); } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index 6762d18a..f7ad8f77 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -10,6 +10,7 @@ package com.yomahub.liteflow.test.nodeExecutor.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; @LiteflowComponent("c") @@ -22,7 +23,7 @@ public class CCmp extends NodeComponent { } @Override - public String getNodeExecutorClass() { - return CustomerNodeExecutor.class.getName(); + public Class getNodeExecutorClass() { + return CustomerNodeExecutor.class; } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index d60135a0..b80d2e0a 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -1,6 +1,7 @@ /** *

Title: liteflow

*

Description: 轻量级的组件式流程框架

+ * * @author Bryan.Zhang * @email weenyc31@163.com * @Date 2020/4/1 @@ -10,21 +11,21 @@ package com.yomahub.liteflow.test.nodeExecutor.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; +import com.yomahub.liteflow.entity.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; @LiteflowComponent("d") @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) public class DCmp extends NodeComponent { - @Override - public void process() { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } - @Override - public String getNodeExecutorClass() { - return CustomerNodeExecutorAndCustomRetry.class.getName(); - } + @Override + public Class getNodeExecutorClass() { + return CustomerNodeExecutorAndCustomRetry.class; + } } diff --git a/liteflow-testcase-springboot/src/test/resources/lazy/application.properties b/liteflow-testcase-springboot/src/test/resources/lazy/application.properties new file mode 100644 index 00000000..372a320c --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/lazy/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lazy/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml b/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/nodeExecutor/application.properties b/liteflow-testcase-springboot/src/test/resources/nodeExecutor/application.properties index 62a0d3a9..b2ca1d08 100644 --- a/liteflow-testcase-springboot/src/test/resources/nodeExecutor/application.properties +++ b/liteflow-testcase-springboot/src/test/resources/nodeExecutor/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=nodeExecutor/flow.xml liteflow.retry-count=3 liteflow.slot-size=512 -liteflow.node-executor-class=com.yomahub.liteflow.entity.executor.DefaultNodeExecutor \ No newline at end of file +liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor \ No newline at end of file diff --git a/liteflow-testcase-springnative/pom.xml b/liteflow-testcase-springnative/pom.xml index c82bcd0c..e48b9e42 100644 --- a/liteflow-testcase-springnative/pom.xml +++ b/liteflow-testcase-springnative/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.9 + 2.6.11 4.0.0 diff --git a/pom.xml b/pom.xml index 5c167f16..0bbe10c1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yomahub liteflow pom - 2.6.9 + 2.6.11 liteflow a lightweight and practical micro-process framework https://github.com/bryan31/liteflow