加入格式化代码插件,并提交格式化后的代码

This commit is contained in:
everywhere.z 2023-03-20 11:50:40 +08:00
parent 1f13db48fc
commit ec50e3a0af
1756 changed files with 24781 additions and 22473 deletions

1
.springjavaformatconfig Normal file
View File

@ -0,0 +1 @@
java-baseline=8

View File

@ -1,6 +1,7 @@
package com.yomahub.liteflow.annotation;
import java.lang.annotation.*;
/**
* @author Bryan.Zhang
*/
@ -9,5 +10,6 @@ import java.lang.annotation.*;
@Documented
public @interface AliasFor {
String value() default "";
String value() default "";
}

View File

@ -3,14 +3,16 @@ package com.yomahub.liteflow.annotation;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import java.lang.annotation.*;
/**
* @author Bryan.Zhang
*/
@Target({ElementType.TYPE})
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface LiteflowCmpDefine {
NodeTypeEnum value() default NodeTypeEnum.COMMON;
NodeTypeEnum value() default NodeTypeEnum.COMMON;
}

View File

@ -8,24 +8,24 @@ import java.lang.annotation.*;
/**
* @author Bryan.Zhang
*/
@Target({ElementType.METHOD})
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface LiteflowMethod {
LiteFlowMethodEnum value();
LiteFlowMethodEnum value();
/**
* 节点ID用于区分节点
* 默认为空 则按照Spring模式下BeanName为准
* @return
*/
String nodeId() default "";
/**
* 节点ID用于区分节点 默认为空 则按照Spring模式下BeanName为准
* @return
*/
String nodeId() default "";
/**
* CMP类型定义
* @return AnnotationNodeTypeEnum
*/
NodeTypeEnum nodeType() default NodeTypeEnum.COMMON;
/**
* CMP类型定义
* @return AnnotationNodeTypeEnum
*/
NodeTypeEnum nodeType() default NodeTypeEnum.COMMON;
}

View File

@ -8,17 +8,18 @@ import java.lang.annotation.*;
* @author Bryan.Zhang
* @since 2.6.0
*/
@Target({ElementType.TYPE,ElementType.METHOD})
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface LiteflowRetry {
@AliasFor("retry")
int value() default 0;
@AliasFor("retry")
int value() default 0;
@AliasFor("value")
int retry() default 0;
@AliasFor("value")
int retry() default 0;
Class<? extends Exception>[] forExceptions() default { Exception.class };
Class<? extends Exception>[] forExceptions() default {Exception.class};
}

View File

@ -11,44 +11,48 @@ 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) {
A annotation = AnnotationUtil.getAnnotation(annotatedElement, annotationType);
if (ObjectUtil.isNull(annotation)){
return null;
}
public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType) {
A annotation = AnnotationUtil.getAnnotation(annotatedElement, annotationType);
if (ObjectUtil.isNull(annotation)) {
return null;
}
Map<String, String> aliasMap = new HashMap<>();
Map<String, Object> defaultValueMap = new HashMap<>();
Arrays.stream(ReflectUtil.getMethods(annotationType)).forEach(method -> {
AliasFor aliasFor = AnnotationUtil.getAnnotation(method, AliasFor.class);
if (ObjectUtil.isNotNull(aliasFor)){
aliasMap.put(method.getName(), aliasFor.value());
defaultValueMap.put(method.getName(), getDefaultValue(annotationType, method.getName()));
}
});
Map<String, String> aliasMap = new HashMap<>();
Map<String, Object> defaultValueMap = new HashMap<>();
Arrays.stream(ReflectUtil.getMethods(annotationType)).forEach(method -> {
AliasFor aliasFor = AnnotationUtil.getAnnotation(method, AliasFor.class);
if (ObjectUtil.isNotNull(aliasFor)) {
aliasMap.put(method.getName(), aliasFor.value());
defaultValueMap.put(method.getName(), getDefaultValue(annotationType, method.getName()));
}
});
aliasMap.forEach((key, value1) -> {
Object value = ReflectUtil.invoke(annotation, key);
Object defaultValue = defaultValueMap.get(key);
if (ObjectUtil.notEqual(value, defaultValue)) {
AnnotationUtil.setValue(annotation, value1, value);
}
});
aliasMap.forEach((key, value1) -> {
Object value = ReflectUtil.invoke(annotation, key);
Object defaultValue = defaultValueMap.get(key);
if (ObjectUtil.notEqual(value, defaultValue)) {
AnnotationUtil.setValue(annotation, value1, value);
}
});
return annotation;
}
return annotation;
}
private static <A extends Annotation> Object getDefaultValue(Class<A> annotationType, String property) {
try {
return annotationType.getMethod(property).getDefaultValue();
}
catch (Exception e) {
return null;
}
}
private static <A extends Annotation> Object getDefaultValue(Class<A> annotationType, String property){
try{
return annotationType.getMethod(property).getDefaultValue();
}catch (Exception e){
return null;
}
}
}

View File

@ -11,23 +11,24 @@ package com.yomahub.liteflow.aop;
import com.yomahub.liteflow.slot.Slot;
/**
* 全局组件拦截器接口
* 实现这个接口并注入到spring上下文即可
* 全局组件拦截器接口 实现这个接口并注入到spring上下文即可
*
* @author Bryan.Zhang
*/
public interface ICmpAroundAspect {
/**
* 前置处理
* @param nodeId 节点ID
* @param slot
*/
void beforeProcess(String nodeId, Slot slot);
/**
* 前置处理
* @param nodeId 节点ID
* @param slot
*/
void beforeProcess(String nodeId, Slot slot);
/**
* 后置处理
* @param nodeId 节点ID
* @param slot
*/
void afterProcess(String nodeId, Slot slot);
/**
* 后置处理
* @param nodeId 节点ID
* @param slot
*/
void afterProcess(String nodeId, Slot slot);
}

View File

@ -18,170 +18,178 @@ import java.util.Objects;
public class LiteFlowNodeBuilder {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
private final Node node;
private final Node node;
public static LiteFlowNodeBuilder createNode() {
return new LiteFlowNodeBuilder();
}
public static LiteFlowNodeBuilder createNode() {
return new LiteFlowNodeBuilder();
}
public static LiteFlowNodeBuilder createCommonNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.COMMON);
}
public static LiteFlowNodeBuilder createCommonNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.COMMON);
}
public static LiteFlowNodeBuilder createSwitchNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH);
}
public static LiteFlowNodeBuilder createSwitchNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH);
}
public static LiteFlowNodeBuilder createIfNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.IF);
}
public static LiteFlowNodeBuilder createIfNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.IF);
}
public static LiteFlowNodeBuilder createForNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.FOR);
}
public static LiteFlowNodeBuilder createForNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.FOR);
}
public static LiteFlowNodeBuilder createWhileNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE);
}
public static LiteFlowNodeBuilder createWhileNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE);
}
public static LiteFlowNodeBuilder createBreakNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK);
}
public static LiteFlowNodeBuilder createBreakNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK);
}
public static LiteFlowNodeBuilder createIteratorNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.ITERATOR);
}
public static LiteFlowNodeBuilder createIteratorNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.ITERATOR);
}
public static LiteFlowNodeBuilder createScriptNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SCRIPT);
}
public static LiteFlowNodeBuilder createScriptNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SCRIPT);
}
public static LiteFlowNodeBuilder createScriptSwitchNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptSwitchNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptIfNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.IF_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptIfNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.IF_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptForNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.FOR_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptForNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.FOR_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptWhileNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptWhileNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptBreakNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK_SCRIPT);
}
public static LiteFlowNodeBuilder createScriptBreakNode() {
return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK_SCRIPT);
}
public LiteFlowNodeBuilder() {
this.node = new Node();
}
public LiteFlowNodeBuilder() {
this.node = new Node();
}
public LiteFlowNodeBuilder(NodeTypeEnum type) {
this.node = new Node();
this.node.setType(type);
}
public LiteFlowNodeBuilder(NodeTypeEnum type) {
this.node = new Node();
this.node.setType(type);
}
public LiteFlowNodeBuilder setId(String nodeId) {
if (StrUtil.isBlank(nodeId)) {
return this;
}
this.node.setId(nodeId.trim());
return this;
}
public LiteFlowNodeBuilder setId(String nodeId) {
if (StrUtil.isBlank(nodeId)) {
return this;
}
this.node.setId(nodeId.trim());
return this;
}
public LiteFlowNodeBuilder setName(String name) {
if (StrUtil.isBlank(name)) {
return this;
}
this.node.setName(name.trim());
return this;
}
public LiteFlowNodeBuilder setName(String name) {
if (StrUtil.isBlank(name)) {
return this;
}
this.node.setName(name.trim());
return this;
}
public LiteFlowNodeBuilder setClazz(String clazz) {
if (StrUtil.isBlank(clazz)) {
return this;
}
this.node.setClazz(clazz.trim());
return this;
}
public LiteFlowNodeBuilder setClazz(String clazz) {
if (StrUtil.isBlank(clazz)) {
return this;
}
this.node.setClazz(clazz.trim());
return this;
}
public LiteFlowNodeBuilder setClazz(Class<?> clazz) {
assert clazz != null;
setClazz(clazz.getName());
return this;
}
public LiteFlowNodeBuilder setClazz(Class<?> clazz) {
assert clazz != null;
setClazz(clazz.getName());
return this;
}
public LiteFlowNodeBuilder setType(NodeTypeEnum type) {
this.node.setType(type);
return this;
}
public LiteFlowNodeBuilder setType(NodeTypeEnum type) {
this.node.setType(type);
return this;
}
public LiteFlowNodeBuilder setScript(String script) {
this.node.setScript(script);
return this;
}
public LiteFlowNodeBuilder setScript(String script) {
this.node.setScript(script);
return this;
}
public LiteFlowNodeBuilder setFile(String filePath) {
if (StrUtil.isBlank(filePath)) {
return this;
}
try {
List<String> scriptList = PathContentParserHolder.loadContextAware().parseContent(ListUtil.toList(filePath));
String script = CollUtil.getFirst(scriptList);
setScript(script);
public LiteFlowNodeBuilder setFile(String filePath) {
if (StrUtil.isBlank(filePath)) {
return this;
}
try {
List<String> scriptList = PathContentParserHolder.loadContextAware()
.parseContent(ListUtil.toList(filePath));
String script = CollUtil.getFirst(scriptList);
setScript(script);
// 添加脚本文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(ListUtil.toList(filePath));
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
} catch (Exception e) {
String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), e.getMessage());
throw new NodeBuildException(errMsg);
}
return this;
}
// 添加脚本文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware()
.getFileAbsolutePath(ListUtil.toList(filePath));
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
}
catch (Exception e) {
String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(),
e.getMessage());
throw new NodeBuildException(errMsg);
}
return this;
}
public LiteFlowNodeBuilder setLanguage(String language) {
this.node.setLanguage(language);
return this;
}
public LiteFlowNodeBuilder setLanguage(String language) {
this.node.setLanguage(language);
return this;
}
public void build() {
checkBuild();
try {
// 用于处理脚本 node
if (this.node.getType().isScript()){
FlowBus.addScriptNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getScript(), this.node.getLanguage());
}
// 用于处理普通 node
else{
FlowBus.addNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getClazz());
}
} catch (Exception e) {
String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), e.getMessage());
LOG.error(errMsg, e);
throw new NodeBuildException(errMsg);
}
}
public void build() {
checkBuild();
try {
// 用于处理脚本 node
if (this.node.getType().isScript()) {
FlowBus.addScriptNode(this.node.getId(), this.node.getName(), this.node.getType(),
this.node.getScript(), this.node.getLanguage());
}
// 用于处理普通 node
else {
FlowBus.addNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getClazz());
}
}
catch (Exception e) {
String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(),
e.getMessage());
LOG.error(errMsg, e);
throw new NodeBuildException(errMsg);
}
}
/**
* build 前简单校验
*/
private void checkBuild() {
List<String> errorList = new ArrayList<>();
if (StrUtil.isBlank(this.node.getId())) {
errorList.add("id is blank");
}
if (Objects.isNull(this.node.getType())) {
errorList.add("type is null");
}
if (CollUtil.isNotEmpty(errorList)) {
throw new NodeBuildException(CollUtil.join(errorList, ",", "[", "]"));
}
}
/**
* build 前简单校验
*/
private void checkBuild() {
List<String> errorList = new ArrayList<>();
if (StrUtil.isBlank(this.node.getId())) {
errorList.add("id is blank");
}
if (Objects.isNull(this.node.getType())) {
errorList.add("type is null");
}
if (CollUtil.isNotEmpty(errorList)) {
throw new NodeBuildException(CollUtil.join(errorList, ",", "[", "]"));
}
}
}

View File

