mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
优化Script功能模块的一些结构问题
This commit is contained in:
@@ -7,12 +7,13 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.9.0
|
||||
*/
|
||||
public class ScriptBreakComponent extends NodeBreakComponent{
|
||||
public class ScriptBreakComponent extends NodeBreakComponent implements ScriptComponent{
|
||||
@Override
|
||||
public boolean processBreak() throws Exception {
|
||||
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yomahub.liteflow.core;
|
||||
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 脚本组件类
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptCommonComponent extends NodeComponent implements ScriptComponent{
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
log.info("load script for component[{}]", getDisplayName());
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,11 @@
|
||||
package com.yomahub.liteflow.core;
|
||||
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 脚本组件类
|
||||
* 脚本接口
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
public class ScriptComponent extends NodeComponent{
|
||||
public interface ScriptComponent {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
public void loadScript(String script) {
|
||||
log.info("load script for component[{}]", getDisplayName());
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
void loadScript(String script);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.9.0
|
||||
*/
|
||||
public class ScriptForComponent extends NodeForComponent{
|
||||
public class ScriptForComponent extends NodeForComponent implements ScriptComponent{
|
||||
@Override
|
||||
public int processFor() throws Exception {
|
||||
return (int) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.8.5
|
||||
*/
|
||||
public class ScriptIfComponent extends NodeIfComponent{
|
||||
public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent{
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
return (boolean)ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptSwitchComponent extends NodeSwitchComponent {
|
||||
public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent{
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
return (String)ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.9.0
|
||||
*/
|
||||
public class ScriptWhileComponent extends NodeWhileComponent{
|
||||
public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent{
|
||||
|
||||
@Override
|
||||
public boolean processWhile() throws Exception {
|
||||
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(this.getCurrChainName(), getNodeId(), getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.yomahub.liteflow.enums;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import com.yomahub.liteflow.core.*;
|
||||
|
||||
/**
|
||||
@@ -21,7 +20,7 @@ public enum NodeTypeEnum {
|
||||
WHILE("while", "循环条件", false, NodeWhileComponent.class),
|
||||
|
||||
BREAK("break", "循环跳出", false, NodeBreakComponent.class),
|
||||
SCRIPT("script","脚本", true, ScriptComponent.class),
|
||||
SCRIPT("script","脚本", true, ScriptCommonComponent.class),
|
||||
|
||||
SWITCH_SCRIPT("switch_script", "选择脚本", true, ScriptSwitchComponent.class),
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GroovyScriptExecutor implements ScriptExecutor {
|
||||
try{
|
||||
if (!compiledScriptMap.containsKey(nodeId)){
|
||||
String errorMsg = StrUtil.format("script for node[{}] is not loaded", nodeId);
|
||||
throw new RuntimeException(errorMsg);
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}
|
||||
|
||||
CompiledScript compiledScript = compiledScriptMap.get(nodeId);
|
||||
|
||||
Reference in New Issue
Block a user