Conflicts:
	liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/IdGeneratorHelper.java
This commit is contained in:
tangkc 2022-07-13 09:22:36 +08:00
commit a136704c7f
48 changed files with 630 additions and 87 deletions

View File

@ -24,7 +24,7 @@ public class ToOperator extends Operator {
throw new Exception();
}
if (objects.length <= 2){
if (objects.length <= 1){
LOG.error("parameter error");
throw new Exception();
}

View File

@ -19,6 +19,7 @@ import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.parser.*;
import com.yomahub.liteflow.parser.base.FlowParser;
import com.yomahub.liteflow.parser.el.*;
@ -113,6 +114,9 @@ public class FlowExecutor {
//在非spring体系下是一个空实现等于不做此步骤
ContextCmpInitHolder.loadContextCmpInit().initCmp();
//进行id生成器的初始化
IdGeneratorHolder.init();
//如果没有配置规则文件路径就停止初始化
//规则文件路径不是一定要有因为liteflow分基于规则和基于代码两种有可能是动态代码构建的
if (StrUtil.isBlank(liteflowConfig.getRuleSource())) {

View File

@ -10,7 +10,6 @@ package com.yomahub.liteflow.flow.element.condition;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.enums.ConditionTypeEnum;
import com.yomahub.liteflow.exception.WhenExecuteException;
import com.yomahub.liteflow.flow.element.Executable;
import com.yomahub.liteflow.flow.parallel.CompletableFutureTimeout;
import com.yomahub.liteflow.flow.parallel.ParallelSupplier;
import com.yomahub.liteflow.flow.parallel.WhenFutureObj;
@ -26,7 +25,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**

View File

@ -32,8 +32,7 @@ public class NodeExecutorHelper {
}
public NodeExecutor buildNodeExecutor(Class<? extends NodeExecutor> nodeExecutorClass) {
// 高频操作-采取apache判空操作-效率高于hutool的isBlank将近3倍
if (ObjectUtil.isNull(nodeExecutorClass)) {
if (nodeExecutorClass == null) {
// 此处使用默认的节点执行器进行执行
nodeExecutorClass = DefaultNodeExecutor.class;
}

View File

@ -1,54 +0,0 @@
package com.yomahub.liteflow.flow.id;
import com.yomahub.liteflow.exception.RequestIdGeneratorException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import java.util.Objects;
/**
* Id 生成器帮助器
*
* @author tangkc
*/
public class IdGeneratorHelper {
private RequestIdGenerator requestIdGenerator;
private volatile static IdGeneratorHelper INSTANCE;
private IdGeneratorHelper() {
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
String requestIdGeneratorClass = liteflowConfig.getRequestIdGeneratorClass();
try {
Class<RequestIdGenerator> idGenerateClass = (Class<RequestIdGenerator>) Class.forName(requestIdGeneratorClass);
this.requestIdGenerator = ContextAwareHolder.loadContextAware().registerBean(idGenerateClass);
} catch (Exception e) {
throw new RequestIdGeneratorException(e.getMessage());
}
}
public static IdGeneratorHelper getInstance() {
if (Objects.isNull(INSTANCE)) {
//这里加同步锁是为了避免启动后第一次多并发获取requestId而造成重复初始化的场景
//并非每次都会执行这个同步锁所以不存在性能问题
synchronized (IdGeneratorHelper.class) {
if (Objects.isNull(INSTANCE)) {
INSTANCE = new IdGeneratorHelper();
}
}
}
return INSTANCE;
}
public String generate() {
return this.requestIdGenerator.generate();
}
public void clear(){
INSTANCE = null;
}
}

View File

@ -0,0 +1,54 @@
package com.yomahub.liteflow.flow.id;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.exception.RequestIdGeneratorException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
/**
* Id 生成器帮助器
*
* @author tangkc
*/
public class IdGeneratorHolder {
private RequestIdGenerator requestIdGenerator;
private static IdGeneratorHolder INSTANCE;
public static void init(){
try{
INSTANCE = new IdGeneratorHolder();
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
String requestIdGeneratorClass = liteflowConfig.getRequestIdGeneratorClass();
RequestIdGenerator requestIdGenerator;
if (StrUtil.isBlank(requestIdGeneratorClass)) {
requestIdGenerator = new DefaultRequestIdGenerator();
} else {
Class<RequestIdGenerator> idGenerateClass = (Class<RequestIdGenerator>) Class.forName(requestIdGeneratorClass);
requestIdGenerator = ContextAwareHolder.loadContextAware().registerBean(idGenerateClass);
}
INSTANCE.setRequestIdGenerator(requestIdGenerator);
}catch (Exception e) {
throw new RequestIdGeneratorException(e.getMessage());
}
}
public static IdGeneratorHolder getInstance() {
return INSTANCE;
}
public String generate() {
return requestIdGenerator.generate();
}
public RequestIdGenerator getRequestIdGenerator() {
return requestIdGenerator;
}
public void setRequestIdGenerator(RequestIdGenerator requestIdGenerator) {
this.requestIdGenerator = requestIdGenerator;
}
}

View File

@ -1,6 +1,7 @@
package com.yomahub.liteflow.parser.helper;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
@ -27,6 +28,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import static com.yomahub.liteflow.common.ChainConstant.*;
@ -383,8 +385,39 @@ public class ParserHelper {
public static void parseOneChainEl(Element e) {
//构建chainBuilder
String chainName = e.attributeValue(NAME);
String el = e.getTextTrim();
String text = e.getText();
String el = RegexUtil.removeComments(text);
LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainName(chainName);
chainELBuilder.setEL(el).build();
}
private static class RegexUtil{
// java 注释的正则表达式
private static final String REGEX_COMMENT = "/\\*((?!\\*/).|[\\r\\n])*?\\*/|[ \\t]*//.*";
/**
* 移除 el 表达式中的注释支持 java 的注释包括单行注释多行注释
* 会压缩字符串移除空格和换行符
*
* @param elStr el 表达式
* @return 移除注释后的 el 表达式
*/
private static String removeComments(String elStr) {
if (StrUtil.isBlank(elStr)) {
return elStr;
}
String text = Pattern.compile(REGEX_COMMENT)
.matcher(elStr)
// 移除注释
.replaceAll(CharSequenceUtil.EMPTY)
// 移除字符串中的空格
.replaceAll(CharSequenceUtil.SPACE, CharSequenceUtil.EMPTY);
// 移除所有换行符
return StrUtil.removeAllLineBreaks(text);
}
}
}

View File

@ -11,7 +11,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.exception.NoSuchContextBeanException;
import com.yomahub.liteflow.exception.NullParamException;
import com.yomahub.liteflow.flow.entity.CmpStep;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -223,7 +223,7 @@ public class Slot{
}
public void generateRequestId() {
metaDataMap.put(REQUEST_ID, IdGeneratorHelper.getInstance().generate());
metaDataMap.put(REQUEST_ID, IdGeneratorHolder.getInstance().generate());
}
public String getRequestId() {

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,7 +17,6 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -0,0 +1,35 @@
package com.yomahub.liteflow.test.comments;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.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:/comments/application.properties")
@SpringBootTest(classes = LiteflowNodeELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"})
public class LiteflowNodeELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 测试注释
@Test
public void testAsyncFlow1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr()));
}
}

View File

@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("a")
@LiteflowCmpDefine
public class ACmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
}

View File

@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import cn.hutool.core.thread.ThreadUtil;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("b")
@LiteflowCmpDefine
public class BCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("BCmp executed!");
}
}