@ -25,238 +25,245 @@ import java.util.List;
import java.util.Objects;
/**
* Chain基于代码形式的组装器
* EL表达式规则专属组装器
* Chain基于代码形式的组装器 EL表达式规则专属组装器
*
* @author Bryan.Zhang
* @since 2.8.0
*/
public class LiteFlowChainELBuilder {
private static final Logger LOG = LoggerFactory.getLogger(LiteFlowChainELBuilder.class);
private static final Logger LOG = LoggerFactory.getLogger(LiteFlowChainELBuilder.class);
private Chain chain;
private Chain chain;
/**
* //这是主体的Condition //声明这个变量而不是用chain.getConditionList的目的是为了辅助平滑加载
* //虽然FlowBus里面的map都是CopyOnWrite类型的但是在buildCondition的时候为了平滑加载所以不能事先把chain.getConditionList给设为空List
* //所以在这里做一个缓存等conditionList全部build完毕后再去一次性替换chain里面的conditionList
*/
private final List<Condition> conditionList;
/**
* //这是主体的Condition
* //声明这个变量而不是用chain.getConditionList的目的是为了辅助平滑加载
* //虽然FlowBus里面的map都是CopyOnWrite类型的但是在buildCondition的时候为了平滑加载所以不能事先把chain.getConditionList给设为空List
* //所以在这里做一个缓存等conditionList全部build完毕后再去一次性替换chain里面的conditionList
*/
private final List<Condition> conditionList;
/**
* EL解析引擎
*/
public final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner();
/**
* EL解析引擎
*/
public final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner();
static {
// 初始化QLExpress的Runner
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.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.addFunction(ChainConstant.ITERATOR, new IteratorOperator());
EXPRESS_RUNNER.addFunction(ChainConstant.CATCH, new CatchOperator());
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.DEFAULT, Object.class, new DefaultOperator());
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.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());
}
static {
//初始化QLExpress的Runner
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.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.addFunction(ChainConstant.ITERATOR, new IteratorOperator());
EXPRESS_RUNNER.addFunction(ChainConstant.CATCH, new CatchOperator());
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.DEFAULT, Object.class, new DefaultOperator());
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.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() {
return new LiteFlowChainELBuilder();
}
public static LiteFlowChainELBuilder createChain() {
return new LiteFlowChainELBuilder();
}
public LiteFlowChainELBuilder() {
chain = new Chain();
conditionList = new ArrayList<>();
}
public LiteFlowChainELBuilder() {
chain = new Chain();
conditionList = new ArrayList<>();
}
// 在parser中chain的build是2段式的因为涉及到依赖问题以前是递归parser
// 2.6.8之后取消了递归的模式两段式组装先把带有chainName的chain对象放进去第二段再组装chain里面的condition
// 所以这里setChainName的时候需要判断下
//在parser中chain的build是2段式的因为涉及到依赖问题以前是递归parser
//2.6.8之后取消了递归的模式两段式组装先把带有chainName的chain对象放进去第二段再组装chain里面的condition
//所以这里setChainName的时候需要判断下
/**
* @return LiteFlowChainELBuilder
* @deprecated 请使用 {@link #setChainId(String)}
*/
public LiteFlowChainELBuilder setChainName(String chainName) {
if (FlowBus.containChain(chainName)) {
this.chain = FlowBus.getChain(chainName);
}
else {
this.chain.setChainName(chainName);
}
return this;
}
/**
* @return LiteFlowChainELBuilder
* @deprecated 请使用 {@link #setChainId(String)}
*/
public LiteFlowChainELBuilder setChainName(String chainName) {
if (FlowBus.containChain(chainName)) {
this.chain = FlowBus.getChain(chainName);
} else {
this.chain.setChainName(chainName);
}
return this;
}
public LiteFlowChainELBuilder setChainId(String chainId) {
if (FlowBus.containChain(chainId)) {
this.chain = FlowBus.getChain(chainId);
}
else {
this.chain.setChainId(chainId);
}
return this;
}
public LiteFlowChainELBuilder setChainId(String chainId) {
if (FlowBus.containChain(chainId)) {
this.chain = FlowBus.getChain(chainId);
} else {
this.chain.setChainId(chainId);
}
return this;
}
public LiteFlowChainELBuilder setEL(String elStr) {
if (StrUtil.isBlank(elStr)) {
String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId());
throw new FlowSystemException(errMsg);
}
public LiteFlowChainELBuilder setEL(String elStr) {
if (StrUtil.isBlank(elStr)) {
String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId());
throw new FlowSystemException(errMsg);
}
List<String> errorList = new ArrayList<>();
try {
DefaultContext<String, Object> context = new DefaultContext<>();
List<String> errorList = new ArrayList<>();
try {
DefaultContext<String, Object> context = new DefaultContext<>();
// 这里一定要先放chain再放node因为node优先于chain所以当重名时node会覆盖掉chain
// 往上下文里放入所有的chain是的el表达式可以直接引用到chain
FlowBus.getChainMap().values().forEach(chain -> context.put(chain.getChainId(), chain));
//这里一定要先放chain再放node因为node优先于chain所以当重名时node会覆盖掉chain
//往上下文里放入所有的chain是的el表达式可以直接引用到chain
FlowBus.getChainMap().values().forEach(chain -> context.put(chain.getChainId(), chain));
// 往上下文里放入所有的node使得el表达式可以直接引用到nodeId
FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.getNode(nodeId)));
//往上下文里放入所有的node使得el表达式可以直接引用到nodeId
FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.getNode(nodeId)));
// 放入当前主chain的ID
context.put(ChainConstant.CURR_CHAIN_ID, this.chain.getChainId());
//放入当前主chain的ID
context.put(ChainConstant.CURR_CHAIN_ID, this.chain.getChainId());
// 解析el成为一个Condition
// 为什么这里只是一个Condition而不是一个List<Condition>
// 这里无论多复杂的外面必定有一个最外层的Condition所以这里只有一个内部可以嵌套很多层这点和以前的不太一样
Condition condition = (Condition) EXPRESS_RUNNER.execute(elStr, context, errorList, true, true);
//解析el成为一个Condition
//为什么这里只是一个Condition而不是一个List<Condition>
//这里无论多复杂的外面必定有一个最外层的Condition所以这里只有一个内部可以嵌套很多层这点和以前的不太一样
Condition condition = (Condition) EXPRESS_RUNNER.execute(elStr, context, errorList, true, true);
// 从condition的第一层嵌套结构里拿出Pre和Finally节点
// 为什么只寻找第一层而不往下寻找了呢
// 因为这是一个规范如果在后面的层级中出现pre和finally语义上也不好理解所以pre和finally只能定义在第一层
// 如果硬是要在后面定义则执行的时候会忽略相关代码已做了判断
/*
* for (Executable executable : condition.getExecutableList()) { if
* (executable instanceof PreCondition) {
* this.preConditionList.add((PreCondition) executable); } else if (executable
* instanceof FinallyCondition) {
* this.finallyConditionList.add((FinallyCondition) executable); } }
*/
//从condition的第一层嵌套结构里拿出Pre和Finally节点
//为什么只寻找第一层而不往下寻找了呢
//因为这是一个规范如果在后面的层级中出现pre和finally语义上也不好理解所以pre和finally只能定义在第一层
//如果硬是要在后面定义则执行的时候会忽略相关代码已做了判断
/*for (Executable executable : condition.getExecutableList()) {
if (executable instanceof PreCondition) {
this.preConditionList.add((PreCondition) executable);
} else if (executable instanceof FinallyCondition) {
this.finallyConditionList.add((FinallyCondition) executable);
}
}*/
// 把主要的condition加入
this.conditionList.add(condition);
return this;
}
catch (QLException e) {
// EL 底层会包装异常这里是曲线处理
if (Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) {
// 构建错误信息
String msg = buildDataNotFoundExceptionMsg(elStr);
throw new ELParseException(msg);
}
throw new ELParseException(e.getCause().getMessage());
}
catch (Exception e) {
throw new ELParseException(e.getMessage());
}
}
//把主要的condition加入
this.conditionList.add(condition);
return this;
} catch (QLException e) {
// EL 底层会包装异常这里是曲线处理
if (Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) {
// 构建错误信息
String msg = buildDataNotFoundExceptionMsg(elStr);
throw new ELParseException(msg);
}
throw new ELParseException(e.getCause().getMessage());
} catch (Exception e) {
throw new ELParseException(e.getMessage());
}
}
/**
* EL表达式校验
* @param elStr EL表达式
* @return true 校验成功 false 校验失败
*/
public static boolean validate(String elStr) {
try {
LiteFlowChainELBuilder.createChain().setEL(elStr);
return Boolean.TRUE;
}
catch (ELParseException e) {
LOG.error(e.getMessage());
}
return Boolean.FALSE;
}
/**
* EL表达式校验
*
* @param elStr EL表达式
* @return true 校验成功 false 校验失败
*/
public static boolean validate(String elStr) {
try {
LiteFlowChainELBuilder.createChain().setEL(elStr);
return Boolean.TRUE;
} catch (ELParseException e) {
LOG.error(e.getMessage());
}
return Boolean.FALSE;
}
public void build() {
this.chain.setConditionList(this.conditionList);
public void build() {
this.chain.setConditionList(this.conditionList);
checkBuild();
checkBuild();
FlowBus.addChain(this.chain);
}
FlowBus.addChain(this.chain);
}
// #region private method
//#region private method
/**
* build 前简单校验
*/
private void checkBuild() {
List<String> errorList = new ArrayList<>();
if (StrUtil.isBlank(this.chain.getChainId())) {
errorList.add("name is blank");
}
if (CollUtil.isNotEmpty(errorList)) {
throw new RuntimeException(CollUtil.join(errorList, ",", "[", "]"));
}
}
/**
* build 前简单校验
*/
private void checkBuild() {
List<String> errorList = new ArrayList<>();
if (StrUtil.isBlank(this.chain.getChainId())) {
errorList.add("name is blank");
}
if (CollUtil.isNotEmpty(errorList)) {
throw new RuntimeException(CollUtil.join(errorList, ",", "[", "]"));
}
}
/**
* 解析 EL 表达式查找未定义的 id 并构建错误信息
* @param elStr el 表达式
*/
private String buildDataNotFoundExceptionMsg(String elStr) {
String msg = String.format("[node/chain is not exist or node/chain not register]\n EL: %s",
StrUtil.trim(elStr));
try {
InstructionSet parseResult = EXPRESS_RUNNER.getInstructionSetFromLocalCache(elStr);
if (parseResult == null) {
return msg;
}
/**
* 解析 EL 表达式查找未定义的 id 并构建错误信息
*
* @param elStr el 表达式
*/
private String buildDataNotFoundExceptionMsg(String elStr) {
String msg = String.format("[node/chain is not exist or node/chain not register]\n EL: %s", StrUtil.trim(elStr));
try {
InstructionSet parseResult = EXPRESS_RUNNER.getInstructionSetFromLocalCache(elStr);
if (parseResult == null) {
return msg;
}
String[] outAttrNames = parseResult.getOutAttrNames();
if (ArrayUtil.isEmpty(outAttrNames)) {
return msg;
}
String[] outAttrNames = parseResult.getOutAttrNames();
if (ArrayUtil.isEmpty(outAttrNames)) {
return msg;
}
List<String> chainIds = CollUtil.map(FlowBus.getChainMap().values(), Chain::getChainId, true);
List<String> nodeIds = CollUtil.map(FlowBus.getNodeMap().values(), Node::getId, true);
for (String attrName : outAttrNames) {
if (!chainIds.contains(attrName) && !nodeIds.contains(attrName)) {
msg = String.format(
"[%s] is not exist or [%s] is not registered, you need to define a node or chain with id [%s] and register it \n EL: ",
attrName, attrName, attrName);
List<String> chainIds = CollUtil.map(FlowBus.getChainMap().values(), Chain::getChainId, true);
List<String> nodeIds = CollUtil.map(FlowBus.getNodeMap().values(), Node::getId, true);
for (String attrName : outAttrNames) {
if (!chainIds.contains(attrName) && !nodeIds.contains(attrName)) {
msg = String.format("[%s] is not exist or [%s] is not registered, you need to define a node or chain with id [%s] and register it \n EL: ", attrName, attrName, attrName);
// 去除 EL 表达式中的空格和换行符
String sourceEl = StrUtil.removeAll(elStr, CharUtil.SPACE, CharUtil.LF, CharUtil.CR);
// 这里需要注意的是nodeId chainId 可能是关键字的一部分如果直接 indexOf(attrName) 会出现误判
// 所以需要判断 attrName 前后是否有 ","
int commaRightIndex = sourceEl.indexOf(attrName + StrUtil.COMMA);
if (commaRightIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 "^" 的长度 1indexOf 0 开始所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaRightIndex + 6, true);
}
int commaLeftIndex = sourceEl.indexOf(StrUtil.COMMA + attrName);
if (commaLeftIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 "^" 的长度 1再加上 "," 的长度 1indexOf 0
// 开始所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 7, true);
}
// 还有一种特殊情况就是 EL 表达式中的节点使用 node("a")
int nodeIndex = sourceEl.indexOf(String.format("node(\"%s\")", attrName));
if (nodeIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 node("” 长度 6再加上 "^" 的长度 1indexOf 从 0
// 开始所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 12, true);
}
}
}
}
catch (Exception ex) {
// ignore
}
return msg;
}
// #endregion
// 去除 EL 表达式中的空格和换行符
String sourceEl = StrUtil.removeAll(elStr, CharUtil.SPACE, CharUtil.LF, CharUtil.CR);
// 这里需要注意的是nodeId chainId 可能是关键字的一部分如果直接 indexOf(attrName) 会出现误判
// 所以需要判断 attrName 前后是否有 ","
int commaRightIndex = sourceEl.indexOf(attrName + StrUtil.COMMA);
if (commaRightIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 "^" 的长度 1indexOf 0 开始所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaRightIndex + 6, true);
}
int commaLeftIndex = sourceEl.indexOf(StrUtil.COMMA + attrName);
if (commaLeftIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 "^" 的长度 1再加上 "," 的长度 1indexOf 0 开始所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 7, true);
}
// 还有一种特殊情况就是 EL 表达式中的节点使用 node("a")
int nodeIndex = sourceEl.indexOf(String.format("node(\"%s\")", attrName));
if (nodeIndex != -1) {
// 需要加上 "EL: " 的长度 4再加上 node("” 长度 6再加上 "^" 的长度 1indexOf 从 0 开始,所以还需要加 1
return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 12, true);
}
}
}
} catch (Exception ex) {
// ignore
}
return msg;
}
//#endregion
}

View File

@ -12,14 +12,15 @@ 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;
}
}

View File

@ -9,30 +9,30 @@ import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.element.condition.LoopCondition;
/**
* EL规则中的BREAK的操作符
* 有两种用法
* FOR...DO...BREAK
* WHILE...DO...BREAK
* EL规则中的BREAK的操作符 有两种用法 FOR...DO...BREAK WHILE...DO...BREAK
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public class BreakOperator extends BaseOperator<LoopCondition> {
@Override
public LoopCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
//DO关键字有可能用在FOR后面也有可能用于WHILE后面所以这里要进行判断是不是这两种类型的超类LoopCondition
String errorMsg = "The caller must be ForCondition or WhileCondition item";
LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg);
@Override
public LoopCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
// DO关键字有可能用在FOR后面也有可能用于WHILE后面所以这里要进行判断是不是这两种类型的超类LoopCondition
String errorMsg = "The caller must be ForCondition or WhileCondition item";
LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg);
// 获得需要执行的可执行表达式
Node breakNode = OperatorHelper.convert(objects[1], Node.class);
if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())) {
condition.setBreakNode(breakNode);
}
else {
throw new QLException("The parameter must be node-break item");
}
return condition;
}
//获得需要执行的可执行表达式
Node breakNode = OperatorHelper.convert(objects[1], Node.class);
if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())) {
condition.setBreakNode(breakNode);
} else {
throw new QLException("The parameter must be node-break item");
}
return condition;
}
}

View File

@ -6,21 +6,23 @@ import com.yomahub.liteflow.flow.element.Executable;
import com.yomahub.liteflow.flow.element.condition.CatchCondition;
/**
* EL规则中的CATCH的操作符
* 用法CATCH...DO...
* EL规则中的CATCH的操作符 用法CATCH...DO...
*
* @author Bryan.Zhang
* @since 2.10.0
*/
public class CatchOperator extends BaseOperator<CatchCondition> {
@Override
public CatchCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Executable catchItem = OperatorHelper.convert(objects[0], Executable.class);
@Override
public CatchCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
CatchCondition catchCondition = new CatchCondition();
catchCondition.setCatchItem(catchItem);
Executable catchItem = OperatorHelper.convert(objects[0], Executable.class);
CatchCondition catchCondition = new CatchCondition();
catchCondition.setCatchItem(catchItem);
return catchCondition;
}
return catchCondition;
}
}

View File

@ -12,16 +12,17 @@ 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;
}
}

View File

@ -13,15 +13,16 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition;
*/
public class DefaultOperator extends BaseOperator<SwitchCondition> {
@Override
public SwitchCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
@Override
public SwitchCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class);
SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class);
Executable target = OperatorHelper.convert(objects[1], Executable.class);
switchCondition.setDefaultExecutor(target);
Executable target = OperatorHelper.convert(objects[1], Executable.class);
switchCondition.setDefaultExecutor(target);
return switchCondition;
}
return switchCondition;
}
}

View File

