mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
!131 优化一些javadoc 格式 删除不必要的import和部分常量提取
Merge pull request !131 from LIke_snow/dev
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.yomahub.liteflow.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@Documented
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.yomahub.liteflow.annotation;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
|
||||
@@ -5,6 +5,9 @@ import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@@ -13,8 +16,11 @@ public @interface LiteflowMethod {
|
||||
|
||||
LiteFlowMethodEnum value();
|
||||
|
||||
// 节点ID,用于区分节点
|
||||
// 默认为空 则按照Spring模式下BeanName为准。
|
||||
/**
|
||||
* 节点ID,用于区分节点
|
||||
* 默认为空 则按照Spring模式下BeanName为准。
|
||||
* @return
|
||||
*/
|
||||
String nodeId() default "";
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,10 @@ import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 注解工具类
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class AnnoUtil {
|
||||
|
||||
public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/10/22
|
||||
@@ -16,7 +17,17 @@ import com.yomahub.liteflow.slot.Slot;
|
||||
*/
|
||||
public interface ICmpAroundAspect {
|
||||
|
||||
/**
|
||||
* 前置处理
|
||||
* @param nodeId 节点ID
|
||||
* @param slot
|
||||
*/
|
||||
void beforeProcess(String nodeId, Slot slot);
|
||||
|
||||
/**
|
||||
* 后置处理
|
||||
* @param nodeId 节点ID
|
||||
* @param slot
|
||||
*/
|
||||
void afterProcess(String nodeId, Slot slot);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ql.util.express.DefaultContext;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.*;
|
||||
import com.yomahub.liteflow.common.ChainConstant;
|
||||
import com.yomahub.liteflow.exception.DataNofFoundException;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.exception.FlowSystemException;
|
||||
@@ -31,45 +32,53 @@ public class LiteFlowChainELBuilder {
|
||||
|
||||
private Chain chain;
|
||||
|
||||
//这是主体的Condition,不包含前置和后置
|
||||
//声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载
|
||||
//虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List
|
||||
//所以在这里做一个缓存,等conditionList全部build完毕后,再去一次性替换chain里面的conditionList
|
||||
/**
|
||||
* //这是主体的Condition,不包含前置和后置
|
||||
* //声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载
|
||||
* //虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List
|
||||
* //所以在这里做一个缓存,等conditionList全部build完毕后,再去一次性替换chain里面的conditionList
|
||||
*/
|
||||
private final List<Condition> conditionList;
|
||||
|
||||
//前置处理Condition,用来区别主体的Condition
|
||||
/**
|
||||
* 前置处理Condition,用来区别主体的Condition
|
||||
*/
|
||||
private final List<Condition> preConditionList;
|
||||
|
||||
//后置处理Condition,用来区别主体的Condition
|
||||
/**
|
||||
* 后置处理Condition,用来区别主体的Condition
|
||||
*/
|
||||
private final List<Condition> finallyConditionList;
|
||||
|
||||
//EL解析引擎
|
||||
/**
|
||||
* EL解析引擎
|
||||
*/
|
||||
private final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner();
|
||||
|
||||
static {
|
||||
//初始化QLExpress的Runner
|
||||
EXPRESS_RUNNER.addFunction("THEN", new ThenOperator());
|
||||
EXPRESS_RUNNER.addFunction("WHEN", new WhenOperator());
|
||||
EXPRESS_RUNNER.addFunction("SWITCH", new SwitchOperator());
|
||||
EXPRESS_RUNNER.addFunction("PRE", new PreOperator());
|
||||
EXPRESS_RUNNER.addFunction("FINALLY", new FinallyOperator());
|
||||
EXPRESS_RUNNER.addFunction("IF", new IfOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("ELSE", Object.class, new ElseOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("ELIF", Object.class, new ElifOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("TO", Object.class, new ToOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("to", Object.class, new ToOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("tag", Object.class, new TagOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("any", Object.class, new AnyOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("id", Object.class, new IdOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("ignoreError", Object.class, new IgnoreErrorOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("threadPool", Object.class, new ThreadPoolOperator());
|
||||
EXPRESS_RUNNER.addFunction("NODE", new NodeOperator());
|
||||
EXPRESS_RUNNER.addFunction("node", new NodeOperator());
|
||||
EXPRESS_RUNNER.addFunction("FOR", new ForOperator());
|
||||
EXPRESS_RUNNER.addFunction("WHILE", new WhileOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("DO", Object.class, new DoOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("BREAK", Object.class, new BreakOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod("data", Object.class, new DataOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.THEN, new ThenOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.WHEN, new WhenOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.SWITCH, new SwitchOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.PRE, new PreOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.FINALLY, new FinallyOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.IF, new IfOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELSE, Object.class, new ElseOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELIF, Object.class, new ElifOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO, Object.class, new ToOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO.toLowerCase(), Object.class, new ToOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TAG, Object.class, new TagOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ANY, Object.class, new AnyOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ID, Object.class, new IdOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.IGNORE_ERROR, Object.class, new IgnoreErrorOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.THREAD_POOL, Object.class, new ThreadPoolOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.NODE.toUpperCase(), new NodeOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.NODE, new NodeOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.FOR, new ForOperator());
|
||||
EXPRESS_RUNNER.addFunction(ChainConstant.WHILE, new WhileOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DO, Object.class, new DoOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.BREAK, Object.class, new BreakOperator());
|
||||
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DATA, Object.class, new DataOperator());
|
||||
}
|
||||
|
||||
public static LiteFlowChainELBuilder createChain() {
|
||||
@@ -86,10 +95,10 @@ public class LiteFlowChainELBuilder {
|
||||
//在parser中chain的build是2段式的,因为涉及到依赖问题,以前是递归parser
|
||||
//2.6.8之后取消了递归的模式,两段式组装,先把带有chainName的chain对象放进去,第二段再组装chain里面的condition
|
||||
//所以这里setChainName的时候需要判断下
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated 请使用 {@link #setChainId(String)}
|
||||
* @return LiteFlowChainELBuilder
|
||||
* @deprecated 请使用 {@link #setChainId(String)}
|
||||
*/
|
||||
public LiteFlowChainELBuilder setChainName(String chainName) {
|
||||
if (FlowBus.containChain(chainName)) {
|
||||
@@ -99,7 +108,7 @@ public class LiteFlowChainELBuilder {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LiteFlowChainELBuilder setChainId(String chainId) {
|
||||
if (FlowBus.containChain(chainId)) {
|
||||
this.chain = FlowBus.getChain(chainId);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.condition.WhenCondition;
|
||||
@@ -13,14 +12,14 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition;
|
||||
*/
|
||||
public class AnyOperator extends BaseOperator<WhenCondition> {
|
||||
|
||||
@Override
|
||||
public WhenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
@Override
|
||||
public WhenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
|
||||
WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class);
|
||||
WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class);
|
||||
|
||||
Boolean any = OperatorHelper.convert(objects[1], Boolean.class);
|
||||
whenCondition.setAny(any);
|
||||
return whenCondition;
|
||||
}
|
||||
Boolean any = OperatorHelper.convert(objects[1], Boolean.class);
|
||||
whenCondition.setAny(any);
|
||||
return whenCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.flow.element.condition.Condition;
|
||||
import com.yomahub.liteflow.flow.element.condition.ForCondition;
|
||||
import com.yomahub.liteflow.flow.element.condition.LoopCondition;
|
||||
import com.yomahub.liteflow.flow.element.condition.WhileCondition;
|
||||
|
||||
/**
|
||||
* EL规则中的BREAK的操作符
|
||||
@@ -31,9 +28,9 @@ public class BreakOperator extends BaseOperator<LoopCondition> {
|
||||
|
||||
//获得需要执行的可执行表达式
|
||||
Node breakNode = OperatorHelper.convert(objects[1], Node.class);
|
||||
if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())){
|
||||
if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())) {
|
||||
condition.setBreakNode(breakNode);
|
||||
}else{
|
||||
} else {
|
||||
throw new QLException("The parameter must be node-break item");
|
||||
}
|
||||
return condition;
|
||||
|
||||
@@ -12,16 +12,16 @@ import com.yomahub.liteflow.flow.element.Node;
|
||||
*/
|
||||
public class DataOperator extends BaseOperator<Node> {
|
||||
|
||||
@Override
|
||||
public Node build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
@Override
|
||||
public Node build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
|
||||
Node node = OperatorHelper.convert(objects[0], Node.class);
|
||||
Node node = OperatorHelper.convert(objects[0], Node.class);
|
||||
|
||||
String cmpData = OperatorHelper.convert(objects[1], String.class);
|
||||
String cmpData = OperatorHelper.convert(objects[1], String.class);
|
||||
|
||||
node.setCmpData(cmpData);
|
||||
node.setCmpData(cmpData);
|
||||
|
||||
return node;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.flow.element.condition.Condition;
|
||||
import com.yomahub.liteflow.flow.element.condition.ForCondition;
|
||||
import com.yomahub.liteflow.flow.element.condition.LoopCondition;
|
||||
import com.yomahub.liteflow.flow.element.condition.WhileCondition;
|
||||
|
||||
/**
|
||||
* EL规则中的DO的操作符
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.condition.Condition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* EL规则中的id的操作符,只有condition可加id
|
||||
@@ -15,18 +12,16 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class IdOperator extends BaseOperator<Condition> {
|
||||
|
||||
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
|
||||
@Override
|
||||
public Condition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
|
||||
@Override
|
||||
public Condition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
Condition condition = OperatorHelper.convert(objects[0], Condition.class);
|
||||
|
||||
Condition condition = OperatorHelper.convert(objects[0], Condition.class);
|
||||
String id = OperatorHelper.convert(objects[1], String.class);
|
||||
|
||||
String id = OperatorHelper.convert(objects[1], String.class);
|
||||
condition.setId(id);
|
||||
|
||||
condition.setId(id);
|
||||
|
||||
return condition;
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,29 +17,29 @@ import com.yomahub.liteflow.flow.element.condition.IfCondition;
|
||||
*/
|
||||
public class IfOperator extends BaseOperator<IfCondition> {
|
||||
|
||||
@Override
|
||||
public IfCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEq(objects, 2, 3);
|
||||
@Override
|
||||
public IfCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEq(objects, 2, 3);
|
||||
|
||||
//解析第一个参数
|
||||
Node ifNode = OperatorHelper.convert(objects[0], Node.class);
|
||||
if (!ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(ifNode.getType())) {
|
||||
throw new QLException("The first parameter must be If item");
|
||||
}
|
||||
//解析第一个参数
|
||||
Node ifNode = OperatorHelper.convert(objects[0], Node.class);
|
||||
if (!ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(ifNode.getType())) {
|
||||
throw new QLException("The first parameter must be If item");
|
||||
}
|
||||
|
||||
//解析第二个参数
|
||||
Executable trueCaseExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
|
||||
//解析第二个参数
|
||||
Executable trueCaseExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
|
||||
|
||||
//解析第三个参数,如果有的话
|
||||
Executable falseCaseExecutableItem = null;
|
||||
if (objects.length == 3) {
|
||||
falseCaseExecutableItem = OperatorHelper.convert(objects[2], Executable.class);
|
||||
}
|
||||
//解析第三个参数,如果有的话
|
||||
Executable falseCaseExecutableItem = null;
|
||||
if (objects.length == 3) {
|
||||
falseCaseExecutableItem = OperatorHelper.convert(objects[2], Executable.class);
|
||||
}
|
||||
|
||||
IfCondition ifCondition = new IfCondition();
|
||||
ifCondition.setExecutableList(ListUtil.toList(ifNode));
|
||||
ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem);
|
||||
ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem);
|
||||
return ifCondition;
|
||||
}
|
||||
IfCondition ifCondition = new IfCondition();
|
||||
ifCondition.setExecutableList(ListUtil.toList(ifNode));
|
||||
ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem);
|
||||
ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem);
|
||||
return ifCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
@@ -14,14 +13,14 @@ import com.yomahub.liteflow.flow.element.condition.PreCondition;
|
||||
*/
|
||||
public class PreOperator extends BaseOperator<PreCondition> {
|
||||
|
||||
@Override
|
||||
public PreCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtZero(objects);
|
||||
@Override
|
||||
public PreCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtZero(objects);
|
||||
|
||||
PreCondition preCondition = new PreCondition();
|
||||
for (Object obj : objects) {
|
||||
preCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
|
||||
}
|
||||
return preCondition;
|
||||
}
|
||||
PreCondition preCondition = new PreCondition();
|
||||
for (Object obj : objects) {
|
||||
preCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
|
||||
}
|
||||
return preCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
@@ -14,14 +13,14 @@ import com.yomahub.liteflow.flow.element.condition.ThenCondition;
|
||||
*/
|
||||
public class ThenOperator extends BaseOperator<ThenCondition> {
|
||||
|
||||
@Override
|
||||
public ThenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtZero(objects);
|
||||
@Override
|
||||
public ThenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtZero(objects);
|
||||
|
||||
ThenCondition thenCondition = new ThenCondition();
|
||||
for (Object obj : objects) {
|
||||
thenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
|
||||
}
|
||||
return thenCondition;
|
||||
}
|
||||
ThenCondition thenCondition = new ThenCondition();
|
||||
for (Object obj : objects) {
|
||||
thenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
|
||||
}
|
||||
return thenCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.condition.WhenCondition;
|
||||
@@ -13,14 +12,14 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition;
|
||||
*/
|
||||
public class ThreadPoolOperator extends BaseOperator<WhenCondition> {
|
||||
|
||||
@Override
|
||||
public WhenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
@Override
|
||||
public WhenCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqTwo(objects);
|
||||
|
||||
WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class);
|
||||
WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class);
|
||||
|
||||
whenCondition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class));
|
||||
whenCondition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class));
|
||||
|
||||
return whenCondition;
|
||||
}
|
||||
return whenCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
@@ -14,16 +13,16 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition;
|
||||
*/
|
||||
public class ToOperator extends BaseOperator<SwitchCondition> {
|
||||
|
||||
@Override
|
||||
public SwitchCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtTwo(objects);
|
||||
@Override
|
||||
public SwitchCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeGtTwo(objects);
|
||||
|
||||
SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class);
|
||||
SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class);
|
||||
|
||||
for (int i = 1; i < objects.length; i++) {
|
||||
Executable target = OperatorHelper.convert(objects[i], Executable.class);
|
||||
switchCondition.addTargetItem(target);
|
||||
}
|
||||
return switchCondition;
|
||||
}
|
||||
for (int i = 1; i < objects.length; i++) {
|
||||
Executable target = OperatorHelper.convert(objects[i], Executable.class);
|
||||
switchCondition.addTargetItem(target);
|
||||
}
|
||||
return switchCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.builder.el.operator;
|
||||
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
|
||||
@@ -3,13 +3,13 @@ package com.yomahub.liteflow.builder.el.operator.base;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ql.util.express.exception.QLException;
|
||||
import com.yomahub.liteflow.exception.DataNofFoundException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Operator 常用工具类
|
||||
*
|
||||
* @author gaibu
|
||||
* @since 2.8.6
|
||||
*/
|
||||
@@ -131,17 +131,17 @@ public class OperatorHelper {
|
||||
* 如果是Node类型的则进行copy
|
||||
*/
|
||||
public static <T> T convert(Object object, Class<T> clazz, String errorMsg) throws QLException {
|
||||
try{
|
||||
try {
|
||||
if (clazz.isAssignableFrom(object.getClass())) {
|
||||
|
||||
if(clazz.equals(Node.class)){
|
||||
if (clazz.equals(Node.class)) {
|
||||
Node node = (Node) object;
|
||||
return (T) node.copy();
|
||||
}else{
|
||||
} else {
|
||||
return (T) object;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new QLException("An error occurred while copying an object");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,40 @@ public interface ChainConstant {
|
||||
String CONDITION = "condition";
|
||||
|
||||
String TYPE = "type";
|
||||
|
||||
String THEN = "THEN";
|
||||
|
||||
String WHEN = "WHEN";
|
||||
|
||||
String SWITCH = "SWITCH";
|
||||
|
||||
String PRE = "PRE";
|
||||
|
||||
String FINALLY = "FINALLY";
|
||||
|
||||
String IF = "IF";
|
||||
|
||||
String ELSE = "ELSE";
|
||||
|
||||
String ELIF = "ELIF";
|
||||
|
||||
String TO = "TO";
|
||||
|
||||
String TAG = "tag";
|
||||
|
||||
String IGNORE_ERROR = "ignoreError";
|
||||
|
||||
String THREAD_POOL = "threadPool";
|
||||
|
||||
String WHILE = "WHILE";
|
||||
|
||||
String FOR = "FOR";
|
||||
|
||||
String DO = "DO";
|
||||
|
||||
String BREAK = "BREAK";
|
||||
|
||||
String DATA = "data";
|
||||
|
||||
String MONITOR_BUS = "monitorBus";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.yomahub.liteflow.common;
|
||||
|
||||
/**
|
||||
* @author Yun
|
||||
*/
|
||||
public class LocalDefaultFlowConstant {
|
||||
public static final String DEFAULT="default";
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.yomahub.liteflow.core;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
||||
import com.yomahub.liteflow.flow.executor.NodeExecutor;
|
||||
import com.yomahub.liteflow.common.ChainConstant;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.flow.executor.NodeExecutor;
|
||||
import com.yomahub.liteflow.monitor.MonitorBus;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
@@ -15,6 +15,7 @@ import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder;
|
||||
|
||||
/**
|
||||
* 组件初始化器
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@@ -22,22 +23,22 @@ public class ComponentInitializer {
|
||||
|
||||
private static ComponentInitializer instance;
|
||||
|
||||
public static ComponentInitializer loadInstance(){
|
||||
if (ObjectUtil.isNull(instance)){
|
||||
public static ComponentInitializer loadInstance() {
|
||||
if (ObjectUtil.isNull(instance)) {
|
||||
instance = new ComponentInitializer();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public NodeComponent initComponent(NodeComponent nodeComponent, NodeTypeEnum type, String name, String nodeId){
|
||||
public NodeComponent initComponent(NodeComponent nodeComponent, NodeTypeEnum type, String name, String nodeId) {
|
||||
nodeComponent.setNodeId(nodeId);
|
||||
nodeComponent.setSelf(nodeComponent);
|
||||
nodeComponent.setType(type);
|
||||
|
||||
//设置MonitorBus,如果没有就不注入
|
||||
if (ContextAwareHolder.loadContextAware().hasBean("monitorBus")){
|
||||
if (ContextAwareHolder.loadContextAware().hasBean(ChainConstant.MONITOR_BUS)) {
|
||||
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
|
||||
if(ObjectUtil.isNotNull(monitorBus)){
|
||||
if (ObjectUtil.isNotNull(monitorBus)) {
|
||||
nodeComponent.setMonitorBus(monitorBus);
|
||||
}
|
||||
}
|
||||
@@ -45,17 +46,17 @@ public class ComponentInitializer {
|
||||
//先取传进来的name值(配置文件中配置的),再看有没有配置@LiteflowComponent标注
|
||||
//@LiteflowComponent标注只在spring体系下生效,这里用了spi机制取到相应环境下的实现类
|
||||
nodeComponent.setName(name);
|
||||
if (!type.isScript() && StrUtil.isBlank(nodeComponent.getName())){
|
||||
if (!type.isScript() && StrUtil.isBlank(nodeComponent.getName())) {
|
||||
nodeComponent.setName(LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(nodeComponent));
|
||||
}
|
||||
|
||||
//先从组件上取@RetryCount标注,如果没有,则看全局配置,全局配置如果不配置的话,默认是0
|
||||
//默认retryForExceptions为Exception.class
|
||||
LiteflowRetry liteflowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class);
|
||||
LiteflowRetry liteFlowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class);
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
if (liteflowRetryAnnotation != null) {
|
||||
nodeComponent.setRetryCount(liteflowRetryAnnotation.retry());
|
||||
nodeComponent.setRetryForExceptions(liteflowRetryAnnotation.forExceptions());
|
||||
if (liteFlowRetryAnnotation != null) {
|
||||
nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry());
|
||||
nodeComponent.setRetryForExceptions(liteFlowRetryAnnotation.forExceptions());
|
||||
} else {
|
||||
nodeComponent.setRetryCount(liteflowConfig.getRetryCount());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yomahub.liteflow.exception.FlowExecutorNotInitException;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class FlowExecutorHolder {
|
||||
|
||||
private static FlowExecutor flowExecutor;
|
||||
|
||||
@@ -7,5 +7,9 @@ package com.yomahub.liteflow.core;
|
||||
*/
|
||||
public interface ScriptComponent {
|
||||
|
||||
/**
|
||||
* 加载脚本
|
||||
* @param script
|
||||
*/
|
||||
void loadScript(String script);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.yomahub.liteflow.core.proxy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class LiteFlowMethodBean {
|
||||
|
||||
private String methodName;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.yomahub.liteflow.enums;
|
||||
|
||||
/**
|
||||
* @author Yun
|
||||
*/
|
||||
public enum ConditionTypeEnum {
|
||||
TYPE_THEN("then","then"),
|
||||
TYPE_WHEN("when","when"),
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 链端异常
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class ChainEndException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 链端不存在
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class ChainNotFoundException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 组件方法定义错误异常
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class ComponentMethodDefineErrorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 组件不可访问异常
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class ComponentNotAccessException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 组件代理错误异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ComponentProxyErrorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 配置错误异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ConfigErrorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 循环依赖异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class CyclicDependencyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 未找到数据异常
|
||||
* @author tangkc
|
||||
*/
|
||||
public class DataNofFoundException extends RuntimeException {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* EL 解析异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ELParseException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 空条件值异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class EmptyConditionValueException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 错误支持路径异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ErrorSupportPathException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 流程执行者未初始化
|
||||
* @author Yun
|
||||
*/
|
||||
public class FlowExecutorNotInitException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 流程系统异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class FlowSystemException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 如果目标不能是 Pre 或 Finally 异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class IfTargetCannotBePreOrFinallyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 类型错误异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class IfTypeErrorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* Json 进程异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class JsonProcessException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 重复解析器异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class MultipleParsersException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 无可用插槽异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NoAvailableSlotException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 没有节点异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NoForNodeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 节点不为真异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NoIfTrueNodeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 无切换目标节点异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NoSwitchTargetNodeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 没有 While 节点异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NoWhileNodeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 节点构建异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NodeBuildException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 找不到节点类异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NodeClassNotFoundException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 节点类型无法猜测异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NodeTypeCanNotGuessException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 不支持条件异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NotSupportConditionException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 空节点异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class NullNodeTypeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 解析异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ParseException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 解析器找不到异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class ParserCannotFindException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 切换目标不能是 Pre 或 Finally 异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class SwitchTargetCannotBePreOrFinallyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* 开关类型错误异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class SwitchTypeErrorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 执行异常时
|
||||
* @author Yun
|
||||
*/
|
||||
public class WhenExecuteException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 当超时异常
|
||||
* @author Yun
|
||||
*/
|
||||
public class WhenTimeoutException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -22,13 +22,16 @@ public abstract class Condition implements Executable{
|
||||
|
||||
private String id;
|
||||
|
||||
//可执行元素的集合
|
||||
/**
|
||||
* 可执行元素的集合
|
||||
*/
|
||||
private List<Executable> executableList = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
//当前所在的ChainName
|
||||
//如果对于子流程来说,那这个就是子流程所在的Chain
|
||||
/**
|
||||
* 当前所在的ChainName
|
||||
* 如果对于子流程来说,那这个就是子流程所在的Chain
|
||||
*/
|
||||
private String currChainName;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,11 @@ import java.util.List;
|
||||
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());
|
||||
@@ -47,7 +51,12 @@ 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.getDisplayName(), currentRetryCount + 1);
|
||||
|
||||
@@ -13,19 +13,26 @@ import java.util.Map;
|
||||
* @since 2.6.9
|
||||
*/
|
||||
public class NodeExecutorHelper {
|
||||
//此处使用Map缓存线程池信息
|
||||
/**
|
||||
* 此处使用Map缓存线程池信息
|
||||
*/
|
||||
private final Map<Class<? extends NodeExecutor>, NodeExecutor> nodeExecutorMap;
|
||||
|
||||
private NodeExecutorHelper() {
|
||||
nodeExecutorMap = MapUtil.newConcurrentHashMap();
|
||||
}
|
||||
|
||||
//使用静态内部类实现单例模式
|
||||
/**
|
||||
* 使用静态内部类实现单例模式
|
||||
*/
|
||||
private static class Holder {
|
||||
static final NodeExecutorHelper INSTANCE = new NodeExecutorHelper();
|
||||
}
|
||||
|
||||
//获取帮助者的实例
|
||||
/**
|
||||
* 获取帮助者的实例
|
||||
* @return
|
||||
*/
|
||||
public static NodeExecutorHelper loadInstance() {
|
||||
// 外围类能直接访问内部类(不管是否是静态的)的私有变量
|
||||
return Holder.INSTANCE;
|
||||
|
||||
@@ -34,20 +34,26 @@ public class DataBus {
|
||||
|
||||
public static AtomicInteger OCCUPY_COUNT = new AtomicInteger(0);
|
||||
|
||||
//这里为什么采用ConcurrentHashMap作为slot存放的容器?
|
||||
//因为ConcurrentHashMap的随机取值复杂度也和数组一样为O(1),并且没有并发问题,还有自动扩容的功能
|
||||
//用数组的话,扩容涉及copy,线程安全问题还要自己处理
|
||||
/**
|
||||
* 这里为什么采用ConcurrentHashMap作为slot存放的容器?
|
||||
* 因为ConcurrentHashMap的随机取值复杂度也和数组一样为O(1),并且没有并发问题,还有自动扩容的功能
|
||||
* 用数组的话,扩容涉及copy,线程安全问题还要自己处理
|
||||
*/
|
||||
private static ConcurrentHashMap<Integer, Slot> SLOTS;
|
||||
|
||||
private static ConcurrentLinkedQueue<Integer> QUEUE;
|
||||
|
||||
//当前slot的下标index的最大值
|
||||
/**
|
||||
* 当前slot的下标index的最大值
|
||||
*/
|
||||
private static Integer currentIndexMaxValue;
|
||||
|
||||
//这里原先版本中是static块,现在改成init静态方法,由FlowExecutor中的init去调用
|
||||
//这样的改动对项目来说没有什么实际意义,但是在单元测试中,却有意义。
|
||||
//因为单元测试中所有的一起跑,jvm是不退出的,所以如果是static块的话,跑多个testsuite只会执行一次。
|
||||
//而由FlowExecutor中的init去调用,是会被执行多次的。保证了每个单元测试都能初始化一遍
|
||||
/**
|
||||
* 这里原先版本中是static块,现在改成init静态方法,由FlowExecutor中的init去调用
|
||||
* 这样的改动对项目来说没有什么实际意义,但是在单元测试中,却有意义。
|
||||
* 因为单元测试中所有的一起跑,jvm是不退出的,所以如果是static块的话,跑多个testsuite只会执行一次。
|
||||
* 而由FlowExecutor中的init去调用,是会被执行多次的。保证了每个单元测试都能初始化一遍
|
||||
*/
|
||||
public static void init() {
|
||||
if (MapUtil.isEmpty(SLOTS)){
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
|
||||
@@ -6,6 +6,10 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* LiteFlow 默认主执行器生成器
|
||||
* @author Yun
|
||||
*/
|
||||
public class LiteFlowDefaultMainExecutorBuilder implements ExecutorBuilder{
|
||||
@Override
|
||||
public ExecutorService buildExecutor() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.*;
|
||||
import com.yomahub.liteflow.core.*;
|
||||
import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.proxy.ComponentProxy;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ComponentProxyErrorException;
|
||||
@@ -17,6 +16,7 @@ import java.util.List;
|
||||
/**
|
||||
* 组件代理类通用方法
|
||||
* 主要用于声明式组件
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.14
|
||||
*/
|
||||
@@ -24,14 +24,18 @@ public class LiteFlowProxyUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LiteFlowProxyUtil.class);
|
||||
|
||||
//判断一个bean是否是声明式组件
|
||||
public static boolean isDeclareCmp(Class<?> clazz){
|
||||
/**
|
||||
* 判断一个bean是否是声明式组件
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDeclareCmp(Class<?> clazz) {
|
||||
//查看bean里的method是否有方法标记了@LiteflowMethod标注
|
||||
//这里的bean有可能是cglib加强过的class,所以要先进行个判断
|
||||
Class<?> targetClass;
|
||||
if (isCglibProxyClass(clazz)){
|
||||
if (isCglibProxyClass(clazz)) {
|
||||
targetClass = getUserClass(clazz);
|
||||
}else{
|
||||
} else {
|
||||
targetClass = clazz;
|
||||
}
|
||||
// 判断是否有方法标记了@LiteflowMethod标注,有则为声明式组件
|
||||
@@ -40,16 +44,21 @@ public class LiteFlowProxyUtil {
|
||||
);
|
||||
}
|
||||
|
||||
//对一个满足声明式的bean进行代理,生成代理类数组
|
||||
public static List<NodeComponent> proxy2NodeComponent(Object bean, String nodeId){
|
||||
try{
|
||||
/**
|
||||
* 对一个满足声明式的bean进行代理,生成代理类数组
|
||||
* @param bean
|
||||
* @param nodeId
|
||||
* @return
|
||||
*/
|
||||
public static List<NodeComponent> proxy2NodeComponent(Object bean, String nodeId) {
|
||||
try {
|
||||
NodeTypeEnum nodeType = NodeTypeEnum.guessType(bean.getClass());
|
||||
ComponentProxy proxy = new ComponentProxy(nodeId, bean, nodeType.getMappingClazz());
|
||||
return proxy.getProxyList();
|
||||
}catch (LiteFlowException liteFlowException){
|
||||
} catch (LiteFlowException liteFlowException) {
|
||||
throw liteFlowException;
|
||||
}catch (Exception e){
|
||||
String errMsg = StrUtil.format("Error while proxying bean[{}]",bean.getClass().getName());
|
||||
} catch (Exception e) {
|
||||
String errMsg = StrUtil.format("Error while proxying bean[{}]", bean.getClass().getName());
|
||||
LOG.error(errMsg);
|
||||
throw new ComponentProxyErrorException(errMsg);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Yun
|
||||
*/
|
||||
public class SerialsUtil {
|
||||
|
||||
public static int serialInt = 1;
|
||||
|
||||
Reference in New Issue
Block a user