From dea0d35303cde08ce36ed3a0f604ab7d59b2782f Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sat, 28 Jan 2023 20:09:28 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat=20#I6BDLN=20=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E7=9B=AE=E5=BD=95=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E6=89=80=E6=9C=89=E5=AD=90=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=E8=A7=84=E5=88=99=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BE=A6=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/FlowExecutor.java | 56 ++++++++------ .../yomahub/liteflow/monitor/MonitorFile.java | 73 +++++++++++++++++++ .../parser/el/LocalJsonFlowELParser.java | 7 ++ .../parser/el/LocalXmlFlowELParser.java | 6 ++ .../parser/el/LocalYmlFlowELParser.java | 6 ++ .../liteflow/property/LiteflowConfig.java | 11 +++ .../liteflow/spi/PathContentParser.java | 2 + .../spi/local/LocalPathContentParser.java | 33 ++++++++- .../spi/solon/SolonPathContentParser.java | 41 +++++++---- .../spi/spring/SpringPathContentParser.java | 51 ++++++++----- 10 files changed, 227 insertions(+), 59 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index da831e266..f9e99541b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -18,6 +18,7 @@ import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.id.IdGeneratorHolder; +import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.parser.base.FlowParser; import com.yomahub.liteflow.parser.factory.FlowParserProvider; import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; @@ -89,11 +90,11 @@ public class FlowExecutor { //所有的Parser的SPI实现都是以custom形式放入的,且只支持xml形式 ServiceLoader loader = ServiceLoader.load(ParserClassNameSpi.class); Iterator it = loader.iterator(); - if (it.hasNext()){ + if (it.hasNext()) { ParserClassNameSpi parserClassNameSpi = it.next(); ruleSource = "el_xml:" + parserClassNameSpi.getSpiClassName(); liteflowConfig.setRuleSource(ruleSource); - }else{ + } else { //ruleSource为空,而且没有spi形式的扩展,那么说明真的没有ruleSource //这种情况有可能是基于代码动态构建的 return; @@ -167,30 +168,37 @@ public class FlowExecutor { } //如果是ruleSource方式的,最后判断下有没有解析出来,如果没有解析出来则报错 - if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData()) && MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())){ - if (FlowBus.getChainMap().isEmpty()){ + 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){ + if (hook) { FlowInitHook.executeHook(); } + + // 文件监听 + if (liteflowConfig.getMonitorFileEnable()){ + MonitorFile.getInstance().create(); + } } //此方法就是从原有的配置源主动拉取新的进行刷新 //和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()){ + if (!response.isSuccess()) { throw response.getCause(); } } @@ -198,7 +206,7 @@ public class FlowExecutor { @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()){ + if (!response.isSuccess()) { throw response.getCause(); } } @@ -240,7 +248,7 @@ public class FlowExecutor { //调用一个流程并返回Future,允许多上下文的传入 public Future execute2Future(String chainId, Object param, Class... contextBeanClazzArray) { return ExecutorHelper.loadInstance().buildMainExecutor(liteflowConfig.getMainExecutorClass()).submit(() - -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray,null)); + -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray, null)); } @@ -251,11 +259,11 @@ public class FlowExecutor { //调用一个流程,返回默认的上下文,适用于简单的调用 @Deprecated - public DefaultContext execute(String chainId, Object param) throws Exception{ + public DefaultContext execute(String chainId, Object param) throws Exception { LiteflowResponse response = this.execute2Resp(chainId, param, DefaultContext.class); - if (!response.isSuccess()){ + if (!response.isSuccess()) { throw response.getCause(); - }else{ + } else { return response.getFirstContextBean(); } } @@ -269,8 +277,8 @@ public class FlowExecutor { } private LiteflowResponse invoke2Resp(String chainId, - Object param, - Integer slotIndex, InnerChainTypeEnum innerChainType) { + Object param, + Integer slotIndex, InnerChainTypeEnum innerChainType) { Slot slot = doExecute(chainId, param, null, null, slotIndex, innerChainType); return LiteflowResponse.newInnerResponse(chainId, slot); } @@ -288,9 +296,9 @@ public class FlowExecutor { //如果不是隐式流程,那么需要分配Slot if (innerChainType.equals(InnerChainTypeEnum.NONE) && ObjectUtil.isNull(slotIndex)) { //这里可以根据class分配,也可以根据bean去分配 - if (ArrayUtil.isNotEmpty(contextBeanClazzArray)){ + if (ArrayUtil.isNotEmpty(contextBeanClazzArray)) { slotIndex = DataBus.offerSlotByClass(ListUtil.toList(contextBeanClazzArray)); - }else{ + } else { slotIndex = DataBus.offerSlotByBean(ListUtil.toList(contextBeanArray)); } if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { @@ -311,7 +319,7 @@ public class FlowExecutor { //如果是隐式流程,事先把subException给置空,然后把隐式流程的chainId放入slot元数据中 //我知道这在多线程调用隐式流程中会有问题。但是考虑到这种场景的不会多,也有其他的转换方式。 //所以暂且这么做,以后再优化 - if (!innerChainType.equals(InnerChainTypeEnum.NONE)){ + if (!innerChainType.equals(InnerChainTypeEnum.NONE)) { slot.removeSubException(chainId); slot.addSubChain(chainId); } @@ -326,9 +334,9 @@ public class FlowExecutor { if (ObjectUtil.isNotNull(param)) { if (innerChainType.equals(InnerChainTypeEnum.NONE)) { slot.setRequestData(param); - } else if(innerChainType.equals(InnerChainTypeEnum.IN_SYNC)){ + } else if (innerChainType.equals(InnerChainTypeEnum.IN_SYNC)) { slot.setChainReqData(chainId, param); - } else if(innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)){ + } else if (innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)) { slot.setChainReqData2Queue(chainId, param); } } @@ -351,15 +359,15 @@ public class FlowExecutor { } 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())){ + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { LOG.error(errMsg, e); - }else{ + } else { LOG.error(errMsg); } - }else{ - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){ + } else { + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { LOG.error(e.getMessage(), e); - }else{ + } else { LOG.error(e.getMessage()); } } @@ -368,7 +376,7 @@ public class FlowExecutor { //如果是隐式流程,则需要设置到隐式流程的exception属性里 if (innerChainType.equals(InnerChainTypeEnum.NONE)) { slot.setException(e); - }else{ + } else { slot.setSubException(chainId, e); } } finally { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java new file mode 100644 index 000000000..c60e51b66 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java @@ -0,0 +1,73 @@ +package com.yomahub.liteflow.monitor; + +import cn.hutool.core.io.watch.SimpleWatcher; +import cn.hutool.core.io.watch.WatchMonitor; +import cn.hutool.core.io.watch.watchers.DelayWatcher; +import cn.hutool.core.lang.Singleton; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.file.Path; +import java.nio.file.WatchEvent; +import java.util.ArrayList; +import java.util.List; + +/** + * 规则文件监听器 + * + * @author tangkc + */ +public class MonitorFile { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final List PATH_LIST = new ArrayList<>(); + + public static MonitorFile getInstance() { + return Singleton.get(MonitorFile.class); + } + + /** + * 添加监听文件路径 + * + * @param filePath 文件路径 + */ + public void addMonitorFilePath(String filePath) { + PATH_LIST.add(filePath); + } + + /** + * 添加监听文件路径 + * + * @param filePaths 文件路径 + */ + public void addMonitorFilePaths(List filePaths) { + PATH_LIST.addAll(filePaths); + } + + /** + * 创建文件监听 + */ + public void create() { + for (String filePath : PATH_LIST) { + // 这里只监听两种类型,文件修改和文件覆盖 + WatchMonitor.createAll(filePath, new DelayWatcher(new SimpleWatcher() { + + @Override + public void onModify(WatchEvent event, Path currentPath) { + logger.info("file modify,filePath={}", filePath); + FlowExecutorHolder.loadInstance().reloadRule(); + } + + @Override + public void onOverflow(WatchEvent event, Path currentPath) { + logger.info("file over flow,filePath={}", filePath); + FlowExecutorHolder.loadInstance().reloadRule(); + } + // 在监听目录或文件时,如果这个文件有修改操作,JDK会多次触发modify方法,为了解决这个问题 + // 合并 500 毫秒内相同的变化 + }, 500)).start(); + } + } + +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java index c343b37c6..3386c45db 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java @@ -1,11 +1,13 @@ package com.yomahub.liteflow.parser.el; +import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; /** * 基于本地的json方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ @@ -14,6 +16,11 @@ public class LocalJsonFlowELParser extends JsonFlowELParser { @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + + // 添加规则文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + parse(contentList); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java index d0769f164..01e3e61e6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.parser.el; +import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; @@ -13,6 +14,11 @@ public class LocalXmlFlowELParser extends XmlFlowELParser{ @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + + // 添加规则文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + parse(contentList); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java index 8c85abef7..5cc92ef9c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.parser.el; +import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; @@ -14,6 +15,11 @@ public class LocalYmlFlowELParser extends YmlFlowELParser { @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + + // 添加规则文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + parse(contentList); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 072671d95..a26162917 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -94,6 +94,17 @@ public class LiteflowConfig { //替补组件class路径 private String substituteCmpClass; + // 规则文件/脚本文件变更监听 + private Boolean monitorFileEnable = Boolean.TRUE; + + public Boolean getMonitorFileEnable() { + return monitorFileEnable; + } + + public void setMonitorFileEnable(Boolean monitorFileEnable) { + this.monitorFileEnable = monitorFileEnable; + } + public Boolean getEnable() { if (ObjectUtil.isNull(enable)) { return Boolean.TRUE; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java index 10682a487..93f7a5117 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java @@ -5,4 +5,6 @@ import java.util.List; public interface PathContentParser extends SpiPriority{ List parseContent(List pathList) throws Exception; + + List getFileAbsolutePath(List pathList) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java index af7387b9e..5dc0bf808 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java @@ -2,6 +2,8 @@ package com.yomahub.liteflow.spi.local; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.io.resource.FileResource; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; @@ -18,14 +20,14 @@ public class LocalPathContentParser implements PathContentParser { @Override public List parseContent(List pathList) throws Exception { - if(CollectionUtil.isEmpty(pathList)){ + if (CollectionUtil.isEmpty(pathList)) { throw new ConfigErrorException("rule source must not be null"); } List contentList = new ArrayList<>(); - for(String path : pathList){ - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)){ + for (String path : pathList) { + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { path = FILE_URL_PREFIX + path; } else { if (!path.startsWith(CLASSPATH_URL_PREFIX)) { @@ -33,7 +35,7 @@ public class LocalPathContentParser implements PathContentParser { } } String content = ResourceUtil.readUtf8Str(path); - if (StrUtil.isNotBlank(content)){ + if (StrUtil.isNotBlank(content)) { contentList.add(content); } } @@ -41,6 +43,29 @@ public class LocalPathContentParser implements PathContentParser { return contentList; } + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + if (CollectionUtil.isEmpty(pathList)) { + throw new ConfigErrorException("rule source must not be null"); + } + + List result = new ArrayList<>(); + + for (String path : pathList) { + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + path = FILE_URL_PREFIX + path; + result.add(new FileResource(path).getFile().getAbsolutePath()); + } else { + if (!path.startsWith(CLASSPATH_URL_PREFIX)) { + path = CLASSPATH_URL_PREFIX + path; + result.add(new ClassPathResource(path).getAbsolutePath()); + } + } + } + + return result; + } + @Override public int priority() { return 2; diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java index b2774d0f1..aa21f1b6c 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java @@ -10,7 +10,7 @@ import com.yomahub.liteflow.spi.PathContentParser; import org.noear.solon.Utils; import java.io.File; -import java.net.URI; +import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashSet; @@ -20,7 +20,32 @@ import java.util.Set; public class SolonPathContentParser implements PathContentParser { @Override public List parseContent(List pathList) throws Exception { - if(CollectionUtil.isEmpty(pathList)){ + List allResource = getUrls(pathList); + + //转换成内容List + List contentList = new ArrayList<>(); + for (URL resource : allResource) { + String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8); + if (StrUtil.isNotBlank(content)) { + contentList.add(content); + } + } + + return contentList; + } + + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + List allResource = getUrls(pathList); + List result = new ArrayList<>(); + for (URL url : allResource) { + result.add(url.getPath()); + } + return result; + } + + private static List getUrls(List pathList) throws MalformedURLException { + if (CollectionUtil.isEmpty(pathList)) { throw new ConfigErrorException("rule source must not be null"); } @@ -44,17 +69,7 @@ public class SolonPathContentParser implements PathContentParser { if (fileTypeSet.size() != 1) { throw new ConfigErrorException("config error,please use the same type of configuration"); } - - //转换成内容List - List contentList = new ArrayList<>(); - for (URL resource : allResource) { - String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8); - if (StrUtil.isNotBlank(content)){ - contentList.add(content); - } - } - - return contentList; + return allResource; } @Override diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java index 791f2789e..f0f4f5157 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.spi.spring; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; @@ -9,24 +8,49 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.spi.PathContentParser; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.util.ResourceUtils; +import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; public class SpringPathContentParser implements PathContentParser { @Override public List parseContent(List pathList) throws Exception { - if(CollectionUtil.isEmpty(pathList)){ + List allResource = getResources(pathList); + + //转换成内容List + List contentList = new ArrayList<>(); + for (Resource resource : allResource) { + String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8); + if (StrUtil.isNotBlank(content)) { + contentList.add(content); + } + } + + return contentList; + } + + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + List allResource = getResources(pathList); + + //转换成内容List + List result = new ArrayList<>(); + for (Resource resource : allResource) { + result.add(resource.getFile().getAbsolutePath()); + } + return result; + } + + private List getResources(List pathList) throws IOException { + if (CollectionUtil.isEmpty(pathList)) { throw new ConfigErrorException("rule source must not be null"); } @@ -35,12 +59,12 @@ public class SpringPathContentParser implements PathContentParser { String locationPattern; //如果path是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)){ + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { locationPattern = ResourceUtils.FILE_URL_PREFIX + path; } else { if (!path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX) && !path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) { locationPattern = ResourceUtils.CLASSPATH_URL_PREFIX + path; - }else{ + } else { locationPattern = path; } } @@ -58,19 +82,10 @@ public class SpringPathContentParser implements PathContentParser { if (fileTypeSet.size() > 1) { throw new ConfigErrorException("config error,please use the same type of configuration"); } - - //转换成内容List - List contentList = new ArrayList<>(); - for (Resource resource : allResource) { - String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8); - if (StrUtil.isNotBlank(content)){ - contentList.add(content); - } - } - - return contentList; + return allResource; } + @Override public int priority() { return 1; From c6953b0f18d4c6b1566e8c392e82292aec63b001 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sun, 29 Jan 2023 09:17:37 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat=20#I6BDLN=20=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E7=9B=AE=E5=BD=95=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E6=89=80=E6=9C=89=E5=AD=90=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=E8=A7=84=E5=88=99=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BE=A6=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yomahub/liteflow/core/FlowExecutor.java | 2 +- .../com/yomahub/liteflow/property/LiteflowConfig.java | 10 +++++----- .../yomahub/liteflow/springboot/LiteflowProperty.java | 11 +++++++++++ .../config/LiteflowPropertyAutoConfiguration.java | 1 + .../additional-spring-configuration-metadata.json | 7 +++++++ .../resources/META-INF/liteflow-default.properties | 1 + 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index f9e99541b..90ab44c76 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -181,7 +181,7 @@ public class FlowExecutor { } // 文件监听 - if (liteflowConfig.getMonitorFileEnable()){ + if (liteflowConfig.getEnableMonitorFile()){ MonitorFile.getInstance().create(); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index a26162917..0f1179207 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -95,14 +95,14 @@ public class LiteflowConfig { private String substituteCmpClass; // 规则文件/脚本文件变更监听 - private Boolean monitorFileEnable = Boolean.TRUE; + private Boolean enableMonitorFile = Boolean.FALSE; - public Boolean getMonitorFileEnable() { - return monitorFileEnable; + public Boolean getEnableMonitorFile() { + return enableMonitorFile; } - public void setMonitorFileEnable(Boolean monitorFileEnable) { - this.monitorFileEnable = monitorFileEnable; + public void setEnableMonitorFile(Boolean enableMonitorFile) { + this.enableMonitorFile = enableMonitorFile; } public Boolean getEnable() { diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 2b7f33c1c..6b0155465 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -70,6 +70,17 @@ public class LiteflowProperty { //替补组件的class路径 private String substituteCmpClass; + // 规则文件/脚本文件变更监听 + private Boolean enableMonitorFile; + + public Boolean getEnableMonitorFile() { + return enableMonitorFile; + } + + public void setEnableMonitorFile(Boolean enableMonitorFile) { + this.enableMonitorFile = enableMonitorFile; + } + public boolean isEnable() { return enable; } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index bd7d4efbe..8f2f51506 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -47,6 +47,7 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); liteflowConfig.setSubstituteCmpClass(property.getSubstituteCmpClass()); + liteflowConfig.setEnableMonitorFile(property.getEnableMonitorFile()); return liteflowConfig; } } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d20c0e939..5258f753d 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -158,6 +158,13 @@ "description": "Set period time to print monitor log.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowMonitorProperty", "defaultValue": 300000 + }, + { + "name": "liteflow.enable-monitor-file", + "type": "java.lang.Boolean", + "description": "Set file change monitoring.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowMonitorProperty", + "defaultValue": false } ] } \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 35a41afd5..b3f17ce32 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -18,3 +18,4 @@ liteflow.monitor.enable-log=false liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 +liteflow.enable-monitor-file=false From 79ce3f1daae7d2078ece74bfb09e1cd3a5d7755a Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sun, 29 Jan 2023 10:56:12 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat=20#I6BDLN=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=96=87=E4=BB=B6=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java index 542974912..9321da703 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java @@ -7,6 +7,7 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.NodeBuildException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.element.Node; +import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,6 +135,10 @@ public class LiteFlowNodeBuilder { List scriptList = PathContentParserHolder.loadContextAware().parseContent(ListUtil.toList(filePath)); String script = CollUtil.getFirst(scriptList); setScript(script); + + // 添加脚本文件监听 + List 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); From 263ec5d21cd7e0dbbc2555d31695848072f4fd91 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sun, 29 Jan 2023 11:04:24 +0800 Subject: [PATCH 4/9] =?UTF-8?q?feat=20#I6BDLN=20=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yomahub/liteflow/monitor/MonitorFile.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java index c60e51b66..e9de20135 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.monitor; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.watch.SimpleWatcher; import cn.hutool.core.io.watch.WatchMonitor; import cn.hutool.core.io.watch.watchers.DelayWatcher; @@ -49,7 +50,7 @@ public class MonitorFile { * 创建文件监听 */ public void create() { - for (String filePath : PATH_LIST) { + for (String filePath : CollUtil.distinct(PATH_LIST)) { // 这里只监听两种类型,文件修改和文件覆盖 WatchMonitor.createAll(filePath, new DelayWatcher(new SimpleWatcher() { From ba1b9165fc6106d45d3a9b2ed7ea13e830ec0845 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 30 Jan 2023 22:06:41 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat=20#I6BDLN=20=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=8E=BB=E9=87=8D=E5=8A=9F=E8=83=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MonitorFileELDeclMultiSpringbootTest.java | 42 +++++++++++++++++ .../test/monitorFile/cmp/CmpConfig.java | 44 +++++++++++++++++ .../monitorFile/application.properties | 2 + .../test/resources/monitorFile/flow.el.xml | 7 +++ .../MonitorFileELDeclSpringbootTest.java | 42 +++++++++++++++++ .../liteflow/test/monitorFile/cmp/ACmp.java | 30 ++++++++++++ .../liteflow/test/monitorFile/cmp/BCmp.java | 30 ++++++++++++ .../liteflow/test/monitorFile/cmp/CCmp.java | 30 ++++++++++++ .../monitorFile/application.properties | 2 + .../test/resources/monitorFile/flow.el.xml | 7 +++ .../monitorFile/LiteflowMonitorFileTest.java | 42 +++++++++++++++++ .../liteflow/test/monitorFile/cmp/ACmp.java | 18 +++++++ .../liteflow/test/monitorFile/cmp/BCmp.java | 19 ++++++++ .../liteflow/test/monitorFile/cmp/CCmp.java | 19 ++++++++ .../test/resources/monitorFile/flow.el.xml | 13 +++++ .../monitorFile/MonitorFileGroovyELTest.java | 47 +++++++++++++++++++ .../script/groovy/monitorFile/cmp/ACmp.java | 20 ++++++++ .../script/groovy/monitorFile/cmp/BCmp.java | 21 +++++++++ .../script/groovy/monitorFile/cmp/CCmp.java | 21 +++++++++ .../script/groovy/monitorFile/cmp/DCmp.java | 29 ++++++++++++ .../monitorFile/application.properties | 2 + .../test/resources/monitorFile/flow.el.xml | 12 +++++ .../src/test/resources/monitorFile/s1.groovy | 3 ++ .../MonitorFileELSpringbootTest.java | 36 ++++++++++++++ .../liteflow/test/monitorFile/cmp/ACmp.java | 28 +++++++++++ .../liteflow/test/monitorFile/cmp/BCmp.java | 28 +++++++++++ .../liteflow/test/monitorFile/cmp/CCmp.java | 28 +++++++++++ .../monitorFile/application.properties | 2 + .../test/resources/monitorFile/flow.el.xml | 7 +++ 29 files changed, 631 insertions(+) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/monitorFile/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/MonitorFileGroovyELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/s1.groovy create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java new file mode 100644 index 000000000..1d9caf64b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.File; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitorFile/application.properties") +@SpringBootTest(classes = MonitorFileELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +public class MonitorFileELDeclMultiSpringbootTest { + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java new file mode 100644 index 000000000..d794c9053 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Random; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } +} + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties new file mode 100644 index 000000000..361f7e90e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=monitorFile/flow.el.xml +liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..98c3cbae6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, b, c); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java new file mode 100644 index 000000000..b4bc848bc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.File; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitorFile/application.properties") +@SpringBootTest(classes = MonitorFileELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +public class MonitorFileELDeclSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java new file mode 100644 index 000000000..296b2f62e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("a") +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java new file mode 100644 index 000000000..042853aa6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("b") +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java new file mode 100644 index 000000000..2d80c88f5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("c") +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties new file mode 100644 index 000000000..361f7e90e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=monitorFile/flow.el.xml +liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..98c3cbae6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, b, c); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java new file mode 100644 index 000000000..bda2f5f3b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +public class LiteflowMonitorFileTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("monitorFile/flow.el.xml"); + config.setEnableMonitorFile(true); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testMultipleType() throws InterruptedException { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java new file mode 100644 index 000000000..f022ab133 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -0,0 +1,18 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java new file mode 100644 index 000000000..8b108f065 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java new file mode 100644 index 000000000..6323f2318 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..f436cc9cb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,13 @@ + + + + + + + + + + THEN(a, b, c); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/MonitorFileGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/MonitorFileGroovyELTest.java new file mode 100644 index 000000000..b3a3f66fe --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/MonitorFileGroovyELTest.java @@ -0,0 +1,47 @@ +package com.yomahub.liteflow.test.script.groovy.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.File; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitorFile/application.properties") +@SpringBootTest(classes = MonitorFileGroovyELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.groovy.monitorFile.cmp"}) +public class MonitorFileGroovyELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + String absolutePath = new ClassPathResource("classpath:/monitorFile/s1.groovy").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("a=3", "a=2"); + FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(4), context.getData("s1")); + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/ACmp.java new file mode 100644 index 000000000..fc46a1502 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/monitorFile/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

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