@ -9,38 +9,38 @@ import com.yomahub.liteflow.flow.element.condition.Condition;
import com.yomahub.liteflow.flow.element.condition.LoopCondition;
/**
* EL规则中的DO的操作符
* 有三种用法
* FOR...DO...BREAK
* WHILE...DO...BREAK
* CATCH...DO
* EL规则中的DO的操作符 有三种用法 FOR...DO...BREAK WHILE...DO...BREAK CATCH...DO
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public class DoOperator extends BaseOperator<Condition> {
@Override
public Condition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
if (objects[0] instanceof CatchCondition){
String errorMsg = "The caller must be CatchCondition item";
CatchCondition condition = OperatorHelper.convert(objects[0], CatchCondition.class, errorMsg);
//获得需要执行的可执行表达式
Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
condition.setDoItem(doExecutableItem);
return condition;
}else if(objects[0] instanceof LoopCondition){
String errorMsg = "The caller must be LoopCondition item";
//DO关键字有可能用在FOR后面也有可能用于WHILE后面所以这里要进行判断是不是这两种类型的超类LoopCondition
LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg);
//获得需要执行的可执行表达式
Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
condition.setDoExecutor(doExecutableItem);
return condition;
}else{
String errorMsg = "The caller must be LoopCondition or CatchCondition item";
throw new QLException(errorMsg);
}
}
@Override
public Condition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqTwo(objects);
if (objects[0] instanceof CatchCondition) {
String errorMsg = "The caller must be CatchCondition item";
CatchCondition condition = OperatorHelper.convert(objects[0], CatchCondition.class, errorMsg);
// 获得需要执行的可执行表达式
Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
condition.setDoItem(doExecutableItem);
return condition;
}
else if (objects[0] instanceof LoopCondition) {
String errorMsg = "The caller must be LoopCondition item";
// DO关键字有可能用在FOR后面也有可能用于WHILE后面所以这里要进行判断是不是这两种类型的超类LoopCondition
LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg);
// 获得需要执行的可执行表达式
Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class);
condition.setDoExecutor(doExecutableItem);
return condition;
}
else {
String errorMsg = "The caller must be LoopCondition or CatchCondition item";
throw new QLException(errorMsg);
}
}
}

View File

@ -21,35 +21,37 @@ public class ElifOperator extends BaseOperator<IfCondition> {
public IfCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEqThree(objects);
//解析caller
// 解析caller
IfCondition ifCondition = OperatorHelper.convert(objects[0], IfCondition.class);
//解析第一个参数
// 解析第一个参数
Node ifNode = OperatorHelper.convert(objects[1], 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[2], Executable.class);
//构建一个内部的IfCondition
// 构建一个内部的IfCondition
IfCondition ifConditionItem = new IfCondition();
ifConditionItem.setIfNode(ifNode);
ifConditionItem.setTrueCaseExecutableItem(trueCaseExecutableItem);
//因为可能会有多个ELIF所以每一次拿到的caller总是最开始大的if需要遍历到没有falseCaseExecutable的地方
//塞进去是一个新的IfCondition
// 因为可能会有多个ELIF所以每一次拿到的caller总是最开始大的if需要遍历到没有falseCaseExecutable的地方
// 塞进去是一个新的IfCondition
IfCondition loopIfCondition = ifCondition;
while (true) {
if (loopIfCondition.getFalseCaseExecutableItem() == null) {
loopIfCondition.setFalseCaseExecutableItem(ifConditionItem);
break;
} else {
}
else {
loopIfCondition = (IfCondition) loopIfCondition.getFalseCaseExecutableItem();
}
}
return ifCondition;
}
}

View File

@ -30,11 +30,13 @@ public class ElseOperator extends BaseOperator<IfCondition> {
if (loopIfCondition.getFalseCaseExecutableItem() == null) {
loopIfCondition.setFalseCaseExecutableItem(elseExecutableItem);
break;
} else {
}
else {
loopIfCondition = (IfCondition) loopIfCondition.getFalseCaseExecutableItem();
}
}
return ifCondition;
}
}

View File

@ -24,4 +24,5 @@ public class FinallyOperator extends BaseOperator<FinallyCondition> {
}
return finallyCondition;
}
}

View File

@ -19,34 +19,38 @@ import com.yomahub.liteflow.flow.element.condition.ForCondition;
* @since 2.9.0
*/
public class ForOperator extends BaseOperator<ForCondition> {
@Override
public ForCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Node node;
if (objects[0] instanceof Node) {
node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.FOR, NodeTypeEnum.FOR_SCRIPT).contains(node.getType())) {
throw new QLException("The parameter must be for-node item");
}
}else if(objects[0] instanceof Integer){
Integer forCount = OperatorHelper.convert(objects[0], Integer.class);
node = new Node();
NodeForComponent nodeForComponent = new NodeForComponent() {
@Override
public int processFor() {
return forCount;
}
};
nodeForComponent.setSelf(nodeForComponent);
nodeForComponent.setNodeId(StrUtil.format("LOOP_{}", forCount));
node.setInstance(nodeForComponent);
}else{
throw new QLException("The parameter must be Node item");
}
@Override
public ForCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Node node;
if (objects[0] instanceof Node) {
node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.FOR, NodeTypeEnum.FOR_SCRIPT).contains(node.getType())) {
throw new QLException("The parameter must be for-node item");
}
}
else if (objects[0] instanceof Integer) {
Integer forCount = OperatorHelper.convert(objects[0], Integer.class);
node = new Node();
NodeForComponent nodeForComponent = new NodeForComponent() {
@Override
public int processFor() {
return forCount;
}
};
nodeForComponent.setSelf(nodeForComponent);
nodeForComponent.setNodeId(StrUtil.format("LOOP_{}", forCount));
node.setInstance(nodeForComponent);
}
else {
throw new QLException("The parameter must be Node item");
}
ForCondition forCondition = new ForCondition();
forCondition.setForNode(node);
return forCondition;
}
ForCondition forCondition = new ForCondition();
forCondition.setForNode(node);
return forCondition;
}
}

View File

@ -12,16 +12,17 @@ import com.yomahub.liteflow.flow.element.condition.Condition;
*/
public class IdOperator extends BaseOperator<Condition> {
@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;
}
}

View File

@ -17,29 +17,30 @@ 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.setIfNode(ifNode);
ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem);
ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem);
return ifCondition;
}
IfCondition ifCondition = new IfCondition();
ifCondition.setIfNode(ifNode);
ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem);
ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem);
return ifCondition;
}
}

View File

@ -24,4 +24,5 @@ public class IgnoreErrorOperator extends BaseOperator<WhenCondition> {
return condition;
}
}

View File

@ -9,18 +9,20 @@ import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.element.condition.IteratorCondition;
public class IteratorOperator extends BaseOperator<IteratorCondition> {
@Override
public IteratorCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Node node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.ITERATOR).contains(node.getType())) {
throw new QLException("The parameter must be iterator-node item");
}
@Override
public IteratorCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
IteratorCondition iteratorCondition = new IteratorCondition();
iteratorCondition.setIteratorNode(node);
Node node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.ITERATOR).contains(node.getType())) {
throw new QLException("The parameter must be iterator-node item");
}
IteratorCondition iteratorCondition = new IteratorCondition();
iteratorCondition.setIteratorNode(node);
return iteratorCondition;
}
return iteratorCondition;
}
}

View File

@ -26,21 +26,33 @@ public class NodeOperator extends BaseOperator<Node> {
if (FlowBus.containNode(nodeId)) {
return FlowBus.getNode(nodeId);
} else {
}
else {
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (StrUtil.isNotBlank(liteflowConfig.getSubstituteCmpClass())) {
Node substituteNode = FlowBus.getNodeMap().values().stream().filter(node
-> node.getInstance().getClass().getName().equals(liteflowConfig.getSubstituteCmpClass())).findFirst().orElse(null);
Node substituteNode = FlowBus.getNodeMap()
.values()
.stream()
.filter(node -> node.getInstance()
.getClass()
.getName()
.equals(liteflowConfig.getSubstituteCmpClass()))
.findFirst()
.orElse(null);
if (ObjectUtil.isNotNull(substituteNode)) {
return substituteNode;
} else {
}
else {
String error = StrUtil.format("This node[{}] cannot be found", nodeId);
throw new QLException(error);
}
} else {
String error = StrUtil.format("This node[{}] cannot be found, or you can configure an substitute node", nodeId);
}
else {
String error = StrUtil.format("This node[{}] cannot be found, or you can configure an substitute node",
nodeId);
throw new QLException(error);
}
}
}
}

View File

@ -13,14 +13,15 @@ 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;
}
}

View File

@ -30,4 +30,5 @@ public class SwitchOperator extends BaseOperator<SwitchCondition> {
return switchCondition;
}
}

View File

@ -26,4 +26,5 @@ public class TagOperator extends BaseOperator<Node> {
return node;
}
}

View File

@ -13,14 +13,15 @@ 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;
}
}

View File

@ -12,14 +12,15 @@ 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;
}
}

View File

@ -13,16 +13,17 @@ 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;
}
}

View File

@ -7,19 +7,21 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition;
/**
* EL规则中的WHEN的操作符
*
* @author Bryan.Zhang
* @since 2.8.0
*/
public class WhenOperator extends BaseOperator<WhenCondition> {
@Override
public WhenCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeGtZero(objects);
@Override
public WhenCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeGtZero(objects);
WhenCondition whenCondition = new WhenCondition();
for (Object obj : objects) {
whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
}
return whenCondition;
}
WhenCondition whenCondition = new WhenCondition();
for (Object obj : objects) {
whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class));
}
return whenCondition;
}
}

View File

@ -15,17 +15,19 @@ import com.yomahub.liteflow.flow.element.condition.WhileCondition;
* @since 2.9.0
*/
public class WhileOperator extends BaseOperator<WhileCondition> {
@Override
public WhileCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Node node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.WHILE, NodeTypeEnum.WHILE_SCRIPT).contains(node.getType())) {
throw new QLException("The parameter must be while-node item");
}
@Override
public WhileCondition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeEq(objects, 1);
Node node = OperatorHelper.convert(objects[0], Node.class);
if (!ListUtil.toList(NodeTypeEnum.WHILE, NodeTypeEnum.WHILE_SCRIPT).contains(node.getType())) {
throw new QLException("The parameter must be while-node item");
}
WhileCondition whileCondition = new WhileCondition();
whileCondition.setWhileNode(node);
return whileCondition;
}
WhileCondition whileCondition = new WhileCondition();
whileCondition.setWhileNode(node);
return whileCondition;
}
}

View File

@ -13,25 +13,27 @@ import com.yomahub.liteflow.flow.element.Executable;
*/
public abstract class BaseOperator<T extends Executable> extends Operator {
@Override
public T executeInner(Object[] objects) throws Exception {
try {
// 检查 node chain 是否已经注册
OperatorHelper.checkNodeAndChainExist(objects);
return build(objects);
} catch (QLException e) {
throw e;
} catch (Exception e) {
throw new ELParseException("errors occurred in EL parsing");
}
}
@Override
public T executeInner(Object[] objects) throws Exception {
try {
// 检查 node chain 是否已经注册
OperatorHelper.checkNodeAndChainExist(objects);
return build(objects);
}
catch (QLException e) {
throw e;
}
catch (Exception e) {
throw new ELParseException("errors occurred in EL parsing");
}
}
/**
* 构建 EL 条件
* @param objects objects
* @return Condition
* @throws Exception Exception
*/
public abstract T build(Object[] objects) throws Exception;
/**
* 构建 EL 条件
*
* @param objects objects
* @return Condition
* @throws Exception Exception
*/
public abstract T build(Object[] objects) throws Exception;
}

View File

@ -15,149 +15,140 @@ import java.util.Objects;
*/
public class OperatorHelper {
/**
* 检查参数数量不等于1
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeNeqOne(Object[] objects) throws QLException {
checkObjectSizeNeq(objects, 1);
}
/**
* 检查参数数量不等于1
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeNeqOne(Object[] objects) throws QLException {
checkObjectSizeNeq(objects, 1);
}
/**
* 检查参数数量不等于 size
*
* @param objects objects
* @param size 参数数量
* @throws QLException QLException
*/
public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length != size) {
throw new QLException("parameter error");
}
}
/**
* 检查参数数量不等于 size
* @param objects objects
* @param size 参数数量
* @throws QLException QLException
*/
public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length != size) {
throw new QLException("parameter error");
}
}
/**
* 检查参数数量大于 0
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeGtZero(Object[] objects) throws QLException {
if (objects.length == 0) {
throw new QLException("parameter is empty");
}
}
/**
* 检查参数数量大于 0
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeGtZero(Object[] objects) throws QLException {
if (objects.length == 0) {
throw new QLException("parameter is empty");
}
}
/**
* 检查参数数量大于 2
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeGtTwo(Object[] objects) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length <= 1) {
throw new QLException("parameter error");
}
}
/**
* 检查参数数量大于 2
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeGtTwo(Object[] objects) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length <= 1) {
throw new QLException("parameter error");
}
}
/**
* 检查参数数量等于 2
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeEqTwo(Object[] objects) throws QLException {
checkObjectSizeEq(objects, 2);
}
/**
* 检查参数数量等于 2
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeEqTwo(Object[] objects) throws QLException {
checkObjectSizeEq(objects, 2);
}
/**
* 检查参数数量等于 3
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeEqThree(Object[] objects) throws QLException {
checkObjectSizeEq(objects, 3);
}
/**
* 检查参数数量等于 3
* @param objects objects
* @throws QLException QLException
*/
public static void checkObjectSizeEqThree(Object[] objects) throws QLException {
checkObjectSizeEq(objects, 3);
}
/**
* 检查参数数量等于 size
*
* @param objects objects
* @param size 参数数量
* @throws QLException QLException
*/
public static void checkObjectSizeEq(Object[] objects, int size) throws QLException {
checkObjectSizeGtZero(objects);
/**
* 检查参数数量等于 size
* @param objects objects
* @param size 参数数量
* @throws QLException QLException
*/
public static void checkObjectSizeEq(Object[] objects, int size) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length != size) {
throw new QLException("parameter error");
}
}
if (objects.length != size) {
throw new QLException("parameter error");
}
}
/**
* 检查参数数量等于 size1 size2
*
* @param objects objects
* @param size1 参数数量1
* @param size2 参数数量2
* @throws QLException QLException
*/
public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException {
checkObjectSizeGtZero(objects);
/**
* 检查参数数量等于 size1 size2
* @param objects objects
* @param size1 参数数量1
* @param size2 参数数量2
* @throws QLException QLException
*/
public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException {
checkObjectSizeGtZero(objects);
if (objects.length != size1 && objects.length != size2) {
throw new QLException("parameter error");
}
}
if (objects.length != size1 && objects.length != size2) {
throw new QLException("parameter error");
}
}
/**
* 转换 object 为指定的类型
* 如果是Node类型的则进行copy
* 为什么要进行copy呢因为原先的Node都是存放在FlowBus的NodeMap中的有些属性在EL中不是全局的属于当前这个chain的
* 所以要进行copy动作
*/
public static <T> T convert(Object object, Class<T> clazz) throws QLException {
String errorMsg = StrUtil.format("The parameter must be {} item", clazz.getSimpleName());
return convert(object, clazz, errorMsg);
}
/**
* 转换 object 为指定的类型 如果是Node类型的则进行copy
* 为什么要进行copy呢因为原先的Node都是存放在FlowBus的NodeMap中的有些属性在EL中不是全局的属于当前这个chain的 所以要进行copy动作
*/
public static <T> T convert(Object object, Class<T> clazz) throws QLException {
String errorMsg = StrUtil.format("The parameter must be {} item", clazz.getSimpleName());
return convert(object, clazz, errorMsg);
}
/**
* 转换 object 为指定的类型,自定义错误信息
* 如果是Node类型的则进行copy
*/
public static <T> T convert(Object object, Class<T> clazz, String errorMsg) throws QLException {
try {
if (clazz.isAssignableFrom(object.getClass())) {
if (clazz.equals(Node.class)) {
Node node = (Node) object;
return (T) node.copy();
} else {
return (T) object;
}
}
} catch (Exception e) {
throw new QLException("An error occurred while copying an object");
}
/**
* 转换 object 为指定的类型,自定义错误信息 如果是Node类型的则进行copy
*/
public static <T> T convert(Object object, Class<T> clazz, String errorMsg) throws QLException {
try {
if (clazz.isAssignableFrom(object.getClass())) {
if (clazz.equals(Node.class)) {
Node node = (Node) object;
return (T) node.copy();
}
else {
return (T) object;
}
}
}
catch (Exception e) {
throw new QLException("An error occurred while copying an object");
}
throw new QLException(errorMsg);
}
throw new QLException(errorMsg);
}
/**
* 检查 node chain 是否已经注册
* @param objects objects
* @throws QLException QLException
*/
public static void checkNodeAndChainExist(Object[] objects) throws QLException {
for (Object object : objects) {
if (Objects.isNull(object)) {
throw new QLException(DataNotFoundException.MSG);
}
}
}
/**
* 检查 node chain 是否已经注册
*
* @param objects objects
* @throws QLException QLException
*/
public static void checkNodeAndChainExist(Object[] objects) throws QLException {
for (Object object : objects) {
if (Objects.isNull(object)) {
throw new QLException(DataNotFoundException.MSG);
}
}
}
}

View File

@ -90,4 +90,5 @@ public class ChainPropBean {
this.conditionType = conditionType;
return this;
}
}

View File

@ -102,4 +102,5 @@ public class NodePropBean {
this.language = language;
return this;
}
}

View File

@ -7,71 +7,72 @@ package com.yomahub.liteflow.common;
*/
public interface ChainConstant {
String CHAIN = "chain";
String CHAIN = "chain";
String FLOW = "flow";
String FLOW = "flow";
String NODES = "nodes";
String NODES = "nodes";
String NODE = "node";
String NODE = "node";
String ID = "id";
String ID = "id";
String _CLASS = "class";
String _CLASS = "class";
String FILE = "file";
String FILE = "file";
String NAME = "name";
String NAME = "name";
String LANGUAGE = "language";
String LANGUAGE = "language";
String VALUE = "value";
String VALUE = "value";
String ANY = "any";
String ANY = "any";
String TYPE = "type";
String TYPE = "type";
String THEN = "THEN";
String THEN = "THEN";
String WHEN = "WHEN";
String WHEN = "WHEN";
String SWITCH = "SWITCH";
String SWITCH = "SWITCH";
String PRE = "PRE";
String PRE = "PRE";
String FINALLY = "FINALLY";
String FINALLY = "FINALLY";
String IF = "IF";
String IF = "IF";
String ELSE = "ELSE";
String ELSE = "ELSE";
String ELIF = "ELIF";
String ELIF = "ELIF";
String TO = "TO";
String TO = "TO";
String TAG = "tag";
String TAG = "tag";
String IGNORE_ERROR = "ignoreError";
String IGNORE_ERROR = "ignoreError";
String THREAD_POOL = "threadPool";
String THREAD_POOL = "threadPool";
String WHILE = "WHILE";
String WHILE = "WHILE";
String FOR = "FOR";
String FOR = "FOR";
String DO = "DO";
String DO = "DO";
String BREAK = "BREAK";
String BREAK = "BREAK";
String DATA = "data";
String DATA = "data";
String ITERATOR = "ITERATOR";
String ITERATOR = "ITERATOR";
String MONITOR_BUS = "monitorBus";
String MONITOR_BUS = "monitorBus";
String CURR_CHAIN_ID = "currChainId";
String CURR_CHAIN_ID = "currChainId";
String DEFAULT = "DEFAULT";
String DEFAULT = "DEFAULT";
String CATCH = "CATCH";
String CATCH = "CATCH";
}