View File

@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import cn.hutool.core.thread.ThreadUtil;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("c")
@LiteflowCmpDefine
public class CCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("CCmp executed!");
}
}

View File

@ -0,0 +1,4 @@
/**
* 测试注释
*/
package com.yomahub.liteflow.test.comments;

View File

@ -0,0 +1 @@
liteflow.rule-source=comments/flow.el.xml

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
// 单行注释
THEN(
// 单行注释
a,
b,
WHEN(
/**
* 多行注释
*/
c,
b
)
);
</chain>
</flow>

View File

@ -2,7 +2,7 @@ package com.yomahub.liteflow.test;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.thread.ExecutorHelper;
@ -17,6 +17,5 @@ public class BaseTest {
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
FlowExecutorHolder.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.comments;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 测试注释
*/
public class LiteflowNodeTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("comments/flow.el.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
// 测试注释
@Test
public void testAsyncFlow1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr()));
}
}

View File

@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent{
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@ -0,0 +1,4 @@
/**
* 测试注释
*/
package com.yomahub.liteflow.test.comments;

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.comments.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.comments.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.comments.cmp.CCmp"/>
</nodes>
<chain name="chain1">
// 单行注释
THEN(
// 单行注释
a,
b,
WHEN(
/**
* 多行注释
*/
c,
b
)
);
</chain>
</flow>

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -0,0 +1,35 @@
package com.yomahub.liteflow.test.comments;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.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:/comments/application.properties")
@SpringBootTest(classes = LiteflowNodeELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"})
public class LiteflowNodeELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 测试注释
@Test
public void testAsyncFlow1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr()));
}
}

View File

@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("a")
@LiteflowCmpDefine
public class ACmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
}

View File

@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("b")
@LiteflowCmpDefine
public class BCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("BCmp executed!");
}
}

View File

@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("c")
@LiteflowCmpDefine
public class CCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("CCmp executed!");
}
}

View File

@ -0,0 +1,4 @@
/**
* 测试注释
*/
package com.yomahub.liteflow.test.comments;

View File

@ -0,0 +1 @@
liteflow.rule-source=comments/flow.el.xml

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
// 单行注释
THEN(
// 单行注释
a,
b,
WHEN(
/**
* 多行注释
*/
c,
b
)
);
</chain>
</flow>

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.comments;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/comments/application.xml")
public class LiteflowNodeELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 测试注释
@Test
public void testAsyncFlow1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr()));
}
}

View File

@ -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.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("a")
public class ACmp extends NodeComponent{
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@ -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.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@ -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.comments.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@ -0,0 +1,4 @@
/**
* 测试注释
*/
package com.yomahub.liteflow.test.comments;

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.yomahub.liteflow.test.comments.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="comments/flow.el.xml"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<constructor-arg name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
// 单行注释
THEN(
// 单行注释
a,
b,
WHEN(
/**
* 多行注释
*/
c,
b
)
);
</chain>
</flow>

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,7 +17,6 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -2,7 +2,7 @@ package com.yomahub.liteflow.test;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.thread.ExecutorHelper;
@ -17,6 +17,5 @@ public class BaseTest {
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
FlowExecutorHolder.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -3,7 +3,6 @@ package com.yomahub.liteflow.test.requestId;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -2,10 +2,8 @@ package com.yomahub.liteflow.test.requestId;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

View File

@ -1,7 +1,7 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.flow.id.IdGeneratorHolder;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
@ -17,6 +17,5 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -2,10 +2,8 @@ package com.yomahub.liteflow.test.requestId;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.ComponentScan;