context) {
+ return ScriptVariableManager.getRegistered(context.getEngineName());
+ }
+
@Override
public String describe() {
return "script-" + getType() + "-" + super.describe();
}
+
+ @Override
+ public void visit(ConditionVisitor visitor) {
+ visitor.visitScript(script);
+ super.visit(visitor);
+ }
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java
index 8d20f40c910493e4192090ed48106195143a0a21..01222030e8525d7bd64e0650b6a15e61031ec639 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java
@@ -23,4 +23,11 @@ public interface ScriptConstants {
* Flow engine execution context.
*/
String CONTEXT = "context";
+
+ /**
+ * Alias for context.
+ *
+ * @since 1.0.5
+ */
+ String CTX = "ctx";
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptVariableManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptVariableManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..dc8d62839971000503dcfca32681644888fd3154
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptVariableManager.java
@@ -0,0 +1,60 @@
+package org.smartboot.flow.core.script;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ *
+ * 1、提供全局脚本变量注册
+ * 2、提供基于引擎维度的脚本变量注册
+ *
+ *
+ * @author qinluo
+ * @date 2023-01-17 19:41
+ * @since 1.0.5
+ */
+public class ScriptVariableManager {
+
+ /**
+ * 全局脚本变量注册
+ */
+ private static final Map GLOBAL = new ConcurrentHashMap<>();
+
+ /**
+ * 引擎维度脚本变量注册
+ */
+ private static final Map> ENGINE_VARIABLES = new ConcurrentHashMap<>();
+
+ public static void register(String key, Object variable) {
+ GLOBAL.put(key, variable);
+ }
+
+ public static Object remove(String key) {
+ return GLOBAL.remove(key);
+ }
+
+ public synchronized static void register(String engine, String key, Object variable) {
+ Map variables = ENGINE_VARIABLES.getOrDefault(engine, new ConcurrentHashMap<>(4));
+ variables.put(key, variable);
+ ENGINE_VARIABLES.put(engine, variables);
+ }
+
+ public static Object remove(String engine, String key) {
+ Map variables = ENGINE_VARIABLES.get(engine);
+ if (variables != null) {
+ return variables.remove(key);
+ }
+
+ return null;
+ }
+
+ public static Map getRegistered(String engine) {
+ Map allRegistered = new HashMap<>(GLOBAL);
+ Map variables = ENGINE_VARIABLES.get(engine);
+ if (variables != null) {
+ allRegistered.putAll(variables);
+ }
+ return allRegistered;
+ }
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Node.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Node.java
index 243deb20c19e273860d94cc80bfa04957dbdf913..031c837d20e872b028a8c3435b5020bc6b46252c 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Node.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Node.java
@@ -1,5 +1,7 @@
package org.smartboot.flow.core.trace;
+import org.smartboot.flow.core.EngineConstants;
+
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@@ -119,7 +121,7 @@ public class Node {
return "|---";
}
- if (prefix.length() == 4) {
+ if (prefix.length() == EngineConstants.TAB_SIZE) {
return (hasNext ? "|" : " ") + " |" + (async ? "~~~" : "---");
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java
index ed890c377cd59e2c0864d28992ac148dec42de99..8ba3a4becbb15210de0501b8509e2fd17ab03af0 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java
@@ -39,4 +39,21 @@ public final class AuxiliaryUtils {
return null;
}
}
+
+ public static void appendTab(StringBuilder sb, int numbersOfTab) {
+ for (int i = 0; i < numbersOfTab; i++) {
+ sb.append("\t");
+ }
+ }
+
+ public static String contact(String p, Object ...s) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(p);
+
+ for (Object suffix : s) {
+ sb.append("-").append(suffix);
+ }
+
+ return sb.toString();
+ }
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
deleted file mode 100644
index e1979185df85c8fbff103958d3bb14b7e7c023eb..0000000000000000000000000000000000000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.smartboot.flow.core.util;
-
-/**
- * @author qinluo
- * @date 2022/11/20 22:10
- * @since 1.0.0
- */
-public final class ContactUtils {
-
- public static String contact(String p, Object ...s) {
- StringBuilder sb = new StringBuilder();
- sb.append(p);
-
- for (Object suffix : s) {
- sb.append("-").append(suffix);
- }
-
- return sb.toString();
- }
-}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ComponentVisitor.java
index 77ff49359c894f3f843e39031d3c382c7fb3eb3b..3abce81dc2cecbfede71e0fbf2849a882c245af3 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ComponentVisitor.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ComponentVisitor.java
@@ -37,10 +37,11 @@ public class ComponentVisitor {
}
}
- public void visitCondition(String condition) {
+ public ConditionVisitor visitCondition(String condition) {
if (delegate != null) {
- delegate.visitCondition(condition);
+ return delegate.visitCondition(condition);
}
+ return null;
}
/**
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ConditionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ConditionVisitor.java
new file mode 100644
index 0000000000000000000000000000000000000000..7ba836bc4a7007b27518d08a101b97ed73ce328a
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/ConditionVisitor.java
@@ -0,0 +1,39 @@
+package org.smartboot.flow.core.visitor;
+
+import org.smartboot.flow.core.Condition;
+
+/**
+ * @author qinluo
+ * @date 2022-11-13 22:34:58
+ * @since 1.0.5
+ */
+public class ConditionVisitor {
+
+ protected ConditionVisitor delegate;
+
+ public ConditionVisitor() {
+ this(null);
+ }
+
+ public ConditionVisitor(ConditionVisitor delegate) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * Visit condition source.
+ */
+ public void visitSource(Condition condition) {
+ if (delegate != null) {
+ delegate.visitSource(condition);
+ }
+ }
+
+ /**
+ * Visit script.
+ */
+ public void visitScript(String script) {
+ if (delegate != null) {
+ delegate.visitScript(script);
+ }
+ }
+}
diff --git a/smart-flow-helper/pom.xml b/smart-flow-helper/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c13f06e685677842c4039e487ecbd8e4cac3aff5
--- /dev/null
+++ b/smart-flow-helper/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ smart-flow-parent
+ org.smartboot.flow
+ 1.0.5
+
+ 4.0.0
+
+ smart-flow-helper
+
+
+ 8
+ 8
+
+
+
+
+ org.smartboot.flow
+ smart-flow-core
+ 1.0.5
+
+
+
+
\ No newline at end of file
diff --git a/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeAdapter.java b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..a127e0bb460d8aa7d4d2c65d6f69b9242f2cb959
--- /dev/null
+++ b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeAdapter.java
@@ -0,0 +1,36 @@
+package org.smartboot.flow.helper.mock;
+
+import org.smartboot.flow.core.Adapter;
+import org.smartboot.flow.core.EngineContext;
+import org.smartboot.flow.core.common.Pair;
+
+/**
+ * Fake Class, do-nothing
+ *
+ * @author qinluo
+ * @date 2023/1/27 12:35
+ * @since 1.0.0
+ */
+public class FakeAdapter implements Adapter