View File

@ -4,5 +4,7 @@ package com.yomahub.liteflow.common;
* @author Yun
*/
public class LocalDefaultFlowConstant {
public static final String DEFAULT="default";
public static final String DEFAULT = "default";
}

View File

@ -6,18 +6,20 @@ import java.lang.annotation.*;
/**
* 用于标注上下文bean的别名以便在脚本或者组件中通过别名来获取上下文对象
*
* @since 2.9.7
* @author Tingliang Wang
*/
@Target({ElementType.TYPE})
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface ContextBean {
@AliasFor("name")
String value() default "";
@AliasFor("value")
String name() default "";
@AliasFor("name")
String value() default "";
@AliasFor("value")
String name() default "";
}

View File

@ -21,57 +21,61 @@ import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder;
*/
public class ComponentInitializer {
private static ComponentInitializer instance;
private static ComponentInitializer instance;
public static ComponentInitializer loadInstance() {
if (ObjectUtil.isNull(instance)) {
instance = new ComponentInitializer();
}
return 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) {
nodeComponent.setNodeId(nodeId);
nodeComponent.setSelf(nodeComponent);
nodeComponent.setType(type);
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(ChainConstant.MONITOR_BUS)) {
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
if (ObjectUtil.isNotNull(monitorBus)) {
nodeComponent.setMonitorBus(monitorBus);
}
}
// 设置MonitorBus如果没有就不注入
if (ContextAwareHolder.loadContextAware().hasBean(ChainConstant.MONITOR_BUS)) {
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
if (ObjectUtil.isNotNull(monitorBus)) {
nodeComponent.setMonitorBus(monitorBus);
}
}
//先取传进来的name值(配置文件中配置的)再看有没有配置@LiteflowComponent标注
//@LiteflowComponent标注只在spring体系下生效这里用了spi机制取到相应环境下的实现类
nodeComponent.setName(name);
if (!type.isScript() && StrUtil.isBlank(nodeComponent.getName())) {
nodeComponent.setName(LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(nodeComponent));
}
// 先取传进来的name值(配置文件中配置的)再看有没有配置@LiteflowComponent标注
// @LiteflowComponent标注只在spring体系下生效这里用了spi机制取到相应环境下的实现类
nodeComponent.setName(name);
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);
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (liteFlowRetryAnnotation != null) {
nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry());
nodeComponent.setRetryForExceptions(liteFlowRetryAnnotation.forExceptions());
} else {
nodeComponent.setRetryCount(liteflowConfig.getRetryCount());
}
nodeComponent.setNodeExecutorClass(buildNodeExecutorClass(liteflowConfig));
// 先从组件上取@RetryCount标注如果没有则看全局配置全局配置如果不配置的话默认是0
// 默认retryForExceptions为Exception.class
LiteflowRetry liteFlowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class);
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (liteFlowRetryAnnotation != null) {
nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry());
nodeComponent.setRetryForExceptions(liteFlowRetryAnnotation.forExceptions());
}
else {
nodeComponent.setRetryCount(liteflowConfig.getRetryCount());
}
nodeComponent.setNodeExecutorClass(buildNodeExecutorClass(liteflowConfig));
return nodeComponent;
}
return nodeComponent;
}
private Class<? extends NodeExecutor> buildNodeExecutorClass(LiteflowConfig liteflowConfig) {
Class<?> nodeExecutorClass;
try {
nodeExecutorClass = Class.forName(liteflowConfig.getNodeExecutorClass());
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
}
return (Class<? extends NodeExecutor>) nodeExecutorClass;
}
private Class<? extends NodeExecutor> buildNodeExecutorClass(LiteflowConfig liteflowConfig) {
Class<?> nodeExecutorClass;
try {
nodeExecutorClass = Class.forName(liteflowConfig.getNodeExecutorClass());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
}
return (Class<? extends NodeExecutor>) nodeExecutorClass;
}
}

View File

@ -43,379 +43,399 @@ import java.util.concurrent.Future;
*/
public class FlowExecutor {
private static final Logger LOG = LoggerFactory.getLogger(FlowExecutor.class);
private static final Logger LOG = LoggerFactory.getLogger(FlowExecutor.class);
private static final String PREFIX_FORMAT_CONFIG_REGEX = "xml:|json:|yml:|el_xml:|el_json:|el_yml:";
private static final String PREFIX_FORMAT_CONFIG_REGEX = "xml:|json:|yml:|el_xml:|el_json:|el_yml:";
private LiteflowConfig liteflowConfig;
private LiteflowConfig liteflowConfig;
public FlowExecutor() {
//设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到
FlowExecutorHolder.setHolder(this);
//初始化DataBus
DataBus.init();
}
public FlowExecutor() {
// 设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到
FlowExecutorHolder.setHolder(this);
// 初始化DataBus
DataBus.init();
}
public FlowExecutor(LiteflowConfig liteflowConfig) {
this.liteflowConfig = liteflowConfig;
//把liteFlowConfig设到LiteFlowGetter中去
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
//设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到
FlowExecutorHolder.setHolder(this);
if (BooleanUtil.isTrue(liteflowConfig.isParseOnStart())) {
this.init(true);
}
//初始化DataBus
DataBus.init();
}
public FlowExecutor(LiteflowConfig liteflowConfig) {
this.liteflowConfig = liteflowConfig;
// 把liteFlowConfig设到LiteFlowGetter中去
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
// 设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到
FlowExecutorHolder.setHolder(this);
if (BooleanUtil.isTrue(liteflowConfig.isParseOnStart())) {
this.init(true);
}
// 初始化DataBus
DataBus.init();
}
/**
* FlowExecutor的初始化化方式主要用于parse规则文件
*/
public void init(boolean hook) {
if (ObjectUtil.isNull(liteflowConfig)) {
throw new ConfigErrorException("config error, please check liteflow config property");
}
/**
* FlowExecutor的初始化化方式主要用于parse规则文件
*/
public void init(boolean hook) {
if (ObjectUtil.isNull(liteflowConfig)) {
throw new ConfigErrorException("config error, please check liteflow config property");
}
//在相应的环境下进行节点的初始化工作
//在spring体系下会获得spring扫描后的节点接入元数据
//在非spring体系下是一个空实现等于不做此步骤
ContextCmpInitHolder.loadContextCmpInit().initCmp();
// 在相应的环境下进行节点的初始化工作
// 在spring体系下会获得spring扫描后的节点接入元数据
// 在非spring体系下是一个空实现等于不做此步骤
ContextCmpInitHolder.loadContextCmpInit().initCmp();
//进行id生成器的初始化
IdGeneratorHolder.init();
// 进行id生成器的初始化
IdGeneratorHolder.init();
String ruleSource = liteflowConfig.getRuleSource();
if (StrUtil.isBlank(ruleSource)) {
//查看有没有Parser的SPI实现
//所有的Parser的SPI实现都是以custom形式放入的且只支持xml形式
ServiceLoader<ParserClassNameSpi> loader = ServiceLoader.load(ParserClassNameSpi.class);
Iterator<ParserClassNameSpi> it = loader.iterator();
if (it.hasNext()) {
ParserClassNameSpi parserClassNameSpi = it.next();
ruleSource = "el_xml:" + parserClassNameSpi.getSpiClassName();
liteflowConfig.setRuleSource(ruleSource);
} else {
//ruleSource为空而且没有spi形式的扩展那么说明真的没有ruleSource
//这种情况有可能是基于代码动态构建的
return;
}
}
String ruleSource = liteflowConfig.getRuleSource();
if (StrUtil.isBlank(ruleSource)) {
// 查看有没有Parser的SPI实现
// 所有的Parser的SPI实现都是以custom形式放入的且只支持xml形式
ServiceLoader<ParserClassNameSpi> loader = ServiceLoader.load(ParserClassNameSpi.class);
Iterator<ParserClassNameSpi> it = loader.iterator();
if (it.hasNext()) {
ParserClassNameSpi parserClassNameSpi = it.next();
ruleSource = "el_xml:" + parserClassNameSpi.getSpiClassName();
liteflowConfig.setRuleSource(ruleSource);
}
else {
// ruleSource为空而且没有spi形式的扩展那么说明真的没有ruleSource
// 这种情况有可能是基于代码动态构建的
return;
}
}
//如果有前缀的则不需要再进行分割了说明是一个整体
//如果没有前缀说明是本地文件可能配置多个所以需要分割
List<String> sourceRulePathList;
if (ReUtil.contains(PREFIX_FORMAT_CONFIG_REGEX, ruleSource)) {
sourceRulePathList = ListUtil.toList(ruleSource);
} else {
String afterHandleRuleSource = ruleSource.replace(StrUtil.SPACE, StrUtil.EMPTY);
sourceRulePathList = ListUtil.toList(afterHandleRuleSource.split(",|;"));
}
// 如果有前缀的则不需要再进行分割了说明是一个整体
// 如果没有前缀说明是本地文件可能配置多个所以需要分割
List<String> sourceRulePathList;
if (ReUtil.contains(PREFIX_FORMAT_CONFIG_REGEX, ruleSource)) {
sourceRulePathList = ListUtil.toList(ruleSource);
}
else {
String afterHandleRuleSource = ruleSource.replace(StrUtil.SPACE, StrUtil.EMPTY);
sourceRulePathList = ListUtil.toList(afterHandleRuleSource.split(",|;"));
}
FlowParser parser = null;
Set<String> parserNameSet = new HashSet<>();
List<String> rulePathList = new ArrayList<>();
for (String path : sourceRulePathList) {
try {
// 查找对应的解析器
parser = FlowParserProvider.lookup(path);
parserNameSet.add(parser.getClass().getName());
// 替换掉前缀标识xml:/json:保留剩下的完整地址
path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, "");
rulePathList.add(path);
FlowParser parser = null;
Set<String> parserNameSet = new HashSet<>();
List<String> rulePathList = new ArrayList<>();
for (String path : sourceRulePathList) {
try {
// 查找对应的解析器
parser = FlowParserProvider.lookup(path);
parserNameSet.add(parser.getClass().getName());
// 替换掉前缀标识xml:/json:保留剩下的完整地址
path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, "");
rulePathList.add(path);
//支持多类型的配置文件分别解析
if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) {
// 解析文件
parser.parseMain(ListUtil.toList(path));
}
} catch (CyclicDependencyException e) {
LOG.error(e.getMessage());
throw e;
} catch (Exception e) {
String errorMsg = StrUtil.format("init flow executor cause error for path {},reason:{}", path, e.getMessage());
LOG.error(e.getMessage(), e);
throw new FlowExecutorNotInitException(errorMsg);
}
}
// 支持多类型的配置文件分别解析
if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) {
// 解析文件
parser.parseMain(ListUtil.toList(path));
}
}
catch (CyclicDependencyException e) {
LOG.error(e.getMessage());
throw e;
}
catch (Exception e) {
String errorMsg = StrUtil.format("init flow executor cause error for path {},reason:{}", path,
e.getMessage());
LOG.error(e.getMessage(), e);
throw new FlowExecutorNotInitException(errorMsg);
}
}
//单类型的配置文件需要一起解析
if (BooleanUtil.isFalse(liteflowConfig.isSupportMultipleType())) {
//检查Parser是否只有一个因为多个不同的parser会造成子流程的混乱
if (parserNameSet.size() > 1) {
String errorMsg = "cannot have multiple different parsers";
LOG.error(errorMsg);
throw new MultipleParsersException(errorMsg);
}
// 单类型的配置文件需要一起解析
if (BooleanUtil.isFalse(liteflowConfig.isSupportMultipleType())) {
// 检查Parser是否只有一个因为多个不同的parser会造成子流程的混乱
if (parserNameSet.size() > 1) {
String errorMsg = "cannot have multiple different parsers";
LOG.error(errorMsg);
throw new MultipleParsersException(errorMsg);
}
//进行多个配置文件的一起解析
try {
if (parser != null) {
// 解析文件
parser.parseMain(rulePathList);
} else {
throw new ConfigErrorException("parse error, please check liteflow config property");
}
} catch (CyclicDependencyException e) {
LOG.error(e.getMessage(), e);
LOG.error(e.getMessage());
throw e;
} catch (ChainDuplicateException e) {
LOG.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
String errorMsg = StrUtil.format("init flow executor cause error for path {},reason: {}", rulePathList, e.getMessage());
LOG.error(e.getMessage(), e);
throw new FlowExecutorNotInitException(errorMsg);
}
}
// 进行多个配置文件的一起解析
try {
if (parser != null) {
// 解析文件
parser.parseMain(rulePathList);
}
else {
throw new ConfigErrorException("parse error, please check liteflow config property");
}
}
catch (CyclicDependencyException e) {
LOG.error(e.getMessage(), e);
LOG.error(e.getMessage());
throw e;
}
catch (ChainDuplicateException e) {
LOG.error(e.getMessage(), e);
throw e;
}
catch (Exception e) {
String errorMsg = StrUtil.format("init flow executor cause error for path {},reason: {}", rulePathList,
e.getMessage());
LOG.error(e.getMessage(), e);
throw new FlowExecutorNotInitException(errorMsg);
}
}
//如果是ruleSource方式的最后判断下有没有解析出来,如果没有解析出来则报错
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData()) && MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())) {
if (FlowBus.getChainMap().isEmpty()) {
String errMsg = StrUtil.format("no valid rule config found in rule path [{}]", liteflowConfig.getRuleSource());
throw new ConfigErrorException(errMsg);
}
}
// 如果是ruleSource方式的最后判断下有没有解析出来,如果没有解析出来则报错
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())
&& MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())) {
if (FlowBus.getChainMap().isEmpty()) {
String errMsg = StrUtil.format("no valid rule config found in rule path [{}]",
liteflowConfig.getRuleSource());
throw new ConfigErrorException(errMsg);
}
}
//执行钩子
if (hook) {
FlowInitHook.executeHook();
}
// 执行钩子
if (hook) {
FlowInitHook.executeHook();
}
// 文件监听
if (liteflowConfig.getEnableMonitorFile()) {
try{
addMonitorFilePaths(rulePathList);
MonitorFile.getInstance().create();
}catch (Exception e){
String errMsg = StrUtil.format("file monitor init error for path:{}", rulePathList);
throw new MonitorFileInitErrorException(errMsg);
}
// 文件监听
if (liteflowConfig.getEnableMonitorFile()) {
try {
addMonitorFilePaths(rulePathList);
MonitorFile.getInstance().create();
}
catch (Exception e) {
String errMsg = StrUtil.format("file monitor init error for path:{}", rulePathList);
throw new MonitorFileInitErrorException(errMsg);
}
}
}
}
}
//此方法就是从原有的配置源主动拉取新的进行刷新
//和FlowBus.refreshFlowMetaData的区别就是一个为主动拉取一个为被动监听到新的内容进行刷新
public void reloadRule() {
long start = System.currentTimeMillis();
init(false);
LOG.info("reload rules takes {}ms", System.currentTimeMillis() - start);
}
// 此方法就是从原有的配置源主动拉取新的进行刷新
// 和FlowBus.refreshFlowMetaData的区别就是一个为主动拉取一个为被动监听到新的内容进行刷新
public void reloadRule() {
long start = System.currentTimeMillis();
init(false);
LOG.info("reload rules takes {}ms", System.currentTimeMillis() - start);
}
//隐式流程的调用方法
@Deprecated
public void invoke(String chainId, Object param, Integer slotIndex) throws Exception {
LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC);
if (!response.isSuccess()) {
throw response.getCause();
}
}
// 隐式流程的调用方法
@Deprecated
public void invoke(String chainId, Object param, Integer slotIndex) throws Exception {
LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC);
if (!response.isSuccess()) {
throw response.getCause();
}
}
@Deprecated
public void invokeInAsync(String chainId, Object param, Integer slotIndex) throws Exception {
LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC);
if (!response.isSuccess()) {
throw response.getCause();
}
}
@Deprecated
public void invokeInAsync(String chainId, Object param, Integer slotIndex) throws Exception {
LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC);
if (!response.isSuccess()) {
throw response.getCause();
}
}
public LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex) {
return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC);
}
public LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex) {
return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC);
}
public LiteflowResponse invoke2RespInAsync(String chainId, Object param, Integer slotIndex) {
return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC);
}
public LiteflowResponse invoke2RespInAsync(String chainId, Object param, Integer slotIndex) {
return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC);
}
//单独调用某一个node
@Deprecated
public void invoke(String nodeId, Integer slotIndex) throws Exception {
Node node = FlowBus.getNode(nodeId);
node.execute(slotIndex);
}
// 单独调用某一个node
@Deprecated
public void invoke(String nodeId, Integer slotIndex) throws Exception {
Node node = FlowBus.getNode(nodeId);
node.execute(slotIndex);
}
//调用一个流程并返回LiteflowResponse上下文为默认的DefaultContext初始参数为null
public LiteflowResponse execute2Resp(String chainId) {
return this.execute2Resp(chainId, null, DefaultContext.class);
}
// 调用一个流程并返回LiteflowResponse上下文为默认的DefaultContext初始参数为null
public LiteflowResponse execute2Resp(String chainId) {
return this.execute2Resp(chainId, null, DefaultContext.class);
}
//调用一个流程并返回LiteflowResponse上下文为默认的DefaultContext
public LiteflowResponse execute2Resp(String chainId, Object param) {
return this.execute2Resp(chainId, param, DefaultContext.class);
}
// 调用一个流程并返回LiteflowResponse上下文为默认的DefaultContext
public LiteflowResponse execute2Resp(String chainId, Object param) {
return this.execute2Resp(chainId, param, DefaultContext.class);
}
//调用一个流程并返回LiteflowResponse允许多上下文的传入
public LiteflowResponse execute2Resp(String chainId, Object param, Class<?>... contextBeanClazzArray) {
return this.execute2Resp(chainId, param, contextBeanClazzArray, null);
}
// 调用一个流程并返回LiteflowResponse允许多上下文的传入
public LiteflowResponse execute2Resp(String chainId, Object param, Class<?>... contextBeanClazzArray) {
return this.execute2Resp(chainId, param, contextBeanClazzArray, null);
}
public LiteflowResponse execute2Resp(String chainId, Object param, Object... contextBeanArray) {
return this.execute2Resp(chainId, param, null, contextBeanArray);
}
public LiteflowResponse execute2Resp(String chainId, Object param, Object... contextBeanArray) {
return this.execute2Resp(chainId, param, null, contextBeanArray);
}
//调用一个流程并返回Future<LiteflowResponse>允许多上下文的传入
public Future<LiteflowResponse> execute2Future(String chainId, Object param, Class<?>... contextBeanClazzArray) {
return ExecutorHelper.loadInstance().buildMainExecutor(liteflowConfig.getMainExecutorClass()).submit(()
-> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray, null));
}
// 调用一个流程并返回Future<LiteflowResponse>允许多上下文的传入
public Future<LiteflowResponse> execute2Future(String chainId, Object param, Class<?>... contextBeanClazzArray) {
return ExecutorHelper.loadInstance()
.buildMainExecutor(liteflowConfig.getMainExecutorClass())
.submit(() -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray, null));
}
public Future<LiteflowResponse> execute2Future(String chainId, Object param, Object... contextBeanArray) {
return ExecutorHelper.loadInstance()
.buildMainExecutor(liteflowConfig.getMainExecutorClass())
.submit(() -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, null, contextBeanArray));
}
public Future<LiteflowResponse> execute2Future(String chainId, Object param, Object... contextBeanArray) {
return ExecutorHelper.loadInstance().buildMainExecutor(liteflowConfig.getMainExecutorClass()).submit(()
-> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, null, contextBeanArray));
}
// 调用一个流程返回默认的上下文适用于简单的调用
@Deprecated
public DefaultContext execute(String chainId, Object param) throws Exception {
LiteflowResponse response = this.execute2Resp(chainId, param, DefaultContext.class);
if (!response.isSuccess()) {
throw response.getCause();
}
else {
return response.getFirstContextBean();
}
}
//调用一个流程返回默认的上下文适用于简单的调用
@Deprecated
public DefaultContext execute(String chainId, Object param) throws Exception {
LiteflowResponse response = this.execute2Resp(chainId, param, DefaultContext.class);
if (!response.isSuccess()) {
throw response.getCause();
} else {
return response.getFirstContextBean();
}
}
private LiteflowResponse execute2Resp(String chainId, Object param, Class<?>[] contextBeanClazzArray,
Object[] contextBeanArray) {
Slot slot = doExecute(chainId, param, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE);
return LiteflowResponse.newMainResponse(slot);
}
private LiteflowResponse execute2Resp(String chainId,
Object param,
Class<?>[] contextBeanClazzArray,
Object[] contextBeanArray) {
Slot slot = doExecute(chainId, param, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE);
return LiteflowResponse.newMainResponse(slot);
}
private LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex,
InnerChainTypeEnum innerChainType) {
Slot slot = doExecute(chainId, param, null, null, slotIndex, innerChainType);
return LiteflowResponse.newInnerResponse(chainId, slot);
}
private LiteflowResponse invoke2Resp(String chainId,
Object param,
Integer slotIndex, InnerChainTypeEnum innerChainType) {
Slot slot = doExecute(chainId, param, null, null, slotIndex, innerChainType);
return LiteflowResponse.newInnerResponse(chainId, slot);
}
private Slot doExecute(String chainId, Object param, Class<?>[] contextBeanClazzArray, Object[] contextBeanArray,
Integer slotIndex, InnerChainTypeEnum innerChainType) {
if (FlowBus.needInit()) {
init(true);
}
private Slot doExecute(String chainId,
Object param,
Class<?>[] contextBeanClazzArray,
Object[] contextBeanArray,
Integer slotIndex,
InnerChainTypeEnum innerChainType) {
if (FlowBus.needInit()) {
init(true);
}
// 如果不是隐式流程那么需要分配Slot
if (innerChainType.equals(InnerChainTypeEnum.NONE) && ObjectUtil.isNull(slotIndex)) {
// 这里可以根据class分配也可以根据bean去分配
if (ArrayUtil.isNotEmpty(contextBeanClazzArray)) {
slotIndex = DataBus.offerSlotByClass(ListUtil.toList(contextBeanClazzArray));
}
else {
slotIndex = DataBus.offerSlotByBean(ListUtil.toList(contextBeanArray));
}
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.info("slot[{}] offered", slotIndex);
}
}
//如果不是隐式流程那么需要分配Slot
if (innerChainType.equals(InnerChainTypeEnum.NONE) && ObjectUtil.isNull(slotIndex)) {
//这里可以根据class分配也可以根据bean去分配
if (ArrayUtil.isNotEmpty(contextBeanClazzArray)) {
slotIndex = DataBus.offerSlotByClass(ListUtil.toList(contextBeanClazzArray));
} else {
slotIndex = DataBus.offerSlotByBean(ListUtil.toList(contextBeanArray));
}
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.info("slot[{}] offered", slotIndex);
}
}
if (slotIndex == -1) {
throw new NoAvailableSlotException("there is no available slot");
}
if (slotIndex == -1) {
throw new NoAvailableSlotException("there is no available slot");
}
Slot slot = DataBus.getSlot(slotIndex);
if (ObjectUtil.isNull(slot)) {
throw new NoAvailableSlotException(StrUtil.format("the slot[{}] is not exist", slotIndex));
}
// 如果是隐式流程事先把subException给置空然后把隐式流程的chainId放入slot元数据中
// 我知道这在多线程调用隐式流程中会有问题但是考虑到这种场景的不会多也有其他的转换方式
// 所以暂且这么做以后再优化
if (!innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.removeSubException(chainId);
slot.addSubChain(chainId);
}
Slot slot = DataBus.getSlot(slotIndex);
if (ObjectUtil.isNull(slot)) {
throw new NoAvailableSlotException(StrUtil.format("the slot[{}] is not exist", slotIndex));
}
if (StrUtil.isBlank(slot.getRequestId())) {
slot.generateRequestId();
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.info("requestId[{}] has generated", slot.getRequestId());
}
}
//如果是隐式流程事先把subException给置空然后把隐式流程的chainId放入slot元数据中
//我知道这在多线程调用隐式流程中会有问题但是考虑到这种场景的不会多也有其他的转换方式
//所以暂且这么做以后再优化
if (!innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.removeSubException(chainId);
slot.addSubChain(chainId);
}
if (ObjectUtil.isNotNull(param)) {
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.setRequestData(param);
}
else if (innerChainType.equals(InnerChainTypeEnum.IN_SYNC)) {
slot.setChainReqData(chainId, param);
}
else if (innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)) {
slot.setChainReqData2Queue(chainId, param);
}
}
if (StrUtil.isBlank(slot.getRequestId())) {
slot.generateRequestId();
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.info("requestId[{}] has generated", slot.getRequestId());
}
}
Chain chain = null;
try {
chain = FlowBus.getChain(chainId);
if (ObjectUtil.isNotNull(param)) {
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.setRequestData(param);
} else if (innerChainType.equals(InnerChainTypeEnum.IN_SYNC)) {
slot.setChainReqData(chainId, param);
} else if (innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)) {
slot.setChainReqData2Queue(chainId, param);
}
}
if (ObjectUtil.isNull(chain)) {
String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(),
chainId);
throw new ChainNotFoundException(errorMsg);
}
// 执行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);
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.error(errMsg, e);
}
else {
LOG.error(errMsg);
}
}
else {
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.error(e.getMessage(), e);
}
else {
LOG.error(e.getMessage());
}
}
Chain chain = null;
try {
chain = FlowBus.getChain(chainId);
// 如果是正常流程需要把异常设置到slot的exception属性里
// 如果是隐式流程则需要设置到隐式流程的exception属性里
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.setException(e);
}
else {
slot.setSubException(chainId, e);
}
}
finally {
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.printStep();
DataBus.releaseSlot(slotIndex);
}
}
return slot;
}
if (ObjectUtil.isNull(chain)) {
String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), chainId);
throw new ChainNotFoundException(errorMsg);
}
// 执行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);
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.error(errMsg, e);
} else {
LOG.error(errMsg);
}
} else {
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
LOG.error(e.getMessage(), e);
} else {
LOG.error(e.getMessage());
}
}
public LiteflowConfig getLiteflowConfig() {
return liteflowConfig;
}
//如果是正常流程需要把异常设置到slot的exception属性里
//如果是隐式流程则需要设置到隐式流程的exception属性里
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.setException(e);
} else {
slot.setSubException(chainId, e);
}
} finally {
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
slot.printStep();
DataBus.releaseSlot(slotIndex);
}
}
return slot;
}
public void setLiteflowConfig(LiteflowConfig liteflowConfig) {
this.liteflowConfig = liteflowConfig;
// 把liteFlowConfig设到LiteFlowGetter中去
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
}
public LiteflowConfig getLiteflowConfig() {
return liteflowConfig;
}
/**
* 添加监听文件路径
* @param pathList 文件路径
*/
private void addMonitorFilePaths(List<String> pathList) throws Exception {
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
}
public void setLiteflowConfig(LiteflowConfig liteflowConfig) {
this.liteflowConfig = liteflowConfig;
//把liteFlowConfig设到LiteFlowGetter中去
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
}
/**
* 添加监听文件路径
*
* @param pathList 文件路径
*/
private void addMonitorFilePaths(List<String> pathList) throws Exception {
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
}
}

