Merge branch 'v2.6.11' of https://gitee.com/sikadai/liteFlow into v2.6.11
This commit is contained in:
commit
61f9336a6e
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -308,15 +308,13 @@ public class FlowExecutor {
|
|||
return this.execute2Resp(chainId, param, slotClazz, null, false);
|
||||
}
|
||||
|
||||
private final ArrayList<Class<? extends Exception>> notFailExceptionList = ListUtil.toList(ChainEndException.class);
|
||||
|
||||
public <T extends Slot> LiteflowResponse<T> execute2Resp(String chainId, Object param, Class<T> slotClazz, Integer slotIndex,
|
||||
boolean isInnerChain) {
|
||||
LiteflowResponse<T> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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)){
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Class<? extends Exception>> 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);
|
||||
|
|
|
@ -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<Class<? extends NodeExecutor>, 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<? 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);
|
||||
nodeExecutor = SpringAware.registerBean(nodeExecutorClass);
|
||||
// 缓存
|
||||
nodeExecutorMap.put(nodeExecutorClass, nodeExecutor);
|
||||
}
|
||||
|
|
|
@ -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 <T> CompletableFuture<T> completeOnTimeout(T t, CompletableFuture<T> future, long timeout, TimeUnit unit) {
|
||||
final CompletableFuture<T> timeoutFuture = timeoutAfter(timeout, unit);
|
||||
return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 哪个先完成 就apply哪一个结果 这是一个关键的API,不设置默认值,超时后抛出异常
|
||||
*/
|
||||
//哪个先完成 就apply哪一个结果 这是一个关键的API,不设置默认值,超时后抛出异常
|
||||
public static <T> CompletableFuture<T> orTimeout(T t, CompletableFuture<T> future, long timeout, TimeUnit unit) {
|
||||
final CompletableFuture<T> timeoutFuture = timeoutAfter(timeout, unit);
|
||||
return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t);
|
||||
|
|
|
@ -27,9 +27,7 @@ public abstract class FlowParser {
|
|||
|
||||
public abstract void parse(List<String> contentList) throws Exception;
|
||||
|
||||
/**
|
||||
* 根据配置的ruleSource查找匹配的资源
|
||||
*/
|
||||
//根据配置的ruleSource查找匹配的资源
|
||||
protected Resource[] matchRuleResources(final List<String> pathList) throws IOException {
|
||||
Assert.notEmpty(pathList, "rule source must not be null");
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -15,18 +15,7 @@ public interface ExecutorBuilder {
|
|||
|
||||
ExecutorService buildExecutor();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 构建默认的线程池对象
|
||||
* </p>
|
||||
* @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,
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ExecutorHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* 使用默认的等待时间1分钟,来关闭目标线程组。
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* @param pool 需要关闭的线程组.
|
||||
|
@ -63,6 +63,7 @@ public class ExecutorHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 关闭ExecutorService的线程管理者
|
||||
* <p>
|
||||
*
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 构建线程池执行器 - 支持多个when公用一个线程池
|
||||
* </p>
|
||||
*
|
||||
* @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();
|
||||
|
|
|
@ -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> T registerBean(String beanName, Class<T> 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> T registerBean(Class<T> c) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -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<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @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!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -35,10 +35,10 @@ public class LiteflowNodeExecutorSpringbootTest extends BaseTest {
|
|||
|
||||
// 默认执行器测试
|
||||
@Test
|
||||
public void testDefaultExecutor() {
|
||||
public void testCustomerDefaultNodeExecutor() {
|
||||
LiteflowResponse<DefaultSlot> 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<DefaultSlot> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<? extends NodeExecutor> getNodeExecutorClass() {
|
||||
return CustomerNodeExecutor.class;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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<? extends NodeExecutor> getNodeExecutorClass() {
|
||||
return CustomerNodeExecutorAndCustomRetry.class;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
liteflow.rule-source=lazy/flow.xml
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
<then value="a,b,c"/>
|
||||
</chain>
|
||||
</flow>
|
|
@ -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
|
||||
liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.6.9</version>
|
||||
<version>2.6.11</version>
|
||||
<name>liteflow</name>
|
||||
<description>a lightweight and practical micro-process framework</description>
|
||||
<url>https://github.com/bryan31/liteflow</url>
|
||||
|
|
Loading…
Reference in New Issue