mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-23 21:18:10 +08:00
工程结构模块的改变
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.yomahub.liteflow.script;
|
||||
|
||||
/**
|
||||
* 脚本执行器接口
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public interface ScriptExecutor {
|
||||
|
||||
ScriptExecutor init();
|
||||
|
||||
void load(String nodeId, String script);
|
||||
|
||||
Object execute(String currChainName, String nodeId, int slotIndex);
|
||||
|
||||
void cleanCache();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.script;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yomahub.liteflow.script.exception.ScriptSpiException;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* 脚本执行器工厂类
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptExecutorFactory {
|
||||
|
||||
private static ScriptExecutorFactory scriptExecutorFactory;
|
||||
|
||||
private ScriptExecutor scriptExecutor;
|
||||
|
||||
public static ScriptExecutorFactory loadInstance(){
|
||||
if (ObjectUtil.isNull(scriptExecutorFactory)){
|
||||
scriptExecutorFactory = new ScriptExecutorFactory();
|
||||
}
|
||||
return scriptExecutorFactory;
|
||||
}
|
||||
|
||||
public ScriptExecutor getScriptExecutor(){
|
||||
if (ObjectUtil.isNull(scriptExecutor)){
|
||||
ServiceLoader<ScriptExecutor> loader = ServiceLoader.load(ScriptExecutor.class);
|
||||
|
||||
if (loader.iterator().hasNext()){
|
||||
scriptExecutor = loader.iterator().next().init();
|
||||
return scriptExecutor;
|
||||
}else{
|
||||
throw new ScriptSpiException("script spi component failed to load");
|
||||
}
|
||||
}
|
||||
return scriptExecutor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
package com.yomahub.liteflow.script.exception;
|
||||
|
||||
/**
|
||||
* 脚本运行异常
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptExecuteException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 异常信息 */
|
||||
private String message;
|
||||
|
||||
public ScriptExecuteException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
package com.yomahub.liteflow.script.exception;
|
||||
|
||||
/**
|
||||
* 脚本加载异常
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptLoadException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 异常信息 */
|
||||
private String message;
|
||||
|
||||
public ScriptLoadException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
package com.yomahub.liteflow.script.exception;
|
||||
|
||||
/**
|
||||
* 脚本SPI插件加载异常
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class ScriptSpiException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 异常信息 */
|
||||
private String message;
|
||||
|
||||
public ScriptSpiException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user