View File

@ -9,27 +9,28 @@ import com.yomahub.liteflow.property.LiteflowConfig;
*/
public class FlowExecutorHolder {
private static FlowExecutor flowExecutor;
private static FlowExecutor flowExecutor;
public static FlowExecutor loadInstance(LiteflowConfig liteflowConfig){
if (ObjectUtil.isNull(flowExecutor)){
flowExecutor = new FlowExecutor(liteflowConfig);
}
return flowExecutor;
}
public static FlowExecutor loadInstance(LiteflowConfig liteflowConfig) {
if (ObjectUtil.isNull(flowExecutor)) {
flowExecutor = new FlowExecutor(liteflowConfig);
}
return flowExecutor;
}
public static FlowExecutor loadInstance(){
if (ObjectUtil.isNull(flowExecutor)){
throw new FlowExecutorNotInitException("flow executor is not initialized yet");
}
return flowExecutor;
}
public static FlowExecutor loadInstance() {
if (ObjectUtil.isNull(flowExecutor)) {
throw new FlowExecutorNotInitException("flow executor is not initialized yet");
}
return flowExecutor;
}
public static void setHolder(FlowExecutor flowExecutor){
FlowExecutorHolder.flowExecutor = flowExecutor;
}
public static void setHolder(FlowExecutor flowExecutor) {
FlowExecutorHolder.flowExecutor = flowExecutor;
}
public static void clean() {
flowExecutor = null;
}
public static void clean(){
flowExecutor = null;
}
}

View File

@ -7,27 +7,27 @@ import java.util.List;
import java.util.function.BooleanSupplier;
/**
* 流程初始化的钩子类所有的钩子都放在这里
* 目前钩子主要是放一些第三方中间件的规则监听
* 放的钩子要求都是无入参无返回的所以这里是BooleanSupplier
* 流程初始化的钩子类所有的钩子都放在这里 目前钩子主要是放一些第三方中间件的规则监听 放的钩子要求都是无入参无返回的所以这里是BooleanSupplier
*
* @author Bryan.Zhang
* @since 2.9.4
*/
public class FlowInitHook {
private static final List<BooleanSupplier> supplierList = new ArrayList<>();
private static final List<BooleanSupplier> supplierList = new ArrayList<>();
public static void executeHook(){
if (CollUtil.isNotEmpty(supplierList)){
supplierList.forEach(BooleanSupplier::getAsBoolean);
}
}
public static void executeHook() {
if (CollUtil.isNotEmpty(supplierList)) {
supplierList.forEach(BooleanSupplier::getAsBoolean);
}
}
public static void addHook(BooleanSupplier hookSupplier){
supplierList.add(hookSupplier);
}
public static void addHook(BooleanSupplier hookSupplier) {
supplierList.add(hookSupplier);
}
public static void cleanHook() {
supplierList.clear();
}
public static void cleanHook(){
supplierList.clear();
}
}

View File