Title: liteflow

+ *

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

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

Title: liteflow

+ *

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

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

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.groovy.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)){ + int count = context.getData(key); + context.setData(key, ++count); + }else{ + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/application.properties new file mode 100644 index 000000000..361f7e90e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=monitorFile/flow.el.xml +liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..8cb2b8655 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,12 @@ + + + + + + + + + THEN(a, b, c, s1); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/s1.groovy b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/s1.groovy new file mode 100644 index 000000000..02ae4756f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/monitorFile/s1.groovy @@ -0,0 +1,3 @@ +Integer a=3 +Integer b=2 +defaultContext.setData("s1",a*b) \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java new file mode 100644 index 000000000..b1e45fa39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonJUnit4ClassRunner; +import org.noear.solon.test.annotation.TestPropertySource; + +import java.io.File; + +@RunWith(SolonJUnit4ClassRunner.class) +@TestPropertySource("classpath:/monitorFile/application.properties") +public class MonitorFileELSpringbootTest { + + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java new file mode 100644 index 000000000..e56e014b5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +import java.util.Random; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java new file mode 100644 index 000000000..08608f56b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +import java.util.Random; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java new file mode 100644 index 000000000..f39944edf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +import java.util.Random; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties new file mode 100644 index 000000000..361f7e90e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=monitorFile/flow.el.xml +liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..98c3cbae6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, b, c); + + + \ No newline at end of file From ec48c71a9d155a3049a5783d1678f4be51a08bf7 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 30 Jan 2023 22:14:26 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat=20#I6BDLN=20=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=8E=BB=E9=87=8D=E5=8A=9F=E8=83=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MonitorFileELSpringbootTest.java | 43 +++++++++++++++++++ .../liteflow/test/monitorFile/cmp/ACmp.java | 28 ++++++++++++ .../liteflow/test/monitorFile/cmp/BCmp.java | 28 ++++++++++++ .../liteflow/test/monitorFile/cmp/CCmp.java | 28 ++++++++++++ .../monitorFile/application.properties | 2 + .../test/resources/monitorFile/flow.el.xml | 7 +++ 6 files changed, 136 insertions(+) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java new file mode 100644 index 000000000..c9a403bf8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.monitorFile; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.util.CharsetUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.File; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitorFile/application.properties") +@SpringBootTest(classes = MonitorFileELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +public class MonitorFileELSpringbootTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + + Thread.sleep(1000); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java new file mode 100644 index 000000000..fa8d164cf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java new file mode 100644 index 000000000..5a43cdda7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java new file mode 100644 index 000000000..71b96537f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitorFile.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/application.properties new file mode 100644 index 000000000..361f7e90e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=monitorFile/flow.el.xml +liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml new file mode 100644 index 000000000..98c3cbae6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, b, c); + + + \ No newline at end of file From dd22f0e0f554e287b4e161d20611b4492facb853 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 30 Jan 2023 22:18:34 +0800 Subject: [PATCH 7/9] =?UTF-8?q?feat=20#I6BDLN=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/spi/PathContentParser.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java index 93f7a5117..c39b4f74a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java @@ -2,9 +2,23 @@ package com.yomahub.liteflow.spi; import java.util.List; -public interface PathContentParser extends SpiPriority{ +public interface PathContentParser extends SpiPriority { + /** + * 解析路径下的文件内容 + * + * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 PathMatchingResourcePatternResolver 规则) + * @return 返回文件内容 + * @throws Exception ex + */ List parseContent(List pathList) throws Exception; + /** + * 获取文件路径的绝对路径 + * + * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 PathMatchingResourcePatternResolver 规则) + * @return 返回文件绝对路径 + * @throws Exception ex + */ List getFileAbsolutePath(List pathList) throws Exception; } From e0b08a714fb0a59b51b84cf2ff3e58a2c2c67220 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Fri, 3 Feb 2023 10:54:33 +0800 Subject: [PATCH 8/9] =?UTF-8?q?feat=20#I6BDLN=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=96=87=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=99=A8=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/FlowExecutor.java | 20 ++++++++++++++++++- .../parser/el/LocalJsonFlowELParser.java | 6 ------ .../parser/el/LocalXmlFlowELParser.java | 6 ------ .../parser/el/LocalYmlFlowELParser.java | 6 ------ .../spi/solon/SolonPathContentParser.java | 8 +++----- .../spi/spring/SpringPathContentParser.java | 18 +++++++++++------ 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 90ab44c76..655f1abef 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -28,6 +28,7 @@ import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import com.yomahub.liteflow.spi.holder.ContextCmpInitHolder; +import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import com.yomahub.liteflow.thread.ExecutorHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,6 +126,9 @@ public class FlowExecutor { //支持多类型的配置文件,分别解析 if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) { + // 添加监听文件路径 + addMonitorFilePaths(ListUtil.toList(path)); + // 解析文件 parser.parseMain(ListUtil.toList(path)); } } catch (CyclicDependencyException e) { @@ -149,6 +153,9 @@ public class FlowExecutor { //进行多个配置文件的一起解析 try { if (parser != null) { + // 添加监听文件路径 + addMonitorFilePaths(rulePathList); + // 解析文件 parser.parseMain(rulePathList); } else { throw new ConfigErrorException("parse error, please check liteflow config property"); @@ -181,7 +188,7 @@ public class FlowExecutor { } // 文件监听 - if (liteflowConfig.getEnableMonitorFile()){ + if (liteflowConfig.getEnableMonitorFile()) { MonitorFile.getInstance().create(); } } @@ -397,4 +404,15 @@ public class FlowExecutor { //把liteFlowConfig设到LiteFlowGetter中去 LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); } + + /** + * 添加监听文件路径 + * + * @param pathList 文件路径 + */ + private void addMonitorFilePaths(List pathList) throws Exception { + // 添加规则文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + } } \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java index 3386c45db..6c6aa1a91 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.parser.el; -import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; @@ -16,11 +15,6 @@ public class LocalJsonFlowELParser extends JsonFlowELParser { @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - - // 添加规则文件监听 - List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); - MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); - parse(contentList); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java index 01e3e61e6..d0769f164 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.parser.el; -import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; @@ -14,11 +13,6 @@ public class LocalXmlFlowELParser extends XmlFlowELParser{ @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - - // 添加规则文件监听 - List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); - MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); - parse(contentList); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java index 5cc92ef9c..8c85abef7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.parser.el; -import com.yomahub.liteflow.monitor.MonitorFile; import com.yomahub.liteflow.spi.holder.PathContentParserHolder; import java.util.List; @@ -15,11 +14,6 @@ public class LocalYmlFlowELParser extends YmlFlowELParser { @Override public void parseMain(List pathList) throws Exception { List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - - // 添加规则文件监听 - List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); - MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); - parse(contentList); } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java index aa21f1b6c..fa14632a3 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.spi.solon; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.stream.StreamUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; @@ -16,6 +17,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class SolonPathContentParser implements PathContentParser { @Override @@ -37,11 +39,7 @@ public class SolonPathContentParser implements PathContentParser { @Override public List getFileAbsolutePath(List pathList) throws Exception { List allResource = getUrls(pathList); - List result = new ArrayList<>(); - for (URL url : allResource) { - result.add(url.getPath()); - } - return result; + return StreamUtil.of(allResource).map(URL::getPath).collect(Collectors.toList()); } private static List getUrls(List pathList) throws MalformedURLException { diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java index f0f4f5157..a0f433ce4 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.stream.StreamUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; @@ -19,6 +20,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class SpringPathContentParser implements PathContentParser { @Override @@ -41,12 +43,16 @@ public class SpringPathContentParser implements PathContentParser { public List getFileAbsolutePath(List pathList) throws Exception { List allResource = getResources(pathList); - //转换成内容List - List result = new ArrayList<>(); - for (Resource resource : allResource) { - result.add(resource.getFile().getAbsolutePath()); - } - return result; + return StreamUtil.of(allResource) + // 过滤非 file 类型 Resource + .filter(Resource::isFile) + .map(r -> { + try { + return r.getFile().getAbsolutePath(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); } private List getResources(List pathList) throws IOException { From 32e24769b0875cfdb5ce05ceee25b7812ff7ec7c Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Fri, 3 Feb 2023 11:32:08 +0800 Subject: [PATCH 9/9] =?UTF-8?q?feat=20#I6BDLN=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=99=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A7=A3=E6=9E=90=E5=99=A8?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/spi/local/LocalPathContentParser.java | 9 +++++++-- .../liteflow/spi/solon/SolonPathContentParser.java | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java index 5dc0bf808..d8d34d5ad 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java @@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.resource.ClassPathResource; import cn.hutool.core.io.resource.FileResource; import cn.hutool.core.io.resource.ResourceUtil; +import cn.hutool.core.util.ClassLoaderUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.spi.PathContentParser; @@ -52,13 +53,17 @@ public class LocalPathContentParser implements PathContentParser { List result = new ArrayList<>(); for (String path : pathList) { - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { path = FILE_URL_PREFIX + path; result.add(new FileResource(path).getFile().getAbsolutePath()); } else { if (!path.startsWith(CLASSPATH_URL_PREFIX)) { path = CLASSPATH_URL_PREFIX + path; - result.add(new ClassPathResource(path).getAbsolutePath()); + + // 这里会有自定义解析器 + if(ClassLoaderUtil.isPresent(path)){ + result.add(new ClassPathResource(path).getAbsolutePath()); + } } } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java index fa14632a3..e25dbe9ae 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java @@ -39,7 +39,10 @@ public class SolonPathContentParser implements PathContentParser { @Override public List getFileAbsolutePath(List pathList) throws Exception { List allResource = getUrls(pathList); - return StreamUtil.of(allResource).map(URL::getPath).collect(Collectors.toList()); + return StreamUtil.of(allResource) + .map(URL::getPath) + .filter(FileUtil::isFile) + .collect(Collectors.toList()); } private static List getUrls(List pathList) throws MalformedURLException { @@ -57,14 +60,16 @@ public class SolonPathContentParser implements PathContentParser { path = path.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()); } - allResource.add(Utils.getResource(path)); + if (Utils.getResource(path) != null) { + allResource.add(Utils.getResource(path)); + } } } //如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 Set fileTypeSet = new HashSet<>(); allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getPath()))); - if (fileTypeSet.size() != 1) { + if (fileTypeSet.size() > 1) { throw new ConfigErrorException("config error,please use the same type of configuration"); } return allResource;