@ -5,17 +5,20 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
/**
* 循环跳出节点逻辑抽象类
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public abstract class NodeBreakComponent extends NodeComponent{
@Override
public void process() throws Exception {
boolean breakFlag = processBreak();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setBreakResult(originalClass.getName(), breakFlag);
}
public abstract class NodeBreakComponent extends NodeComponent {
@Override
public void process() throws Exception {
boolean breakFlag = processBreak();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setBreakResult(originalClass.getName(), breakFlag);
}
public abstract boolean processBreak() throws Exception;
public abstract boolean processBreak() throws Exception;
}

View File

@ -32,9 +32,10 @@ import java.util.Map;
/**
* 普通组件抽象类
*
* @author Bryan.Zhang
*/
public abstract class NodeComponent{
public abstract class NodeComponent {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@ -46,42 +47,41 @@ public abstract class NodeComponent{
private NodeTypeEnum type;
//这是自己的实例取代this
//为何要设置这个用this不行么因为如果有aop去切的话this在spring的aop里是切不到的self对象有可能是代理过的对象
// 这是自己的实例取代this
// 为何要设置这个用this不行么因为如果有aop去切的话this在spring的aop里是切不到的self对象有可能是代理过的对象
private NodeComponent self;
//重试次数
// 重试次数
private int retryCount = 0;
//在目标异常抛出时才重试
private Class<? extends Exception>[] retryForExceptions = new Class[]{Exception.class};
// 在目标异常抛出时才重试
private Class<? extends Exception>[] retryForExceptions = new Class[] { Exception.class };
/** 节点执行器的类全名 */
private Class<? extends NodeExecutor> nodeExecutorClass = DefaultNodeExecutor.class;
/**当前对象为单例注册进spring上下文但是node实例不是单例这里通过对node实例的引用来获得一些链路属性**/
/** 当前对象为单例注册进spring上下文但是node实例不是单例这里通过对node实例的引用来获得一些链路属性 **/
private final TransmittableThreadLocal<Node> refNodeTL = new TransmittableThreadLocal<>();
/**
*******************以下的属性为线程附加属性********************
* 线程属性是指每一个request的值都是不一样的
******************* 以下的属性为线程附加属性******************** 线程属性是指每一个request的值都是不一样的
* 这里NodeComponent是单例所以要用ThreadLocal来修饰
*/
//当前slot的index
// 当前slot的index
private final TransmittableThreadLocal<Integer> slotIndexTL = new TransmittableThreadLocal<>();
//是否结束整个流程这个只对串行流程有效并行流程无效
// 是否结束整个流程这个只对串行流程有效并行流程无效
private final TransmittableThreadLocal<Boolean> isEndTL = new TransmittableThreadLocal<>();
public NodeComponent() {
}
public void execute() throws Exception{
public void execute() throws Exception {
Slot slot = this.getSlot();
//在元数据里加入step信息
// 在元数据里加入step信息
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE);
cmpStep.setTag(this.getTag());
slot.addStep(cmpStep);
@ -89,42 +89,46 @@ public abstract class NodeComponent{
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try{
//前置处理
try {
// 前置处理
self.beforeProcess();
//主要的处理逻辑
// 主要的处理逻辑
self.process();
//成功后回调方法
// 成功后回调方法
self.onSuccess();
//步骤状态设为true
// 步骤状态设为true
cmpStep.setSuccess(true);
} catch (Exception e){
//步骤状态设为false并加入异常
}
catch (Exception e) {
// 步骤状态设为false并加入异常
cmpStep.setSuccess(false);
cmpStep.setException(e);
//执行失败后回调方法
//这里要注意失败方法本身抛出错误只打出堆栈往外抛出的还是主要的异常
try{
// 执行失败后回调方法
// 这里要注意失败方法本身抛出错误只打出堆栈往外抛出的还是主要的异常
try {
self.onError();
}catch (Exception ex){
String errMsg = StrUtil.format("[{}]:component[{}] onError method happens exception",slot.getRequestId(),this.getDisplayName());
}
catch (Exception ex) {
String errMsg = StrUtil.format("[{}]:component[{}] onError method happens exception",
slot.getRequestId(), this.getDisplayName());
LOG.error(errMsg);
}
throw e;
} finally {
//后置处理
}
finally {
// 后置处理
self.afterProcess();
stopWatch.stop();
final long timeSpent = stopWatch.getTotalTimeMillis();
LOG.debug("[{}]:component[{}] finished in {} milliseconds",slot.getRequestId(),this.getDisplayName(),timeSpent);
LOG.debug("[{}]:component[{}] finished in {} milliseconds", slot.getRequestId(), this.getDisplayName(),
timeSpent);
//往CmpStep中放入时间消耗信息
// 往CmpStep中放入时间消耗信息
cmpStep.setTimeSpent(timeSpent);
// 性能统计
@ -135,52 +139,53 @@ public abstract class NodeComponent{
}
}
public void beforeProcess(){
//全局切面只在spring体系下生效这里用了spi机制取到相应环境下的实现类
//非spring环境下全局切面为空实现
public void beforeProcess() {
// 全局切面只在spring体系下生效这里用了spi机制取到相应环境下的实现类
// 非spring环境下全局切面为空实现
CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(nodeId, this.getSlot());
}
public abstract void process() throws Exception;
public void onSuccess() throws Exception{
//如果需要在成功后回调某一个方法请覆盖这个方法
public void onSuccess() throws Exception {
// 如果需要在成功后回调某一个方法请覆盖这个方法
}
public void onError() throws Exception{
//如果需要在抛错后回调某一段逻辑请覆盖这个方法
public void onError() throws Exception {
// 如果需要在抛错后回调某一段逻辑请覆盖这个方法
}
public void afterProcess(){
public void afterProcess() {
CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(nodeId, this.getSlot());
}
//是否进入该节点
public boolean isAccess(){
// 是否进入该节点
public boolean isAccess() {
return true;
}
//出错是否继续执行(这个只适用于并行流程串行流程不起作用)
// 出错是否继续执行(这个只适用于并行流程串行流程不起作用)
public boolean isContinueOnError() {
return false;
}
//是否结束整个流程(不往下继续执行)
// 是否结束整个流程(不往下继续执行)
public boolean isEnd() {
Boolean isEnd = isEndTL.get();
if(ObjectUtil.isNull(isEnd)){
if (ObjectUtil.isNull(isEnd)) {
return false;
} else {
}
else {
return isEndTL.get();
}
}
//设置是否结束整个流程
public void setIsEnd(boolean isEnd){
// 设置是否结束整个流程
public void setIsEnd(boolean isEnd) {
this.isEndTL.set(isEnd);
}
public void removeIsEnd(){
public void removeIsEnd() {
this.isEndTL.remove();
}
@ -193,19 +198,19 @@ public abstract class NodeComponent{
return this.slotIndexTL.get();
}
public void removeSlotIndex(){
public void removeSlotIndex() {
this.slotIndexTL.remove();
}
public Slot getSlot(){
public Slot getSlot() {
return DataBus.getSlot(this.slotIndexTL.get());
}
public <T> T getFirstContextBean(){
public <T> T getFirstContextBean() {
return this.getSlot().getFirstContextBean();
}
public <T> T getContextBean(Class<T> contextBeanClazz){
public <T> T getContextBean(Class<T> contextBeanClazz) {
return this.getSlot().getContextBean(contextBeanClazz);
}
@ -241,11 +246,11 @@ public abstract class NodeComponent{
this.type = type;
}
public <T> void sendPrivateDeliveryData(String nodeId, T t){
public <T> void sendPrivateDeliveryData(String nodeId, T t) {
this.getSlot().setPrivateDeliveryData(nodeId, t);
}
public <T> T getPrivateDeliveryData(){
public <T> T getPrivateDeliveryData() {
return this.getSlot().getPrivateDeliveryData(this.getNodeId());
}
@ -273,7 +278,7 @@ public abstract class NodeComponent{
this.nodeExecutorClass = nodeExecutorClass;
}
public String getTag(){
public String getTag() {
return this.refNodeTL.get().getTag();
}
@ -285,15 +290,15 @@ public abstract class NodeComponent{
this.monitorBus = monitorBus;
}
public <T> T getRequestData(){
public <T> T getRequestData() {
return getSlot().getRequestData();
}
public <T> T getSubChainReqData(){
public <T> T getSubChainReqData() {
return getSlot().getChainReqData(this.getCurrChainId());
}
public <T> T getSubChainReqDataInAsync(){
public <T> T getSubChainReqDataInAsync() {
return getSlot().getChainReqDataFromQueue(this.getCurrChainId());
}
@ -302,54 +307,55 @@ public abstract class NodeComponent{
* @return String
*/
@Deprecated
public String getChainName(){
public String getChainName() {
return getSlot().getChainName();
}
public String getChainId(){
public String getChainId() {
return getSlot().getChainId();
}
public String getDisplayName(){
if(StrUtil.isEmpty(this.name)){
public String getDisplayName() {
if (StrUtil.isEmpty(this.name)) {
return this.nodeId;
}else {
}
else {
return StrUtil.format("{}({})", this.nodeId, this.name);
}
}
public String getCurrChainId(){
public String getCurrChainId() {
return getRefNode().getCurrChainId();
}
public Node getRefNode(){
public Node getRefNode() {
return this.refNodeTL.get();
}
public void setRefNode(Node refNode){
public void setRefNode(Node refNode) {
this.refNodeTL.set(refNode);
}
public void removeRefNode(){
public void removeRefNode() {
this.refNodeTL.remove();
}
public <T> T getCmpData(Class<T> clazz){
public <T> T getCmpData(Class<T> clazz) {
String cmpData = getRefNode().getCmpData();
if (StrUtil.isBlank(cmpData)){
if (StrUtil.isBlank(cmpData)) {
return null;
}
if (clazz.equals(String.class) || clazz.equals(Object.class)){
if (clazz.equals(String.class) || clazz.equals(Object.class)) {
return (T) cmpData;
}
return JsonUtil.parseObject(cmpData, clazz);
}
public Integer getLoopIndex(){
public Integer getLoopIndex() {
return this.refNodeTL.get().getLoopIndex();
}
public <T> T getCurrLoopObj(){
public <T> T getCurrLoopObj() {
return this.refNodeTL.get().getCurrLoopObject();
}
@ -370,4 +376,5 @@ public abstract class NodeComponent{
public LiteflowResponse invoke2RespInAsync(String chainId, Object param) {
return FlowExecutorHolder.loadInstance().invoke2RespInAsync(chainId, param, this.getSlotIndex());
}
}

View File

@ -5,18 +5,20 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
/**
* FOR计数节点抽象类
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public abstract class NodeForComponent extends NodeComponent{
public abstract class NodeForComponent extends NodeComponent {
@Override
public void process() throws Exception {
int forCount = processFor();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setForResult(originalClass.getName(), forCount);
}
@Override
public void process() throws Exception {
int forCount = processFor();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setForResult(originalClass.getName(), forCount);
}
public abstract int processFor() throws Exception;
public abstract int processFor() throws Exception;
}

View File

@ -4,17 +4,19 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
/**
* IF节点抽象类
*
* @author Bryan.Zhang
* @since 2.8.5
*/
public abstract class NodeIfComponent extends NodeComponent{
public abstract class NodeIfComponent extends NodeComponent {
@Override
public void process() throws Exception {
boolean result = this.processIf();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
this.getSlot().setIfResult(originalClass.getName(), result);
}
@Override
public void process() throws Exception {
boolean result = this.processIf();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
this.getSlot().setIfResult(originalClass.getName(), result);
}
public abstract boolean processIf() throws Exception;
public abstract boolean processIf() throws Exception;
}

View File

@ -7,18 +7,20 @@ import java.util.Iterator;
/**
* ITERATOR迭代器循环组件抽象类
*
* @author Bryan.Zhang
* @since 2.9.7
*/
public abstract class NodeIteratorComponent extends NodeComponent{
public abstract class NodeIteratorComponent extends NodeComponent {
@Override
public void process() throws Exception {
Iterator<?> it = processIterator();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setIteratorResult(originalClass.getName(), it);
}
@Override
public void process() throws Exception {
Iterator<?> it = processIterator();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setIteratorResult(originalClass.getName(), it);
}
public abstract Iterator<?> processIterator() throws Exception;
public abstract Iterator<?> processIterator() throws Exception;
}

View File

@ -11,6 +11,7 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
/**
* 条件路由节点抽象类
*
* @author Bryan.Zhang
*/
public abstract class NodeSwitchComponent extends NodeComponent {
@ -22,7 +23,7 @@ public abstract class NodeSwitchComponent extends NodeComponent {
this.getSlot().setSwitchResult(originalClass.getName(), nodeId);
}
//用以返回路由节点的beanId
// 用以返回路由节点的beanId
public abstract String processSwitch() throws Exception;
}

View File

@ -5,17 +5,20 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
/**
* WHILE条件节点抽象类
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public abstract class NodeWhileComponent extends NodeComponent{
@Override
public void process() throws Exception {
boolean whileFlag = processWhile();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setWhileResult(originalClass.getName(), whileFlag);
}
public abstract class NodeWhileComponent extends NodeComponent {
@Override
public void process() throws Exception {
boolean whileFlag = processWhile();
Slot slot = this.getSlot();
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getClass());
slot.setWhileResult(originalClass.getName(), whileFlag);
}
public abstract boolean processWhile() throws Exception;
public abstract boolean processWhile() throws Exception;
}

View File

@ -7,23 +7,28 @@ import java.util.Map;
/**
* 脚本BREAK节点
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public class ScriptBreakComponent extends NodeBreakComponent implements ScriptComponent{
@Override
public boolean processBreak() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
public class ScriptBreakComponent extends NodeBreakComponent implements ScriptComponent {
@Override
public boolean processBreak() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean) ScriptExecutorFactory.loadInstance()
.getScriptExecutor(this.getRefNode().getLanguage())
.execute(wrap);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -9,27 +9,29 @@ import java.util.Map;
/**
* 脚本组件类
*
* @author Bryan.Zhang
* @since 2.6.0
*/
public class ScriptCommonComponent extends NodeComponent implements ScriptComponent{
public class ScriptCommonComponent extends NodeComponent implements ScriptComponent {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void process() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
@Override
public void process() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
@Override
public void loadScript(String script, String language) {
log.info("load script for component[{}]", getDisplayName());
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
log.info("load script for component[{}]", getDisplayName());
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -7,26 +7,30 @@ import java.util.Map;
/**
* 脚本接口
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public interface ScriptComponent {
/**
* 用于维护脚本类型和脚本 cmp 的映射关系
*/
Map<NodeTypeEnum, Class<?>> ScriptComponentClassMap = new HashMap<NodeTypeEnum, Class<?>>() {{
put(NodeTypeEnum.SCRIPT, ScriptCommonComponent.class);
put(NodeTypeEnum.SWITCH_SCRIPT, ScriptSwitchComponent.class);
put(NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class);
put(NodeTypeEnum.FOR_SCRIPT, ScriptForComponent.class);
put(NodeTypeEnum.WHILE_SCRIPT, ScriptWhileComponent.class);
put(NodeTypeEnum.BREAK_SCRIPT, ScriptBreakComponent.class);
}};
/**
* 用于维护脚本类型和脚本 cmp 的映射关系
*/
Map<NodeTypeEnum, Class<?>> ScriptComponentClassMap = new HashMap<NodeTypeEnum, Class<?>>() {
{
put(NodeTypeEnum.SCRIPT, ScriptCommonComponent.class);
put(NodeTypeEnum.SWITCH_SCRIPT, ScriptSwitchComponent.class);
put(NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class);
put(NodeTypeEnum.FOR_SCRIPT, ScriptForComponent.class);
put(NodeTypeEnum.WHILE_SCRIPT, ScriptWhileComponent.class);
put(NodeTypeEnum.BREAK_SCRIPT, ScriptBreakComponent.class);
}
};
/**
* 加载脚本
* @param script
*/
void loadScript(String script, String language);
/**
* 加载脚本
* @param script
*/
void loadScript(String script, String language);
}

View File

@ -7,23 +7,28 @@ import java.util.Map;
/**
* 脚本FOR节点
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public class ScriptForComponent extends NodeForComponent implements ScriptComponent{
@Override
public int processFor() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (int) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
public class ScriptForComponent extends NodeForComponent implements ScriptComponent {
@Override
public int processFor() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (int) ScriptExecutorFactory.loadInstance()
.getScriptExecutor(this.getRefNode().getLanguage())
.execute(wrap);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -7,23 +7,28 @@ import java.util.Map;
/**
* 脚本IF节点
*
* @author Bryan.Zhang
* @since 2.8.5
*/
public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent{
@Override
public boolean processIf() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean)ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent {
@Override
public boolean processIf() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean) ScriptExecutorFactory.loadInstance()
.getScriptExecutor(this.getRefNode().getLanguage())
.execute(wrap);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -7,24 +7,28 @@ import java.util.Map;
/**
* 脚本条件节点
*
* @author Bryan.Zhang
* @since 2.6.0
*/
public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent{
public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent {
@Override
public String processSwitch() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (String)ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
@Override
public String processSwitch() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (String) ScriptExecutorFactory.loadInstance()
.getScriptExecutor(this.getRefNode().getLanguage())
.execute(wrap);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -7,24 +7,28 @@ import java.util.Map;
/**
* 脚本WHILE节点
*
* @author Bryan.Zhang
* @since 2.9.0
*/
public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent{
public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent {
@Override
public boolean processWhile() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
}
@Override
public boolean processWhile() throws Exception {
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
wrap.setCurrChainId(this.getCurrChainId());
wrap.setNodeId(this.getNodeId());
wrap.setSlotIndex(this.getSlotIndex());
wrap.setTag(this.getTag());
wrap.setCmpData(this.getCmpData(Map.class));
return (boolean) ScriptExecutorFactory.loadInstance()
.getScriptExecutor(this.getRefNode().getLanguage())
.execute(wrap);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
@Override
public void loadScript(String script, String language) {
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
}
}

View File

@ -34,181 +34,190 @@ import java.util.stream.Collectors;
/**
* 声明式组件的代理核心生成类
*
* @author Bryan.Zhang
* @since 2.6.14
*/
public class ComponentProxy {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
private final String nodeId;
private final String nodeId;
private final Object bean;
private final Object bean;
private final Class<?> clazz;
private final Class<?> clazz;
public ComponentProxy(String nodeId, Object bean, Class<?> clazz) {
this.nodeId = nodeId;
this.bean = bean;
this.clazz = clazz;
}
public ComponentProxy(String nodeId, Object bean, Class<?> clazz) {
this.nodeId = nodeId;
this.bean = bean;
this.clazz = clazz;
}
public List<NodeComponent> getProxyList() throws Exception{
//这里要判断bean是否是spring代理过的bean如果是代理过的bean需要取到原class对象
Class<?> beanClazz;
if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())){
beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass());
}else{
beanClazz = bean.getClass();
}
//得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的)自己定义的不算
Map<String, List<Method>> methodListMap = Arrays.stream(beanClazz.getMethods()).filter(
m -> m.getAnnotation(LiteflowMethod.class) != null
).collect(Collectors.groupingBy(
m -> m.getAnnotation(LiteflowMethod.class).nodeId()
));
public List<NodeComponent> getProxyList() throws Exception {
// 这里要判断bean是否是spring代理过的bean如果是代理过的bean需要取到原class对象
Class<?> beanClazz;
if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())) {
beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass());
}
else {
beanClazz = bean.getClass();
}
// 得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的)自己定义的不算
Map<String, List<Method>> methodListMap = Arrays.stream(beanClazz.getMethods())
.filter(m -> m.getAnnotation(LiteflowMethod.class) != null)
.collect(Collectors.groupingBy(m -> m.getAnnotation(LiteflowMethod.class).nodeId()));
return methodListMap.entrySet().stream().map(entry -> {
// 获取当前节点的原有注解LiteFlowRetry 之类的规则注解
Annotation[] beanClassAnnotation = beanClazz.getAnnotations();
// 如果entry的key为空字符串则是为了兼容老版本的写法没有指定nodeId的情况
// 判断是否是方法级创造节点
boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey());
// 获取当前bean 真实的nodeId
String activeNodeId = isMethodCreate ? entry.getKey() : nodeId;
// 获取当前节点所有的@LiteflowRetry @LiteflowMethod注解对
List<Tuple> tupleList = entry.getValue().stream().map(m ->
new Tuple(m.getAnnotation(LiteflowRetry.class), m.getAnnotation(LiteflowMethod.class))
).collect(Collectors.toList());
// 获取当前节点的所有LiteFlowMethod注解
List<LiteflowMethod> methodList = tupleList.stream().map(tuple -> ((LiteflowMethod)tuple.get(1)))
.filter(Objects::nonNull)
.collect(Collectors.toList());
// nodeType去重
List<? extends Class<? extends NodeComponent>> classes = methodList.stream()
.map(LiteflowMethod::nodeType)
.map(NodeTypeEnum::getMappingClazz)
.distinct()
.collect(Collectors.toList());
// 相同nodeId里只能定义同一种的类型的NodeComponent
boolean legal = classes.size() == 1;
if (!legal){
throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" + activeNodeId + ",cmpClass:" + classes);
}
// 当前节点实际LiteflowRetry注解
AtomicReference<LiteflowRetry> liteflowRetryAtomicReference = new AtomicReference<>(null);
// 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上
boolean illegal = tupleList.stream().anyMatch(
tuple -> {
LiteflowRetry liteflowRetry = tuple.get(0);
LiteflowMethod liteflowMethod = tuple.get(1);
boolean existRetry = liteflowRetry != null;
boolean isProcess = liteflowMethod.value().isMainMethod();
// 如果是再Process方法上的liteflowRetry注解则默认为真实节点
if (isProcess && existRetry) {
liteflowRetryAtomicReference.set(liteflowRetry);
}
// 如果存在existRetry注解但是不是在Process方法上则为非法
return existRetry && !isProcess;
}
);
if (illegal){
throw new LiteFlowException("the retry annotation (@LiteflowRetry) must be declared on the PROCESS method");
}
// 生成nodeCmp的类型默认为全局定义的clazz
Class<?> cmpClazz;
cmpClazz = clazz;
// 判断是否是方法声明的组件
if (isMethodCreate){
cmpClazz = methodList.iterator().next().nodeType().getMappingClazz();
LiteflowRetry liteflowRetry;
if ((liteflowRetry = liteflowRetryAtomicReference.get()) != null){
// 增加LiteFlowRetry注解到注解数组里
List<Annotation> annotations = Arrays.stream(beanClassAnnotation)
.filter(a -> !a.annotationType().equals(LiteflowRetry.class))
.collect(Collectors.toList());
annotations.add(liteflowRetry);
beanClassAnnotation = new Annotation[annotations.size()];
annotations.toArray(beanClassAnnotation);
}
}
try {
//创建对象
//这里package进行了重设放到了被代理对象的所在目录
//生成的对象也加了上被代理对象拥有的注解
//被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断
Object instance = new ByteBuddy().subclass(cmpClazz)
.name(StrUtil.format("{}.ByteBuddy${}${}",
ClassUtil.getPackage(beanClazz),
activeNodeId,
SerialsUtil.generateShortUUID()))
.method(ElementMatchers.namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new)))
.intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean)))
.annotateType(beanClassAnnotation)
.make()
.load(ComponentProxy.class.getClassLoader())
.getLoaded()
.newInstance();
NodeComponent nodeComponent = (NodeComponent) instance;
// 重设nodeId
nodeComponent.setNodeId(activeNodeId);
return nodeComponent;
} catch (Exception e) {
throw new LiteFlowException(e);
}
}).collect(Collectors.toList());
}
return methodListMap.entrySet().stream().map(entry -> {
// 获取当前节点的原有注解LiteFlowRetry 之类的规则注解
Annotation[] beanClassAnnotation = beanClazz.getAnnotations();
// 如果entry的key为空字符串则是为了兼容老版本的写法没有指定nodeId的情况
// 判断是否是方法级创造节点
boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey());
// 获取当前bean 真实的nodeId
String activeNodeId = isMethodCreate ? entry.getKey() : nodeId;
// 获取当前节点所有的@LiteflowRetry @LiteflowMethod注解对
List<Tuple> tupleList = entry.getValue()
.stream()
.map(m -> new Tuple(m.getAnnotation(LiteflowRetry.class), m.getAnnotation(LiteflowMethod.class)))
.collect(Collectors.toList());
// 获取当前节点的所有LiteFlowMethod注解
List<LiteflowMethod> methodList = tupleList.stream()
.map(tuple -> ((LiteflowMethod) tuple.get(1)))
.filter(Objects::nonNull)
.collect(Collectors.toList());
// nodeType去重
List<? extends Class<? extends NodeComponent>> classes = methodList.stream()
.map(LiteflowMethod::nodeType)
.map(NodeTypeEnum::getMappingClazz)
.distinct()
.collect(Collectors.toList());
// 相同nodeId里只能定义同一种的类型的NodeComponent
boolean legal = classes.size() == 1;
if (!legal) {
throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:"
+ activeNodeId + ",cmpClass:" + classes);
}
// 当前节点实际LiteflowRetry注解
AtomicReference<LiteflowRetry> liteflowRetryAtomicReference = new AtomicReference<>(null);
// 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上
boolean illegal = tupleList.stream().anyMatch(tuple -> {
LiteflowRetry liteflowRetry = tuple.get(0);
LiteflowMethod liteflowMethod = tuple.get(1);
boolean existRetry = liteflowRetry != null;
boolean isProcess = liteflowMethod.value().isMainMethod();
// 如果是再Process方法上的liteflowRetry注解则默认为真实节点
if (isProcess && existRetry) {
liteflowRetryAtomicReference.set(liteflowRetry);
}
// 如果存在existRetry注解但是不是在Process方法上则为非法
return existRetry && !isProcess;
});
if (illegal) {
throw new LiteFlowException(
"the retry annotation (@LiteflowRetry) must be declared on the PROCESS method");
}
// 生成nodeCmp的类型默认为全局定义的clazz
Class<?> cmpClazz;
cmpClazz = clazz;
// 判断是否是方法声明的组件
if (isMethodCreate) {
cmpClazz = methodList.iterator().next().nodeType().getMappingClazz();
LiteflowRetry liteflowRetry;
if ((liteflowRetry = liteflowRetryAtomicReference.get()) != null) {
// 增加LiteFlowRetry注解到注解数组里
List<Annotation> annotations = Arrays.stream(beanClassAnnotation)
.filter(a -> !a.annotationType().equals(LiteflowRetry.class))
.collect(Collectors.toList());
annotations.add(liteflowRetry);
beanClassAnnotation = new Annotation[annotations.size()];
annotations.toArray(beanClassAnnotation);
}
}
try {
// 创建对象
// 这里package进行了重设放到了被代理对象的所在目录
// 生成的对象也加了上被代理对象拥有的注解
// 被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断
Object instance = new ByteBuddy().subclass(cmpClazz)
.name(StrUtil.format("{}.ByteBuddy${}${}", ClassUtil.getPackage(beanClazz), activeNodeId,
SerialsUtil.generateShortUUID()))
.method(ElementMatchers
.namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new)))
.intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean)))
.annotateType(beanClassAnnotation)
.make()
.load(ComponentProxy.class.getClassLoader())
.getLoaded()
.newInstance();
NodeComponent nodeComponent = (NodeComponent) instance;
// 重设nodeId
nodeComponent.setNodeId(activeNodeId);
return nodeComponent;
}
catch (Exception e) {
throw new LiteFlowException(e);
}
}).collect(Collectors.toList());
}
public class AopInvocationHandler implements InvocationHandler {
public class AopInvocationHandler implements InvocationHandler {
private final Object bean;
private final Object bean;
private final Class<?> clazz;
private final Class<?> clazz;
public AopInvocationHandler(Object bean) {
this.bean = bean;
this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass());
}
public AopInvocationHandler(Object bean) {
this.bean = bean;
this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass());
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//这里做了2件事情
//先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法
//然后进行转换成LiteFlowMethodBean对象List,形成<methodName,Method>键值对的对象
List<LiteFlowMethodBean> liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(clazz)).filter(m -> {
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return ObjectUtil.isNotNull(liteFlowMethod);
}).filter(m -> {
// 过滤不属于当前NodeComponent的方法
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return StrUtil.isEmpty(liteFlowMethod.nodeId())|| Objects.equals(liteFlowMethod.nodeId(),((NodeComponent) proxy).getNodeId());
}).map(m -> {
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m);
}).collect(Collectors.toList());
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// 这里做了2件事情
// 先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法
// 然后进行转换成LiteFlowMethodBean对象List,形成<methodName,Method>键值对的对象
List<LiteFlowMethodBean> liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(clazz)).filter(m -> {
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return ObjectUtil.isNotNull(liteFlowMethod);
}).filter(m -> {
// 过滤不属于当前NodeComponent的方法
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return StrUtil.isEmpty(liteFlowMethod.nodeId())
|| Objects.equals(liteFlowMethod.nodeId(), ((NodeComponent) proxy).getNodeId());
}).map(m -> {
LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class);
return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m);
}).collect(Collectors.toList());
//获取当前调用方法是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断)
//如果在里面则返回那个LiteFlowMethodBean不在则返回null
LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream().filter(
liteFlowMethodBean1 -> liteFlowMethodBean1.getMethodName().equals(method.getName())
).findFirst().orElse(null);
// 获取当前调用方法是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断)
// 如果在里面则返回那个LiteFlowMethodBean不在则返回null
LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream()
.filter(liteFlowMethodBean1 -> liteFlowMethodBean1.getMethodName().equals(method.getName()))
.findFirst()
.orElse(null);
//如果被代理的对象里有此标注标的方法则调用此被代理的对象里的方法如果没有则调用父类里的方法
//进行检查检查被代理的bean里是否有且仅有NodeComponent这个类型的参数
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1
&& Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class);
if (!checkFlag) {
String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName());
LOG.error(errMsg);
throw new ComponentMethodDefineErrorException(errMsg);
}
// 如果被代理的对象里有此标注标的方法则调用此被代理的对象里的方法如果没有则调用父类里的方法
// 进行检查检查被代理的bean里是否有且仅有NodeComponent这个类型的参数
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1
&& Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class);
if (!checkFlag) {
String errMsg = StrUtil.format(
"Method[{}.{}] must have NodeComponent parameter(and only one parameter)",
bean.getClass().getName(), liteFlowMethodBean.getMethod().getName());
LOG.error(errMsg);
throw new ComponentMethodDefineErrorException(errMsg);
}
try {
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
}
catch (Exception e) {
InvocationTargetException targetEx = (InvocationTargetException) e;
throw targetEx.getTargetException();
}
}
}
try{
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
}catch (Exception e){
InvocationTargetException targetEx = (InvocationTargetException)e;
throw targetEx.getTargetException();
}
}
}
}

View File

@ -7,28 +7,29 @@ import java.lang.reflect.Method;
*/
public class LiteFlowMethodBean {
private String methodName;
private String methodName;
private Method method;
private Method method;
public LiteFlowMethodBean(String methodName, Method method) {
this.methodName = methodName;
this.method = method;
}
public LiteFlowMethodBean(String methodName, Method method) {
this.methodName = methodName;
this.method = method;
}
public String getMethodName() {
return methodName;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public Method getMethod() {
return method;
}
public Method getMethod() {
return method;
}
public void setMethod(Method method) {
this.method = method;
}
public void setMethod(Method method) {
this.method = method;
}
}

View File

@ -9,10 +9,11 @@ package com.yomahub.liteflow.enums;
/**
* 组件步骤类型
*
* @author Bryan.Zhang
*/
public enum CmpStepTypeEnum {
START,
END,
SINGLE;
START, END, SINGLE;
}

View File

@ -4,52 +4,51 @@ package com.yomahub.liteflow.enums;
* @author Yun
*/
public enum ConditionTypeEnum {
TYPE_THEN("then","then"),
TYPE_WHEN("when","when"),
TYPE_SWITCH("switch", "switch"),
TYPE_IF("if", "if"),
TYPE_PRE("pre","pre"),
TYPE_FINALLY("finally","finally"),
TYPE_THEN("then", "then"), TYPE_WHEN("when", "when"), TYPE_SWITCH("switch", "switch"),
TYPE_FOR("for", "for"),
TYPE_IF("if", "if"), TYPE_PRE("pre", "pre"), TYPE_FINALLY("finally", "finally"),
TYPE_WHILE("while", "while"),
TYPE_FOR("for", "for"),
TYPE_ITERATOR("iterator", "iterator"),
TYPE_WHILE("while", "while"),
TYPE_CATCH("catch", "catch")
;
private String type;
private String name;
TYPE_ITERATOR("iterator", "iterator"),
ConditionTypeEnum(String type, String name) {
this.type = type;
this.name = name;
}
TYPE_CATCH("catch", "catch");
public String getType() {
return type;
}
private String type;
public void setType(String type) {
this.type = type;
}
private String name;
public String getName() {
return name;
}
ConditionTypeEnum(String type, String name) {
this.type = type;
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static ConditionTypeEnum getEnumByCode(String code) {
for (ConditionTypeEnum e : ConditionTypeEnum.values()) {
if (e.getType().equals(code)) {
return e;
}
}
return null;
}
public static ConditionTypeEnum getEnumByCode(String code) {
for (ConditionTypeEnum e : ConditionTypeEnum.values()) {
if (e.getType().equals(code)) {
return e;
}
}
return null;
}
}

View File

@ -9,8 +9,11 @@ package com.yomahub.liteflow.enums;
/**
* 可执行节点枚举
*
* @author Bryan.Zhang
*/
public enum ExecuteTypeEnum {
CHAIN,CONDITION,NODE
CHAIN, CONDITION, NODE
}

View File

@ -5,35 +5,33 @@ package com.yomahub.liteflow.enums;
* @since 2.5.0
*/
public enum FlowParserTypeEnum {
TYPE_XML("xml", "xml"),
TYPE_YML("yml", "yml"),
TYPE_JSON("json", "json"),
TYPE_EL_XML("el_xml", "el_xml"),
TYPE_EL_JSON("el_json", "el_json"),
TYPE_EL_YML("el_yml", "el_yml")
;
private String type;
private String name;
FlowParserTypeEnum(String type, String name) {
this.type = type;
this.name = name;
}
TYPE_XML("xml", "xml"), TYPE_YML("yml", "yml"), TYPE_JSON("json", "json"), TYPE_EL_XML("el_xml", "el_xml"),
TYPE_EL_JSON("el_json", "el_json"), TYPE_EL_YML("el_yml", "el_yml");
public String getType() {
return type;
}
private String type;
public void setType(String type) {
this.type = type;
}
private String name;
public String getName() {
return name;
}
FlowParserTypeEnum(String type, String name) {
this.type = type;
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -2,14 +2,17 @@ package com.yomahub.liteflow.enums;
/**
* 隐式流程类型
*
* @author Bryan.Zhang
* @since 2.8.5
*/
public enum InnerChainTypeEnum {
//不是隐式chain
NONE,
//在串行环境中执行
IN_SYNC,
//在并行环境中执行
IN_ASYNC
// 不是隐式chain
NONE,
// 在串行环境中执行
IN_SYNC,
// 在并行环境中执行
IN_ASYNC
}

View File

@ -1,52 +1,49 @@
package com.yomahub.liteflow.enums;
public enum LiteFlowMethodEnum {
PROCESS("process", true),
PROCESS_SWITCH("processSwitch", true),
PROCESS_IF("processIf", true),
PROCESS_FOR("processFor", true),
PROCESS_WHILE("processWhile", true),
PROCESS_BREAK("processBreak", true),
PROCESS_ITERATOR("processIterator", true),
PROCESS("process", true), PROCESS_SWITCH("processSwitch", true), PROCESS_IF("processIf", true),
PROCESS_FOR("processFor", true), PROCESS_WHILE("processWhile", true), PROCESS_BREAK("processBreak", true),
IS_ACCESS("isAccess", false),
PROCESS_ITERATOR("processIterator", true),
IS_END("isEnd", false),
IS_CONTINUE_ON_ERROR("isContinueOnError", false),
IS_ACCESS("isAccess", false),
GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false),
IS_END("isEnd", false), IS_CONTINUE_ON_ERROR("isContinueOnError", false),
ON_SUCCESS("onSuccess", false),
GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false),
ON_ERROR("onError", false),
ON_SUCCESS("onSuccess", false),
BEFORE_PROCESS("beforeProcess", false),
ON_ERROR("onError", false),
AFTER_PROCESS("afterProcess", false);
BEFORE_PROCESS("beforeProcess", false),
private String methodName;
AFTER_PROCESS("afterProcess", false);
private boolean isMainMethod;
private String methodName;
LiteFlowMethodEnum(String methodName, boolean isMainMethod){
this.methodName = methodName;
this.isMainMethod = isMainMethod;
}
private boolean isMainMethod;
public String getMethodName() {
return methodName;
}
LiteFlowMethodEnum(String methodName, boolean isMainMethod) {
this.methodName = methodName;
this.isMainMethod = isMainMethod;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public String getMethodName() {
return methodName;
}
public boolean isMainMethod() {
return isMainMethod;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public boolean isMainMethod() {
return isMainMethod;
}
public void setMainMethod(boolean mainMethod) {
isMainMethod = mainMethod;
}
public void setMainMethod(boolean mainMethod) {
isMainMethod = mainMethod;
}
}

View File

@ -52,6 +52,7 @@ public enum NodeTypeEnum {
private static final Logger LOG = LoggerFactory.getLogger(NodeTypeEnum.class);
private String code;
private String name;
private boolean isScript;
@ -127,34 +128,35 @@ public enum NodeTypeEnum {
}
public static NodeTypeEnum guessType(Class<?> clazz) {
if(LiteFlowProxyUtil.isCglibProxyClass(clazz)){
if (LiteFlowProxyUtil.isCglibProxyClass(clazz)) {
clazz = LiteFlowProxyUtil.getUserClass(clazz);
}
NodeTypeEnum nodeType = guessTypeBySuperClazz(clazz);
if (nodeType == null) {
//尝试从类声明处进行推断
// 尝试从类声明处进行推断
LiteflowCmpDefine liteflowCmpDefine = clazz.getAnnotation(LiteflowCmpDefine.class);
if (liteflowCmpDefine != null) {
//类声明方式中@LiteflowMethod是无需设置nodeId的
//但是如果设置了那么核心逻辑其实是取类上定义的id的
//这种可以运行但是理解起来不大好理解所以给出提示建议不要这么做
// 类声明方式中@LiteflowMethod是无需设置nodeId的
// 但是如果设置了那么核心逻辑其实是取类上定义的id的
// 这种可以运行但是理解起来不大好理解所以给出提示建议不要这么做
boolean mixDefined = Arrays.stream(clazz.getDeclaredMethods()).anyMatch(method -> {
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
if (liteflowMethod != null) {
return StrUtil.isNotBlank(liteflowMethod.nodeId());
} else {
}
else {
return false;
}
});
if (mixDefined) {
LOG.warn("[[[WARNING!!!]]]The @liteflowMethod in the class[{}] defined by @liteflowCmpDefine should not configure the nodeId again!",
LOG.warn(
"[[[WARNING!!!]]]The @liteflowMethod in the class[{}] defined by @liteflowCmpDefine should not configure the nodeId again!",
clazz.getName());
}
//在返回之前还要对方法级别的@LiteflowMethod进行检查如果存在方法上的类型与类上的不一致时给予警告信息
// 在返回之前还要对方法级别的@LiteflowMethod进行检查如果存在方法上的类型与类上的不一致时给予警告信息
AtomicReference<Method> differenceTypeMethod = new AtomicReference<>();
boolean hasDifferenceNodeType = Arrays.stream(clazz.getDeclaredMethods()).anyMatch(method -> {
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
@ -162,27 +164,33 @@ public enum NodeTypeEnum {
if (!liteflowMethod.nodeType().equals(liteflowCmpDefine.value())) {
differenceTypeMethod.set(method);
return true;
} else {
}
else {
return false;
}
} else {
}
else {
return false;
}
});
//表示存在不一样的类型
// 表示存在不一样的类型
if (hasDifferenceNodeType) {
LOG.warn("[[[WARNING!!!]]]The nodeType in @liteflowCmpDefine declared on the class[{}] does not match the nodeType in @liteflowMethod declared on the method[{}]!",
LOG.warn(
"[[[WARNING!!!]]]The nodeType in @liteflowCmpDefine declared on the class[{}] does not match the nodeType in @liteflowMethod declared on the method[{}]!",
clazz.getName(), differenceTypeMethod.get().getName());
}
return liteflowCmpDefine.value();
}
//再尝试声明式组件这部分的推断
LiteflowMethod liteflowMethod = Arrays.stream(clazz.getDeclaredMethods()).map(
method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class)
).filter(Objects::nonNull).filter(lfMethod -> lfMethod.value().isMainMethod()).findFirst().orElse(null);
// 再尝试声明式组件这部分的推断
LiteflowMethod liteflowMethod = Arrays.stream(clazz.getDeclaredMethods())
.map(method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class))
.filter(Objects::nonNull)
.filter(lfMethod -> lfMethod.value().isMainMethod())
.findFirst()
.orElse(null);
if (liteflowMethod != null) {
nodeType = liteflowMethod.nodeType();
@ -190,4 +198,5 @@ public enum NodeTypeEnum {
}
return nodeType;
}
}

View File

@ -2,43 +2,41 @@ package com.yomahub.liteflow.enums;
public enum ScriptTypeEnum {
GROOVY("groovy", "groovy"),
QLEXPRESS("qlexpress", "qlexpress"),
JS("javascript", "js"),
PYTHON("python", "python"),
LUA("luaj", "lua")
;
private String engineName;
GROOVY("groovy", "groovy"), QLEXPRESS("qlexpress", "qlexpress"), JS("javascript", "js"), PYTHON("python", "python"),
LUA("luaj", "lua");
private String displayName;
private String engineName;
ScriptTypeEnum(String engineName, String displayName) {
this.engineName = engineName;
this.displayName = displayName;
}
private String displayName;
public String getEngineName() {
return engineName;
}
ScriptTypeEnum(String engineName, String displayName) {
this.engineName = engineName;
this.displayName = displayName;
}
public void setEngineName(String engineName) {
this.engineName = engineName;
}
public String getEngineName() {
return engineName;
}
public String getDisplayName() {
return displayName;
}
public void setEngineName(String engineName) {
this.engineName = engineName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public static ScriptTypeEnum getEnumByDisplayName(String displayName) {
for (ScriptTypeEnum e : ScriptTypeEnum.values()) {
if (e.getDisplayName().equals(displayName)) {
return e;
}
}
return null;
}
public static ScriptTypeEnum getEnumByDisplayName(String displayName) {
for (ScriptTypeEnum e : ScriptTypeEnum.values()) {
if (e.getDisplayName().equals(displayName)) {
return e;
}
}
return null;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 类型错误异常
*
* @author Yun
*/
public class CatchErrorException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public CatchErrorException(String message) {
this.message = message;
}
public CatchErrorException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -7,24 +7,24 @@ package com.yomahub.liteflow.exception;
*/
public class ChainDuplicateException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public ChainDuplicateException(String message) {
this.message = message;
}
public ChainDuplicateException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 链端异常
*
* @author Bryan.Zhang
*/
public class ChainEndException extends RuntimeException {
@ -24,4 +25,5 @@ public class ChainEndException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 链端不存在
*
* @author Bryan.Zhang
*/
public class ChainNotFoundException extends RuntimeException {
@ -23,4 +24,5 @@ public class ChainNotFoundException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 流程规则主要执行器类
*
* @author Bryan.Zhang
* @since 2.5.3
*/
@ -25,4 +26,5 @@ public class ComponentCannotRegisterException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 组件方法定义错误异常
*
* @author Bryan.Zhang
*/
public class ComponentMethodDefineErrorException extends RuntimeException {
@ -24,4 +25,5 @@ public class ComponentMethodDefineErrorException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 组件不可访问异常
*
* @author Bryan.Zhang
*/
public class ComponentNotAccessException extends RuntimeException {
@ -23,4 +24,5 @@ public class ComponentNotAccessException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 组件代理错误异常
*
* @author Yun
*/
public class ComponentProxyErrorException extends RuntimeException {
@ -24,4 +25,5 @@ public class ComponentProxyErrorException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 配置错误异常
*
* @author Yun
*/
public class ConfigErrorException extends RuntimeException {
@ -23,4 +24,5 @@ public class ConfigErrorException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 循环依赖异常
*
* @author Yun
*/
public class CyclicDependencyException extends RuntimeException {
@ -24,4 +25,5 @@ public class CyclicDependencyException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,32 +2,35 @@ package com.yomahub.liteflow.exception;
/**
* 未找到数据异常
*
* @author tangkc
*/
public class DataNotFoundException extends RuntimeException {
public static final String MSG = "DataNotFoundException";
private static final long serialVersionUID = 1L;
public static final String MSG = "DataNotFoundException";
/**
* 异常信息
*/
private String message;
private static final long serialVersionUID = 1L;
public DataNotFoundException() {
this.message = MSG;
}
/**
* 异常信息
*/
private String message;
public DataNotFoundException(String message) {
this.message = message;
}
public DataNotFoundException() {
this.message = MSG;
}
@Override
public String getMessage() {
return message;
}
public DataNotFoundException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* EL 解析异常
*
* @author Yun
*/
public class ELParseException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public ELParseException(String message) {
this.message = message;
}
public ELParseException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -1,26 +1,28 @@
package com.yomahub.liteflow.exception;
/**
* 空条件值异常
*
* @author Yun
*/
public class EmptyConditionValueException extends RuntimeException {
private static final long serialVersionUID = 1L;
/** 异常信息 */
private String message;
private static final long serialVersionUID = 1L;
public EmptyConditionValueException(String message) {
this.message = message;
}
/** 异常信息 */
private String message;
@Override
public String getMessage() {
return message;
}
public EmptyConditionValueException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 错误支持路径异常
*
* @author Yun
*/
public class ErrorSupportPathException extends RuntimeException {
@ -23,4 +24,5 @@ public class ErrorSupportPathException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -29,4 +29,5 @@ public class ExecutableItemNotFoundException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 流程执行者未初始化
*
* @author Yun
*/
public class FlowExecutorNotInitException extends RuntimeException {
@ -23,4 +24,5 @@ public class FlowExecutorNotInitException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 流程系统异常
*
* @author Yun
*/
public class FlowSystemException extends RuntimeException {
@ -23,4 +24,5 @@ public class FlowSystemException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 如果目标不能是 Pre Finally 异常
*
* @author Yun
*/
public class IfTargetCannotBePreOrFinallyException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public IfTargetCannotBePreOrFinallyException(String message) {
this.message = message;
}
public IfTargetCannotBePreOrFinallyException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 类型错误异常
*
* @author Yun
*/
public class IfTypeErrorException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public IfTypeErrorException(String message) {
this.message = message;
}
public IfTypeErrorException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* Json 进程异常
*
* @author Yun
*/
public class JsonProcessException extends RuntimeException {
@ -23,4 +24,5 @@ public class JsonProcessException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,8 +2,8 @@
package com.yomahub.liteflow.exception;
/**
* LiteFlow架内部逻辑发生错误抛出的异常
* (自定义此异常方便开发者在做全局异常处理时分辨异常类型)
* LiteFlow架内部逻辑发生错误抛出的异常 (自定义此异常方便开发者在做全局异常处理时分辨异常类型)
*
* @author zendwang
* @since 2.8.3
*/
@ -16,7 +16,6 @@ public class LiteFlowException extends RuntimeException {
/**
* 构建一个异常
*
* @param message 异常描述信息
*/
public LiteFlowException(String message) {
@ -35,7 +34,6 @@ public class LiteFlowException extends RuntimeException {
/**
* 构建一个异常
*
* @param cause 异常对象
*/
public LiteFlowException(Throwable cause) {
@ -44,7 +42,6 @@ public class LiteFlowException extends RuntimeException {
/**
* 构建一个异常
*
* @param message 异常信息
* @param cause 异常对象
*/
@ -69,4 +66,5 @@ public class LiteFlowException extends RuntimeException {
public String getCode() {
return code;
}
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception;
/**
* 文件监听异常
*
* @author Bryan.Zhang
* @since 2.10.0
*/
@ -25,4 +26,5 @@ public class MonitorFileInitErrorException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 重复解析器异常
*
* @author Yun
*/
public class MultipleParsersException extends RuntimeException {
@ -23,4 +24,5 @@ public class MultipleParsersException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception;
/**
* 无可用插槽异常
*
* @author Yun
*/
public class NoAvailableSlotException extends RuntimeException {
@ -23,4 +24,5 @@ public class NoAvailableSlotException extends RuntimeException {
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 没有节点异常
*
* @author Yun
*/
public class NoForNodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoForNodeException(String message) {
this.message = message;
}
public NoForNodeException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 节点不为真异常
*
* @author Yun
*/
public class NoIfTrueNodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoIfTrueNodeException(String message) {
this.message = message;
}
public NoIfTrueNodeException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 没有节点异常
*
* @author Yun
*/
public class NoIteratorNodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoIteratorNodeException(String message) {
this.message = message;
}
public NoIteratorNodeException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -7,24 +7,24 @@ package com.yomahub.liteflow.exception;
*/
public class NoSuchContextBeanException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoSuchContextBeanException(String message) {
this.message = message;
}
public NoSuchContextBeanException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 无切换目标节点异常
*
* @author Yun
*/
public class NoSwitchTargetNodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoSwitchTargetNodeException(String message) {
this.message = message;
}
public NoSwitchTargetNodeException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 没有 While 节点异常
*
* @author Yun
*/
public class NoWhileNodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NoWhileNodeException(String message) {
this.message = message;
}
public NoWhileNodeException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -1,26 +1,28 @@
package com.yomahub.liteflow.exception;
/**
* 节点构建异常
*
* @author Yun
*/
public class NodeBuildException extends RuntimeException {
private static final long serialVersionUID = 1L;
/** 异常信息 */
private String message;
private static final long serialVersionUID = 1L;
public NodeBuildException(String message) {
this.message = message;
}
/** 异常信息 */
private String message;
@Override
public String getMessage() {
return message;
}
public NodeBuildException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 找不到节点类异常
*
* @author Yun
*/
public class NodeClassNotFoundException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NodeClassNotFoundException(String message) {
this.message = message;
}
public NodeClassNotFoundException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception;
/**
* 节点类型无法猜测异常
*
* @author Yun
*/
public class NodeTypeCanNotGuessException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 异常信息
*/
private String message;
/**
* 异常信息
*/
private String message;
public NodeTypeCanNotGuessException(String message) {
this.message = message;
}
public NodeTypeCanNotGuessException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
}

Some files were not shown because too many files have changed in this diff Show More