From 151758241f5703d1156befb2553ce59a413987b7 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Mon, 28 Nov 2022 17:54:50 +0800 Subject: [PATCH 01/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20test?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=B0=83=E6=95=B4=20=20=20=20=20=20-=20xsd?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- smart-flow-core/pom.xml | 2 +- ...rt-flow-1.0.0.xsd => smart-flow-1.0.1.xsd} | 116 +++++++++++++++--- .../org/smartboot/flow/core/AsyncStep1.java | 17 --- .../org/smartboot/flow/core/AsyncStep2.java | 21 ---- .../org/smartboot/flow/core/AsyncStep3.java | 21 ---- .../org/smartboot/flow/core/BaseTest.java | 21 ---- .../smartboot/flow/core/ChooseCondition.java | 22 ---- .../org/smartboot/flow/core/DefaultStep.java | 17 --- .../org/smartboot/flow/core/ElseStep.java | 17 --- .../org/smartboot/flow/core/ErrorStep.java | 17 --- .../org/smartboot/flow/core/IfCondition.java | 15 --- .../org/smartboot/flow/core/IfCondition2.java | 15 --- .../org/smartboot/flow/core/IfCondition3.java | 15 --- .../org/smartboot/flow/core/IntegerStep.java | 17 --- .../org/smartboot/flow/core/NullStep.java | 17 --- .../java/org/smartboot/flow/core/Step2.java | 21 ---- .../java/org/smartboot/flow/core/Step3.java | 17 --- .../java/org/smartboot/flow/core/Step4.java | 17 --- .../java/org/smartboot/flow/core/Step5.java | 17 --- .../java/org/smartboot/flow/core/Step6.java | 17 --- .../src/test/resources/log4j.properties | 59 --------- .../src/test/resources/log4j2.properties | 6 - .../test/resources/log4jdbc.log4j2.properties | 2 - smart-flow-example/pom.xml | 4 +- .../example/{extension => }/AsyncStep1.java | 2 +- .../example/{extension => }/AsyncStep2.java | 2 +- .../example/{extension => }/AsyncStep3.java | 2 +- .../{extension => }/ChooseCondition.java | 2 +- .../example/{extension => }/DefaultStep.java | 2 +- .../example/{extension => }/ElseStep.java | 2 +- .../example/{extension => }/ErrorStep.java | 2 +- .../example/{extension => }/IfCondition.java | 2 +- .../example/{extension => }/IfCondition2.java | 2 +- .../example/{extension => }/IfCondition3.java | 2 +- .../example/{extension => }/IntegerStep.java | 2 +- .../example/{extension => }/NullStep.java | 2 +- .../org/smartboot/flow/example}/Step1.java | 2 +- .../flow/example/{extension => }/Step2.java | 2 +- .../flow/example/{extension => }/Step3.java | 2 +- .../flow/example/{extension => }/Step4.java | 2 +- .../flow/example/{extension => }/Step5.java | 2 +- .../flow/example/{extension => }/Step6.java | 2 +- .../flow/example/extension/Step1.java | 17 --- .../src/main/resources/bean.xml | 12 +- .../src/main}/resources/flow-example.xsd | 0 .../src/main}/resources/flow-example3.xsd | 6 +- .../src/main}/resources/flow-example4.xsd | 10 +- .../src/main}/resources/flow-example5.xsd | 24 ++-- .../src/main}/resources/flow-example6.xsd | 32 ++--- .../src/main}/resources/flow-example7.xsd | 36 +++--- .../smartboot/flow/example}/EngineTest.java | 6 +- .../flow/example}/async/AsyncTest.java | 28 ++--- .../example}/attributes/AttributeTest.java | 16 +-- .../builder/IfComponentBuilderTest.java | 17 +-- .../flow/example}/manager/ManagerTest.java | 28 ++--- .../example}/parser/DefaultParserTest.java | 12 +- smart-flow-manager/pom.xml | 4 +- smart-flow-spring-extension/pom.xml | 4 +- 59 files changed, 236 insertions(+), 564 deletions(-) rename smart-flow-core/src/main/resources/{smart-flow-1.0.0.xsd => smart-flow-1.0.1.xsd} (61%) delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep1.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep2.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep3.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/BaseTest.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/ChooseCondition.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/DefaultStep.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/ElseStep.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/ErrorStep.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition2.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition3.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/IntegerStep.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/NullStep.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/Step2.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/Step3.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/Step4.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/Step5.java delete mode 100644 smart-flow-core/src/test/java/org/smartboot/flow/core/Step6.java delete mode 100644 smart-flow-core/src/test/resources/log4j.properties delete mode 100644 smart-flow-core/src/test/resources/log4j2.properties delete mode 100644 smart-flow-core/src/test/resources/log4jdbc.log4j2.properties rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/AsyncStep1.java (88%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/AsyncStep2.java (90%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/AsyncStep3.java (90%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/ChooseCondition.java (91%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/DefaultStep.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/ElseStep.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/ErrorStep.java (90%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/IfCondition.java (88%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/IfCondition2.java (88%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/IfCondition3.java (88%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/IntegerStep.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/NullStep.java (91%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/main/java/org/smartboot/flow/example}/Step1.java (90%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/Step2.java (87%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/Step3.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/Step4.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/Step5.java (89%) rename smart-flow-example/src/main/java/org/smartboot/flow/example/{extension => }/Step6.java (89%) delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example.xsd (100%) rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example3.xsd (61%) rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example4.xsd (51%) rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example5.xsd (32%) rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example6.xsd (31%) rename {smart-flow-core/src/test => smart-flow-example/src/main}/resources/flow-example7.xsd (30%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/EngineTest.java (97%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/async/AsyncTest.java (75%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/attributes/AttributeTest.java (81%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/builder/IfComponentBuilderTest.java (69%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/manager/ManagerTest.java (80%) rename {smart-flow-core/src/test/java/org/smartboot/flow/core => smart-flow-example/src/test/java/org/smartboot/flow/example}/parser/DefaultParserTest.java (91%) diff --git a/pom.xml b/pom.xml index d524125..913c77d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartboot flow-engine - 1.0.1 + 1.0.2 4.0.0 pom diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index 5fefaf4..6b2cc8d 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -5,7 +5,7 @@ org.smartboot flow-engine - 1.0.1 + 1.0.2 4.0.0 diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.0.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd similarity index 61% rename from smart-flow-core/src/main/resources/smart-flow-1.0.0.xsd rename to smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index a7c7130..08a15cc 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.0.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -3,6 +3,75 @@ targetNamespace="http://org.smartboot/smart-flow" elementFormDefault="qualified"> + + + + + 设置组件是否可回滚,默认为false,不可回滚, 仅对基本类型组件生效 + + + + + + + + 设置组件是否可降级,默认为false,开启降级时,当组件执行发生异常不会中断流程 + + + + + + + + 设置组件是否异步执行,默认false,注意设置此属性需要指定Executor + + + + + + + + 异步组件超时时间,单位毫秒(ms) + + + + + + + + 设置组件的前置依赖组件名称,当前置组件为异步组件时,会等待异步组件执行完毕后开始执行当前组件 + 多个组件名称以,分割 + + + + + + + + 启用/禁用组件,默认启用组件,设置为false,禁用该组件时,该组件不会执行 + + + + + + + + + + + + + + + + + + + + + + + @@ -12,6 +81,9 @@ + + + @@ -59,9 +131,13 @@ - - - + + + + + + + @@ -74,8 +150,12 @@ - - + + + + + + @@ -94,8 +174,8 @@ - - + + @@ -114,14 +194,12 @@ - - + + - - @@ -133,8 +211,12 @@ - - + + + + + + @@ -153,8 +235,8 @@ - - + + @@ -173,8 +255,8 @@ - - + + diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep1.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep1.java deleted file mode 100644 index b79b2c9..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep1.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class AsyncStep1 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep2.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep2.java deleted file mode 100644 index 91f02ba..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep2.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class AsyncStep2 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - try { - Thread.sleep(100); - } catch (Exception e) { - - } - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep3.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep3.java deleted file mode 100644 index c3a6eba..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/AsyncStep3.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class AsyncStep3 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - try { - Thread.sleep(200); - } catch (Exception e) { - - } - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/BaseTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/BaseTest.java deleted file mode 100644 index 12b0b87..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/BaseTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartboot.flow.core; - -import org.junit.jupiter.api.BeforeEach; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.manager.DefaultEngineManager; - -/** - * @author yamikaze - * @date 2022/11/13 - */ -public class BaseTest { - - protected static final Logger LOGGER = LoggerFactory.getLogger(BaseTest.class); - - @BeforeEach - public void setUp() { - DefaultEngineManager.getDefaultManager().detachAll(); - } - -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/ChooseCondition.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/ChooseCondition.java deleted file mode 100644 index 217a2b0..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/ChooseCondition.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.smartboot.flow.core; - - -/** - * @author qinluo - * @date 2022-11-11 16:45:21 - * @since 1.0.0 - */ -public class ChooseCondition extends Condition { - - @Override - public Object test(Integer integer, String s) { - if (integer == null) { - return "null"; - } else if (integer == 1) { - return 1; - } else if (integer == 2) { - return 2; - } - return null; - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/DefaultStep.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/DefaultStep.java deleted file mode 100644 index 9cdddb1..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/DefaultStep.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 16:44:21 - * @since 1.0.0 - */ -public class DefaultStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/ElseStep.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/ElseStep.java deleted file mode 100644 index 6a88b8b..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/ElseStep.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 16:44:21 - * @since 1.0.0 - */ -public class ElseStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/ErrorStep.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/ErrorStep.java deleted file mode 100644 index d275f29..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/ErrorStep.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class ErrorStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("error executed ======="); - throw new IllegalArgumentException("Error"); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition.java deleted file mode 100644 index f2dc883..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.smartboot.flow.core; - - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -public class IfCondition extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition2.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition2.java deleted file mode 100644 index 6bc14ba..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition2.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.smartboot.flow.core; - - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -public class IfCondition2 extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition3.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition3.java deleted file mode 100644 index 4ecfc6b..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/IfCondition3.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.smartboot.flow.core; - - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -public class IfCondition3 extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/IntegerStep.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/IntegerStep.java deleted file mode 100644 index 9ddd607..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/IntegerStep.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class IntegerStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/NullStep.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/NullStep.java deleted file mode 100644 index aae7289..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/NullStep.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class NullStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step2.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/Step2.java deleted file mode 100644 index 7e6dda7..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step2.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step2 extends AbstractExecutable { - - public Step2() { - System.out.println("create new step2 instance"); - } - - @Override - public void execute(Integer integer, String s) { - System.out.println("step2 == " + integer); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step3.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/Step3.java deleted file mode 100644 index 7914637..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step3.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step3 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step3 == " + integer); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step4.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/Step4.java deleted file mode 100644 index 41812a2..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step4.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step4 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step4 == " + integer); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step5.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/Step5.java deleted file mode 100644 index 26e2b33..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step5.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step5 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step5 == " + integer); - } -} diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step6.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/Step6.java deleted file mode 100644 index 78815b4..0000000 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step6.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.core; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step6 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step5 == " + integer); - } -} diff --git a/smart-flow-core/src/test/resources/log4j.properties b/smart-flow-core/src/test/resources/log4j.properties deleted file mode 100644 index 05ad41f..0000000 --- a/smart-flow-core/src/test/resources/log4j.properties +++ /dev/null @@ -1,59 +0,0 @@ -### direct log messages to stdout ### -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.debug=org.apache.log4j.ConsoleAppender -log4j.appender.debug.layout=org.apache.log4j.PatternLayout -log4j.appender.debug.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.warn=org.apache.log4j.ConsoleAppender -log4j.appender.warn.layout=org.apache.log4j.PatternLayout -log4j.appender.warn.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.error=org.apache.log4j.ConsoleAppender -log4j.appender.error.layout=org.apache.log4j.PatternLayout -log4j.appender.error.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -### direct messages to file hibernate.log ### -#log4j.appender.file=org.apache.log4j.FileAppender -#log4j.appender.file.File=hibernate.log -#log4j.appender.file.layout=org.apache.log4j.PatternLayout -#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### set log levels - for more verbose logging change 'info' to 'debug' ### - -log4j.rootLogger=info,stdout - -#log4j.logger.org.hibernate=info -#log4j.logger.org.hibernate=debug - -### log HQL query parser activity -#log4j.logger.org.hibernate.hql.ast.AST=debug - -### log just the SQL -#log4j.logger.org.hibernate.SQL=debug - -### log JDBC bind parameters ### -#log4j.logger.org.hibernate.type=info -#log4j.logger.org.hibernate.type=debug - -### log schema export/update ### -log4j.logger.org.hibernate.tool.hbm2ddl=debug - -### log HQL parse trees -#log4j.logger.org.hibernate.hql=debug - -### log cache activity ### -#log4j.logger.org.hibernate.cache=debug - -### log transaction activity -#log4j.logger.org.hibernate.transaction=debug - -### log JDBC resource acquisition -#log4j.logger.org.hibernate.jdbc=debug - -### enable the following line if you want to track down connection ### -### leakages when using DriverManagerConnectionProvider ### -#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace diff --git a/smart-flow-core/src/test/resources/log4j2.properties b/smart-flow-core/src/test/resources/log4j2.properties deleted file mode 100644 index fced116..0000000 --- a/smart-flow-core/src/test/resources/log4j2.properties +++ /dev/null @@ -1,6 +0,0 @@ -appender.console.type = Console -appender.console.name = console -appender.console.layout.type = PatternLayout - -rootLogger.level = info -rootLogger.appenderRef.console.ref = console \ No newline at end of file diff --git a/smart-flow-core/src/test/resources/log4jdbc.log4j2.properties b/smart-flow-core/src/test/resources/log4jdbc.log4j2.properties deleted file mode 100644 index 76f2440..0000000 --- a/smart-flow-core/src/test/resources/log4jdbc.log4j2.properties +++ /dev/null @@ -1,2 +0,0 @@ -#log4jdbc-log4j2默认只支持log4j2,如果想要支持slf4j,则需要增加如下配置: -log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator \ No newline at end of file diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml index fd01f88..e4b6f30 100644 --- a/smart-flow-example/pom.xml +++ b/smart-flow-example/pom.xml @@ -20,13 +20,13 @@ org.smartboot smart-flow-manager - 1.0.1 + 1.0.2 org.smartboot smart-flow-spring-extension - 1.0.1 + 1.0.2 diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java similarity index 88% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep1.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java index 67645c0..0347c92 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep1.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java similarity index 90% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java index 8bff547..8a94014 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java similarity index 90% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java index f326a1d..2c20351 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java similarity index 91% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java index 0bba277..9bab376 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.Condition; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java index 679f1a7..d021efc 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java index 22d4295..b334791 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java similarity index 90% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java index f0b97fe..79d0e29 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; import org.springframework.stereotype.Service; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java similarity index 88% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java index 99b01b2..b1f1e44 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.Condition; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java similarity index 88% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java index 4533495..8e1c17c 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.Condition; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java similarity index 88% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java index 1fb61d9..eb9ac14 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.Condition; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java index 54dbeb4..ec2be0d 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java similarity index 91% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java index f3c6512..c1e43b3 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java similarity index 90% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/Step1.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java index 64e989c..92b06f9 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/Step1.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.core; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java similarity index 87% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java index 0fa36eb..3538277 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java index 5c1a1da..107320d 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java index d343a89..20e90a6 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java index 3cd8014..fd4b890 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java similarity index 89% rename from smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java rename to smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java index 54b3661..9a4c7fa 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.example.extension; +package org.smartboot.flow.example; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java deleted file mode 100644 index a0ff762..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.example.extension; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step1 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step1 == " + integer); - } -} diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 64a4bd9..0b07af6 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -8,7 +8,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://org.smartboot/smart-flow - http://org.smartboot/smart-flow-1.0.0.xsd"> + http://org.smartboot/smart-flow-1.0.1.xsd"> @@ -29,13 +29,13 @@ - - + + - - + + @@ -56,7 +56,7 @@ - + diff --git a/smart-flow-core/src/test/resources/flow-example.xsd b/smart-flow-example/src/main/resources/flow-example.xsd similarity index 100% rename from smart-flow-core/src/test/resources/flow-example.xsd rename to smart-flow-example/src/main/resources/flow-example.xsd diff --git a/smart-flow-core/src/test/resources/flow-example3.xsd b/smart-flow-example/src/main/resources/flow-example3.xsd similarity index 61% rename from smart-flow-core/src/test/resources/flow-example3.xsd rename to smart-flow-example/src/main/resources/flow-example3.xsd index 515e723..c9c057c 100644 --- a/smart-flow-core/src/test/resources/flow-example3.xsd +++ b/smart-flow-example/src/main/resources/flow-example3.xsd @@ -2,14 +2,14 @@ + http://org.smartboot/smart-flow-1.0.1.xsd"> - - + + \ No newline at end of file diff --git a/smart-flow-core/src/test/resources/flow-example4.xsd b/smart-flow-example/src/main/resources/flow-example4.xsd similarity index 51% rename from smart-flow-core/src/test/resources/flow-example4.xsd rename to smart-flow-example/src/main/resources/flow-example4.xsd index bf60fa1..00c2731 100644 --- a/smart-flow-core/src/test/resources/flow-example4.xsd +++ b/smart-flow-example/src/main/resources/flow-example4.xsd @@ -2,17 +2,17 @@ + http://org.smartboot/smart-flow-1.0.1.xsd"> - - + + - - + + diff --git a/smart-flow-core/src/test/resources/flow-example5.xsd b/smart-flow-example/src/main/resources/flow-example5.xsd similarity index 32% rename from smart-flow-core/src/test/resources/flow-example5.xsd rename to smart-flow-example/src/main/resources/flow-example5.xsd index 1373e14..f529a8a 100644 --- a/smart-flow-core/src/test/resources/flow-example5.xsd +++ b/smart-flow-example/src/main/resources/flow-example5.xsd @@ -2,26 +2,26 @@ + http://org.smartboot/smart-flow-1.0.1.xsd"> - - + + - - + + - - - + + + - - - - + + + + diff --git a/smart-flow-core/src/test/resources/flow-example6.xsd b/smart-flow-example/src/main/resources/flow-example6.xsd similarity index 31% rename from smart-flow-core/src/test/resources/flow-example6.xsd rename to smart-flow-example/src/main/resources/flow-example6.xsd index 7ca81d7..81ae4bd 100644 --- a/smart-flow-core/src/test/resources/flow-example6.xsd +++ b/smart-flow-example/src/main/resources/flow-example6.xsd @@ -2,35 +2,35 @@ + http://org.smartboot/smart-flow-1.0.1.xsd"> - - + + - - + + - + - - + + - - + + - + - + - - - - + + + + diff --git a/smart-flow-core/src/test/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd similarity index 30% rename from smart-flow-core/src/test/resources/flow-example7.xsd rename to smart-flow-example/src/main/resources/flow-example7.xsd index 24d3345..d5dc653 100644 --- a/smart-flow-core/src/test/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -2,38 +2,38 @@ + http://org.smartboot/smart-flow-1.0.1.xsd" useCache="false"> - - - + + + - - + + - + - - + + - - + + - + - + - + - - + + - - + + diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java similarity index 97% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index e705f52..adf41fb 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -1,8 +1,12 @@ -package org.smartboot.flow.core; +package org.smartboot.flow.example; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.Condition; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java similarity index 75% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java index 54e5afd..ac5ee41 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java @@ -1,27 +1,11 @@ -package org.smartboot.flow.core.async; +package org.smartboot.flow.example.async; import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.AsyncStep1; -import org.smartboot.flow.core.AsyncStep2; -import org.smartboot.flow.core.AsyncStep3; -import org.smartboot.flow.core.BaseTest; -import org.smartboot.flow.core.ChooseCondition; -import org.smartboot.flow.core.DefaultStep; -import org.smartboot.flow.core.ElseStep; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.ErrorStep; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.IfCondition; -import org.smartboot.flow.core.IfCondition2; -import org.smartboot.flow.core.IfCondition3; -import org.smartboot.flow.core.IntegerStep; -import org.smartboot.flow.core.NullStep; -import org.smartboot.flow.core.Step1; -import org.smartboot.flow.core.Step2; -import org.smartboot.flow.core.Step3; -import org.smartboot.flow.core.Step4; -import org.smartboot.flow.core.Step5; -import org.smartboot.flow.core.Step6; +import org.smartboot.flow.example.*; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; @@ -37,7 +21,9 @@ import java.util.concurrent.Executors; * @date 2022-11-14 22:34:14 * @since 1.0.0 */ -public class AsyncTest extends BaseTest { +public class AsyncTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AsyncTest.class); @Test public void testAsync() { diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java similarity index 81% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java index d16e59f..36ceab7 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java @@ -1,15 +1,12 @@ -package org.smartboot.flow.core.attributes; +package org.smartboot.flow.example.attributes; import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.BaseTest; -import org.smartboot.flow.core.ChooseCondition; -import org.smartboot.flow.core.DefaultStep; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.IfCondition; -import org.smartboot.flow.core.IntegerStep; import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.Step5; +import org.smartboot.flow.example.*; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; @@ -21,7 +18,10 @@ import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; * @date 2022/11/18 22:23 * @since 1.0.0 */ -public class AttributeTest extends BaseTest { +public class AttributeTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); + @Test public void testEnabled() { diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java similarity index 69% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java index f7677c2..b668b0b 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java @@ -1,21 +1,24 @@ -package org.smartboot.flow.core.builder; +package org.smartboot.flow.example.builder; import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.BaseTest; -import org.smartboot.flow.core.ChooseCondition; -import org.smartboot.flow.core.DefaultStep; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.IfCondition; -import org.smartboot.flow.core.IntegerStep; import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.builder.EngineBuilder; +import org.smartboot.flow.core.builder.PipelineBuilder; import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.example.*; +import org.smartboot.flow.example.attributes.AttributeTest; /** * @author yamikaze * @date 2022/11/13 */ -public class IfComponentBuilderTest extends BaseTest{ +public class IfComponentBuilderTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); @Test public void testBuild() { diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java similarity index 80% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java index b7f40c4..997b2b5 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java @@ -1,23 +1,18 @@ -package org.smartboot.flow.core.manager; +package org.smartboot.flow.example.manager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.AsyncStep1; -import org.smartboot.flow.core.AsyncStep2; -import org.smartboot.flow.core.AsyncStep3; -import org.smartboot.flow.core.BaseTest; -import org.smartboot.flow.core.ChooseCondition; -import org.smartboot.flow.core.DefaultStep; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.IfCondition; -import org.smartboot.flow.core.IntegerStep; import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.Step1; -import org.smartboot.flow.core.Step2; -import org.smartboot.flow.core.Step3; -import org.smartboot.flow.core.Step5; -import org.smartboot.flow.core.Step6; +import org.smartboot.flow.core.manager.ComponentModel; +import org.smartboot.flow.core.manager.DefaultEngineManager; +import org.smartboot.flow.core.manager.EngineManager; +import org.smartboot.flow.core.manager.EngineModel; +import org.smartboot.flow.example.*; +import org.smartboot.flow.example.attributes.AttributeTest; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; @@ -31,12 +26,13 @@ import java.util.Map; * @date 2022/11/18 22:23 * @since 1.0.0 */ -public class ManagerTest extends BaseTest { +public class ManagerTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); @BeforeEach public void setUp() { DefaultEngineManager.getDefaultManager().detachAll(); - LOGGER.info("detachAll executed"); } @Test diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java similarity index 91% rename from smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java rename to smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 725bc13..14ca9ae 100644 --- a/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -1,11 +1,14 @@ -package org.smartboot.flow.core.parser; +package org.smartboot.flow.example.parser; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.BaseTest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.parser.DefaultParser; +import org.smartboot.flow.example.EngineTest; import org.smartboot.flow.core.manager.DefaultEngineManager; import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; @@ -16,7 +19,10 @@ import java.io.InputStream; * @date 2022-11-15 23:42:32 * @since 1.0.0 */ -public class DefaultParserTest extends BaseTest { +public class DefaultParserTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); + @BeforeEach public void setUp() { diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 39dea51..970e954 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.1 + 1.0.2 4.0.0 @@ -20,7 +20,7 @@ org.smartboot smart-flow-core - 1.0.1 + 1.0.2 diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml index 4fb8869..806b0d4 100644 --- a/smart-flow-spring-extension/pom.xml +++ b/smart-flow-spring-extension/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.1 + 1.0.2 4.0.0 @@ -21,7 +21,7 @@ org.smartboot smart-flow-core - 1.0.1 + 1.0.2 -- Gitee From 610c9830d23dd9becd889528f8cba3fa04aa5fd9 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Mon, 28 Nov 2022 18:36:03 +0800 Subject: [PATCH 02/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/parser/BuilderDefinitionVisitor.java | 3 +-- .../core/parser/DefaultObjectCreator.java | 16 +++++++++++--- .../flow/core/parser/DefaultParser.java | 6 +++++- .../flow/core/parser/ObjectCreator.java | 2 +- .../flow/core/parser/ParserContext.java | 21 +++++++++---------- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index c8521b6..a358b4a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -129,8 +129,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { private Object newInstance(String type) { try { - Class clazz = Class.forName(type); - return objectCreator.create(clazz, useCache); + return objectCreator.create(type, useCache); } catch (Exception e) { throw new IllegalStateException(type, e); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java index 67df7a5..84d7fe4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java @@ -10,14 +10,24 @@ import java.util.concurrent.ConcurrentHashMap; * @date 2022/11/19 14:29 * @since 1.0.0 */ +@SuppressWarnings("unchecked") public class DefaultObjectCreator implements ObjectCreator { private final Map, Object> cachedObjects = new ConcurrentHashMap<>(); + private static Class check(String type) { + try { + return (Class) Class.forName(type); + } catch (Exception e) { + return null; + } + } + @Override - @SuppressWarnings("unchecked") - public T create(Class type, boolean useCache) { - AssertUtil.notNull(type, "type must not be null!"); + public T create(String typename, boolean useCache) { + AssertUtil.notBlank(typename, "type must not be blank!"); + Class type = check(typename); + AssertUtil.notNull(type, "typename " + typename + " is not class"); T created = null; if (useCache) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java index 1af113a..f606b4c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java @@ -55,7 +55,7 @@ public class DefaultParser implements Parser { for (Element sub : elements) { String subName = ElementUtils.getName(sub); - AssertUtil.isTrue(ALLOWED.contains(subName), "element " + subName + " not allowed in engines"); + AssertUtil.isTrue(isAllowed(subName), "element " + subName + " not allowed in engines"); ElementParser parser = context.getParser(subName); AssertUtil.notNull(parser, "Could not find parser for element " + subName); parser.parseElement(sub, context); @@ -95,6 +95,10 @@ public class DefaultParser implements Parser { this.parse(fstream, streams); } + protected boolean isAllowed(String name) { + return ALLOWED.contains(name); + } + protected ObjectCreator getObjectCreator() { return new DefaultObjectCreator(); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java index 28c0550..a2a837b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java @@ -14,5 +14,5 @@ public interface ObjectCreator { * @param useCache useCache * @return instance. */ - T create(Class type, boolean useCache); + T create(String type, boolean useCache); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java index a6659ec..4ba8b5c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java @@ -17,16 +17,6 @@ import java.util.concurrent.ConcurrentHashMap; */ public class ParserContext { - /** - * ElementParser registry - */ - private final ElementParserRegistry parserRegistry = ElementParserRegistry.getInstance(); - - /* Registered Element definitions */ - private final Map registered = new ConcurrentHashMap<>(); - private final Map generatedIdentifiers = new ConcurrentHashMap<>(); - private IdentifierManager identifierManager = new DefaultIdentifierManager(); - /** * Allowed sub elements. */ @@ -38,6 +28,16 @@ public class ParserContext { ALLOWED.add(ParseConstants.COMPONENT); } + /** + * ElementParser registry + */ + private final ElementParserRegistry parserRegistry = ElementParserRegistry.getInstance(); + + /* Registered Element definitions */ + private final Map registered = new ConcurrentHashMap<>(); + private final Map generatedIdentifiers = new ConcurrentHashMap<>(); + private IdentifierManager identifierManager = new DefaultIdentifierManager(); + public IdentifierManager getIdentifierManager() { return identifierManager; } @@ -93,5 +93,4 @@ public class ParserContext { public boolean isAllowed(String name) { return ALLOWED.contains(name); } - } -- Gitee From c5e3facdfedfaf24bda913b5f103e6c700243133 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Mon, 28 Nov 2022 19:31:23 +0800 Subject: [PATCH 03/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E4=BC=98=E5=8C=96=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/parser/AbstractElementParser.java | 2 +- .../core/parser/BuilderDefinitionVisitor.java | 30 ++++++++++++++-- .../flow/core/parser/ChooseElementParser.java | 11 ++---- .../core/parser/ComponentElementParser.java | 12 ++----- .../flow/core/parser/IfElementParser.java | 12 ++----- .../flow/core/parser/ParseConstants.java | 3 +- .../parser/definition/ElementDefinition.java | 30 ++++++---------- .../flow/core/util/AuxiliaryUtils.java | 9 +++++ .../src/main/resources/smart-flow-1.0.1.xsd | 6 ++-- smart-flow-example/pom.xml | 2 +- .../src/main/resources/bean.xml | 36 +++++++++---------- .../src/main/resources/flow-example3.xsd | 4 +-- .../src/main/resources/flow-example4.xsd | 8 ++--- .../src/main/resources/flow-example5.xsd | 18 +++++----- .../src/main/resources/flow-example6.xsd | 24 ++++++------- .../src/main/resources/flow-example7.xsd | 28 +++++++-------- .../extension/BeanDefinitionVisitor.java | 19 +++++----- .../main/resources/META-INF/spring.schemas | 2 +- 18 files changed, 130 insertions(+), 126 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java index 07e22ba..cda8654 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java @@ -29,7 +29,7 @@ public abstract class AbstractElementParser implements ElementParser { // name String name = element.getAttribute(ParseConstants.NAME); // nested pipeline maybe no name. - if (name.trim().length() == 0 || Objects.equals(name, element.getAttribute(ParseConstants.REF))) { + if (name.trim().length() == 0 || Objects.equals(name, element.getAttribute(ParseConstants.EXECUTE))) { name = context.getIdentifier(element); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index a358b4a..ab373e8 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -17,6 +17,8 @@ import org.smartboot.flow.core.parser.definition.EngineDefinition; import org.smartboot.flow.core.parser.definition.IfElementDefinition; import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition; import org.smartboot.flow.core.parser.definition.PipelineDefinition; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.core.util.AuxiliaryUtils; import java.util.ArrayList; import java.util.List; @@ -123,7 +125,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { // resolve value type. builder.apply(p.getAttribute(), p.getValue()); }); - Component component = builder.newAdapter((Executable) newInstance(ed.getType())); + Component component = builder.newAdapter((Executable) newInstance(ed.getExecute())); namedComponents.put(ed.getIdentifier(), component); } @@ -137,7 +139,16 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { @Override public void visit(IfElementDefinition ed) { - IfComponentBuilder ifComponentBuilder = new IfComponentBuilder<>((Condition) newInstance(ed.getTest())); + String test = ed.getTest(); + Condition condition = null; + if (AuxiliaryUtils.isType(test)) { + condition = (Condition) newInstance(test); + } else if (ed.getContext().getRegistered(test) != null) { + condition = getInternalObject(test, ed.getContext()); + } + + AssertUtil.notNull(condition, "can't find condition for if-element, test = " + test); + IfComponentBuilder ifComponentBuilder = new IfComponentBuilder<>(condition); ed.getAttributes().forEach(p -> { // resolve value type. ifComponentBuilder.apply(p.getAttribute(), p.getValue()); @@ -157,9 +168,22 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { this.namedComponents.put(ed.getIdentifier(), build); } + public T getInternalObject(String test, ParserContext context) { + return null; + } + @Override public void visit(ChooseDefinition ed) { - ChooseBuilder chooseBuilder = new ChooseBuilder<>((Condition) newInstance(ed.getTest())); + String test = ed.getTest(); + Condition condition = null; + if (AuxiliaryUtils.isType(test)) { + condition = (Condition) newInstance(test); + } else if (ed.getContext().getRegistered(test) != null) { + condition = getInternalObject(test, ed.getContext()); + } + + AssertUtil.notNull(condition, "can't find condition for choose-element, test = " + test); + ChooseBuilder chooseBuilder = new ChooseBuilder<>(condition); ed.getAttributes().forEach(p -> { // resolve value type. chooseBuilder.apply(p.getAttribute(), p.getValue()); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java index 57f0888..edff646 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java @@ -30,10 +30,7 @@ public class ChooseElementParser extends AbstractElementParser{ @Override public void doParse(Element element, ParserContext context) { String test = element.getAttribute(ParseConstants.TEST); - String ref = element.getAttribute(ParseConstants.REF); - if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(test)) { - throw new IllegalArgumentException("attribute [ref] [type] cannot be null"); - } + AssertUtil.notBlank(test, "attribute [test] cannot be null"); ChooseDefinition chooseDefinition = new ChooseDefinition(); ElementDefinition.build(chooseDefinition, element); @@ -42,7 +39,6 @@ public class ChooseElementParser extends AbstractElementParser{ chooseDefinition.setName(ElementUtils.resolveName(element, "choose")); chooseDefinition.setIdentifier(identifier); chooseDefinition.setTest(test); - chooseDefinition.setRef(ref); List subElements = ElementUtils.subElements(element); List caseList = new ArrayList<>(); @@ -67,9 +63,8 @@ public class ChooseElementParser extends AbstractElementParser{ chooseDefinition.setChooseDefaultRef(currentDef); } - String type = subElement.getAttribute(ParseConstants.TYPE); - ref = subElement.getAttribute(ParseConstants.REF); - if (AuxiliaryUtils.isNotBlank(type) || AuxiliaryUtils.isNotBlank(ref)) { + String type = subElement.getAttribute(ParseConstants.EXECUTE); + if (AuxiliaryUtils.isNotBlank(type)) { continue; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java index 3795839..07a4873 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java @@ -2,6 +2,7 @@ package org.smartboot.flow.core.parser; import org.smartboot.flow.core.parser.definition.ElementDefinition; import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition; +import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.w3c.dom.Element; @@ -14,10 +15,6 @@ import org.w3c.dom.Element; */ public class ComponentElementParser extends AbstractElementParser { - /* - - */ - @Override public void doParse(Element element, ParserContext context) { ElementDefinition elementDefinition = new ElementDefinition(); @@ -37,11 +34,8 @@ public class ComponentElementParser extends AbstractElementParser { return; } - String ref = elementDefinition.getRef(); - String type = elementDefinition.getType(); - if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(type)) { - throw new IllegalArgumentException("attribute [ref] [type] cannot be null"); - } + String type = elementDefinition.getExecute(); + AssertUtil.notBlank(elementDefinition.getExecute(), "attribute [execute] cannot be null"); context.register(elementDefinition); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java index 2fa9b95..6e5b216 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java @@ -32,19 +32,14 @@ public class IfElementParser extends AbstractElementParser { @Override public void doParse(Element element, ParserContext context) { String test = element.getAttribute(ParseConstants.TEST); - String ref = element.getAttribute(ParseConstants.REF); - if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(test)) { - throw new IllegalArgumentException("attribute [ref] [type] cannot be null"); - } + AssertUtil.notBlank(test, "attribute [test] cannot be null"); IfElementDefinition ifDef = new IfElementDefinition(); ElementDefinition.build(ifDef, element); ifDef.setName(ElementUtils.resolveName(element, "if")); ifDef.setIdentifier(super.getIdentifier(element, context)); - ifDef.setTest(element.getAttribute(ParseConstants.TEST)); - ifDef.setRef(ref); List elementList = ElementUtils.subElements(element); AssertUtil.isTrue(elementList.size() != 0, "[if] childNodes can't be null"); @@ -70,9 +65,8 @@ public class IfElementParser extends AbstractElementParser { thenDef = thenDefinition; } - String type = subElement.getAttribute(ParseConstants.TYPE); - ref = subElement.getAttribute(ParseConstants.REF); - if (AuxiliaryUtils.isNotBlank(type) || AuxiliaryUtils.isNotBlank(ref)) { + String type = subElement.getAttribute(ParseConstants.EXECUTE); + if (AuxiliaryUtils.isNotBlank(type)) { continue; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java index cbb12f5..7a0c9fc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java @@ -22,8 +22,7 @@ public interface ParseConstants { * Attributes; */ String NAME = "name"; - String TYPE = "type"; - String REF = "ref"; + String EXECUTE = "execute"; String TEST = "test"; String THEN = "then"; String WHEN = "when"; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java index a889fe8..fe0dbca 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java @@ -21,8 +21,7 @@ import java.util.List; public class ElementDefinition extends Uniqueness implements Validator { protected String name; - private String type; - private String ref; + private String execute; private String test; private String when; protected ParserContext context; @@ -52,36 +51,27 @@ public class ElementDefinition extends Uniqueness implements Validator { } public static void build(ElementDefinition definition, Element element) { - definition.setRef(element.getAttribute(ParseConstants.REF)); - definition.setType(element.getAttribute(ParseConstants.TYPE)); definition.setName(element.getAttribute(ParseConstants.NAME)); + definition.setExecute(element.getAttribute(ParseConstants.EXECUTE)); definition.setWhen(element.getAttribute(ParseConstants.WHEN)); // Extra well-known attributes. definition.getAttributes().addAll(ElementUtils.extraAttributes(element)); } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; + public String getExecute() { + return execute; } - public String getType() { - return type; + public void setExecute(String execute) { + this.execute = execute; } - public void setType(String type) { - this.type = type; - } - - public String getRef() { - return ref; + public String getName() { + return name; } - public void setRef(String ref) { - this.ref = ref; + public void setName(String name) { + this.name = name; } public List getAttributes() { 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 c6d6694..a25db16 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 @@ -22,4 +22,13 @@ public final class AuxiliaryUtils { public static boolean isNotBlank(String value) { return !isBlank(value); } + + public static boolean isType(String typename) { + try { + Class.forName(typename); + return true; + } catch (Exception e) { + return false; + } + } } diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 08a15cc..8485973 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -36,7 +36,7 @@ - + 设置组件的前置依赖组件名称,当前置组件为异步组件时,会等待异步组件执行完毕后开始执行当前组件 @@ -150,7 +150,7 @@ - + @@ -211,7 +211,7 @@ - + diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml index e4b6f30..156fd6c 100644 --- a/smart-flow-example/pom.xml +++ b/smart-flow-example/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.1 + 1.0.2 4.0.0 diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 0b07af6..1f6038b 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -29,38 +29,38 @@ - - + + - - + + - - + + - + - - + + - - + + - + - + - + - - + + - - + + diff --git a/smart-flow-example/src/main/resources/flow-example3.xsd b/smart-flow-example/src/main/resources/flow-example3.xsd index c9c057c..1ddc418 100644 --- a/smart-flow-example/src/main/resources/flow-example3.xsd +++ b/smart-flow-example/src/main/resources/flow-example3.xsd @@ -8,8 +8,8 @@ - - + + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example4.xsd b/smart-flow-example/src/main/resources/flow-example4.xsd index 00c2731..5501fb7 100644 --- a/smart-flow-example/src/main/resources/flow-example4.xsd +++ b/smart-flow-example/src/main/resources/flow-example4.xsd @@ -8,11 +8,11 @@ - - + + - - + + diff --git a/smart-flow-example/src/main/resources/flow-example5.xsd b/smart-flow-example/src/main/resources/flow-example5.xsd index f529a8a..ae35fcd 100644 --- a/smart-flow-example/src/main/resources/flow-example5.xsd +++ b/smart-flow-example/src/main/resources/flow-example5.xsd @@ -8,20 +8,20 @@ - - + + - - + + - - + + - - - + + + diff --git a/smart-flow-example/src/main/resources/flow-example6.xsd b/smart-flow-example/src/main/resources/flow-example6.xsd index 81ae4bd..b647239 100644 --- a/smart-flow-example/src/main/resources/flow-example6.xsd +++ b/smart-flow-example/src/main/resources/flow-example6.xsd @@ -8,29 +8,29 @@ - - + + - - + + - - + + - + - + - + - - - + + + diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd index d5dc653..ecb79d1 100644 --- a/smart-flow-example/src/main/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -7,33 +7,33 @@ - - - + + + - - + + - - + + - + - + - + - - + + - - + + diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index e85745d..f475631 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -108,13 +108,13 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); - if (AuxiliaryUtils.isNotBlank(ed.getType()) && isType(ed.getType())) { + if (isType(ed.getExecute())) { RootBeanDefinition conditionDef = new RootBeanDefinition(); - conditionDef.setBeanClassName(ed.getType()); + conditionDef.setBeanClassName(ed.getExecute()); definition.getPropertyValues().add("executable", conditionDef); } else { - AssertUtil.notBlank(ed.getRef(), "component element ref must not be null!"); - definition.getPropertyValues().add("executable", new RuntimeBeanReference(ed.getRef())); + AssertUtil.notBlank(ed.getExecute(), "component element ref must not be null!"); + definition.getPropertyValues().add("executable", new RuntimeBeanReference(ed.getExecute())); } appendAttributes(ed, definition); @@ -138,13 +138,13 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); - if (AuxiliaryUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) { + if (isType(ed.getTest())) { RootBeanDefinition conditionDef = new RootBeanDefinition(); conditionDef.setBeanClassName(ed.getTest()); definition.getPropertyValues().add("condition", conditionDef); } else { - AssertUtil.notBlank(ed.getRef(), "if element ref must not be null!"); - definition.getPropertyValues().add("condition", new RuntimeBeanReference(ed.getRef())); + AssertUtil.notBlank(ed.getTest(), "if element ref must not be null!"); + definition.getPropertyValues().add("condition", new RuntimeBeanReference(ed.getTest())); } ed.getIfThenRef().visit(this); @@ -172,13 +172,12 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.getPropertyValues().addPropertyValue(name); definition.getPropertyValues().add("allBranchWasString", true); - if (AuxiliaryUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) { + if (isType(ed.getTest())) { RootBeanDefinition conditionDef = new RootBeanDefinition(); conditionDef.setBeanClassName(ed.getTest()); definition.getPropertyValues().add("condition", conditionDef); } else { - AssertUtil.notBlank(ed.getRef(), "choose element ref must not be null!"); - definition.getPropertyValues().add("condition", new RuntimeBeanReference(ed.getRef())); + definition.getPropertyValues().add("condition", new RuntimeBeanReference(ed.getTest())); } ManagedMap managedMap = new ManagedMap<>(); diff --git a/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas b/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas index 68ca2f4..4fcc304 100644 --- a/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas +++ b/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas @@ -1 +1 @@ -http\://org.smartboot/smart-flow-1.0.0.xsd=smart-flow-1.0.0.xsd \ No newline at end of file +http\://org.smartboot/smart-flow-1.0.1.xsd=smart-flow-1.0.1.xsd \ No newline at end of file -- Gitee From f900f334f00f9c6014eeb262e8d6a4f58a139add Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Mon, 28 Nov 2022 19:47:09 +0800 Subject: [PATCH 04/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/ScriptCondition.java | 29 +++++++++++++++++++ .../src/main/resources/smart-flow-1.0.1.xsd | 20 +++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java new file mode 100644 index 0000000..eef8118 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java @@ -0,0 +1,29 @@ +package org.smartboot.flow.core; + +/** + * @author qinluo + * @date 2022/11/28 19:41 + * @since 1.0.0 + */ +public abstract class ScriptCondition extends NamedCondition { + + /** + * 执行脚本 + */ + protected String script; + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } + + /** + * 获取脚本条件的类型 + * + * @return type string + */ + public abstract String getType(); +} diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 8485973..1f5a864 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -72,6 +72,22 @@ + + + + + + + + + + + + + + + + @@ -81,9 +97,7 @@ - - - + -- Gitee From 3eefe72f4d670e5b1668a68542918b26bc6a56a6 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 29 Nov 2022 20:09:04 +0800 Subject: [PATCH 05/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=E5=9B=9E=E8=B0=83=20=20=20=20=20=20-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Escript=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/DegradeCallback.java | 18 +++++ .../flow/core/ScriptElementParser.java | 37 +++++++++ .../AttributeHolder.java | 2 +- .../attribute/AttributeValueResolver.java | 60 +++++++++++++++ .../{component => attribute}/Attributes.java | 76 +++++++------------ .../builder/AbstractComponentBuilder.java | 12 ++- .../flow/core/builder/ChooseBuilder.java | 2 +- .../flow/core/builder/ExecutableBuilder.java | 2 +- .../flow/core/builder/IfComponentBuilder.java | 2 +- .../flow/core/component/Component.java | 11 +++ ...ecuteException.java => FlowException.java} | 14 ++-- .../core/executable/ExecutableAdapter.java | 14 ++++ .../flow/core/manager/ComponentModel.java | 11 ++- .../core/manager/DefaultEngineManager.java | 2 +- .../flow/core/manager/EngineManager.java | 2 +- .../flow/core/manager/EngineModel.java | 2 +- .../manager/RegisteredComponentVisitor.java | 2 +- .../core/parser/BuilderDefinitionVisitor.java | 19 ++++- .../core/parser/ComponentElementParser.java | 2 - .../flow/core/parser/DefaultParser.java | 1 + .../core/parser/ElementParserRegistry.java | 3 + .../flow/core/parser/ElementUtils.java | 4 +- .../flow/core/parser/ParseConstants.java | 1 + .../parser/definition/ElementDefinition.java | 2 +- .../parser/definition/ScriptDefinition.java | 65 ++++++++++++++++ .../core/{ => script}/ScriptCondition.java | 9 ++- .../flow/core/script/ScriptConstants.java | 13 ++++ .../flow/core/script/ScriptDetector.java | 60 +++++++++++++++ .../smartboot/flow/core/util/AssertUtil.java | 18 +++-- .../flow/core/util/AuxiliaryUtils.java | 8 ++ .../core/view/plantuml/PlantumlComponent.java | 4 +- .../plantuml/PlantumlComponentVisitor.java | 2 +- .../flow/core/visitor/ComponentVisitor.java | 2 +- .../src/main/resources/smart-flow-1.0.1.xsd | 71 ++++++++++++++--- .../flow/example/AlwaysFalseCondition.java | 24 ++++++ .../flow/example/AlwaysTrueCondition.java | 25 ++++++ .../flow/example/ExampleCallback.java | 24 ++++++ .../flow/example/SelfCallbackComponent.java | 33 ++++++++ .../main/resources/META-INF/smart-flow-script | 1 + .../src/main/resources/bean.xml | 14 +++- .../src/main/resources/degrade-callback.xsd | 40 ++++++++++ .../src/main/resources/flow-example3.xsd | 3 + .../src/main/resources/flow-example7.xsd | 2 +- .../src/main/resources/script-use.xsd | 51 +++++++++++++ .../smartboot/flow/example/EngineTest.java | 2 +- .../flow/example/async/AsyncTest.java | 2 +- .../example/attributes/AttributeTest.java | 2 +- .../builder/IfComponentBuilderTest.java | 2 +- .../example/degrade/DegradeCallbackTest.java | 38 ++++++++++ .../flow/example/manager/ManagerTest.java | 4 +- .../flow/example/script/ScriptTest.java | 38 ++++++++++ .../flow/manager/change/HttpManager.java | 4 +- .../extension/BeanDefinitionVisitor.java | 57 +++++++++++++- .../extension/SpringNamespaceHandler.java | 1 + 54 files changed, 808 insertions(+), 112 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/DegradeCallback.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java rename smart-flow-core/src/main/java/org/smartboot/flow/core/{component => attribute}/AttributeHolder.java (92%) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java rename smart-flow-core/src/main/java/org/smartboot/flow/core/{component => attribute}/Attributes.java (67%) rename smart-flow-core/src/main/java/org/smartboot/flow/core/exception/{PipelineExecuteException.java => FlowException.java} (41%) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java rename smart-flow-core/src/main/java/org/smartboot/flow/core/{ => script}/ScriptCondition.java (72%) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java create mode 100644 smart-flow-example/src/main/resources/META-INF/smart-flow-script create mode 100644 smart-flow-example/src/main/resources/degrade-callback.xsd create mode 100644 smart-flow-example/src/main/resources/script-use.xsd create mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java create mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/DegradeCallback.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/DegradeCallback.java new file mode 100644 index 0000000..cbc0aac --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/DegradeCallback.java @@ -0,0 +1,18 @@ +package org.smartboot.flow.core; + +/** + * @author qinluo + * @date 2022-11-28 20:10:46 + * @since 1.0.0 + */ +public interface DegradeCallback extends Describable { + + default void doWithDegrade(EngineContext context, Throwable e) { + + } + + @Override + default String describe() { + return this.getClass().getName(); + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java new file mode 100644 index 0000000..2a85fea --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java @@ -0,0 +1,37 @@ +package org.smartboot.flow.core; + +import org.smartboot.flow.core.parser.AbstractElementParser; +import org.smartboot.flow.core.parser.ParseConstants; +import org.smartboot.flow.core.parser.ParserContext; +import org.smartboot.flow.core.parser.definition.ScriptDefinition; +import org.smartboot.flow.core.util.AssertUtil; +import org.w3c.dom.Element; + +/** + * Parse script element. + * + * @author qinluo + * @date 2022-11-15 13:00:59 + * @since 1.0.0 + */ +public class ScriptElementParser extends AbstractElementParser { + + @Override + public void doParse(Element element, ParserContext context) { + ScriptDefinition elementDefinition = new ScriptDefinition(); + String name = element.getAttribute(ParseConstants.NAME); + AssertUtil.notBlank(name, "script name must not be blank"); + String type = element.getAttribute("type"); + + elementDefinition.setName(name); + elementDefinition.setIdentifier(name); + elementDefinition.setType(type); + elementDefinition.setScript(element.getTextContent()); + context.register(elementDefinition); + } + + @Override + public String getElementName() { + return ParseConstants.SCRIPT; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java similarity index 92% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java index f40eada..1cac30f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.core.component; +package org.smartboot.flow.core.attribute; /** * @author qinluo diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java new file mode 100644 index 0000000..faa8313 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java @@ -0,0 +1,60 @@ +package org.smartboot.flow.core.attribute; + +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.parser.DefaultObjectCreator; +import org.smartboot.flow.core.parser.ObjectCreator; + +import java.util.Arrays; +import java.util.List; + +/** + * @author qinluo + * @date 2022-11-28 20:41:17 + * @since 1.0.0 + */ +public class AttributeValueResolver { + + private ObjectCreator objectCreator = new DefaultObjectCreator(); + + public void setObjectCreator(ObjectCreator objectCreator) { + this.objectCreator = objectCreator; + } + + public Object resolve(Attributes attribute, Object value) { + if (value == null) { + return null; + } + + if (attribute.accept(value)) { + return value; + } + + Class accepted = attribute.accept; + // Must as string + String strValue = String.valueOf(value); + + if (accepted == Boolean.class || accepted == boolean.class) { + return Boolean.parseBoolean(strValue); + } + + if (accepted == Long.class || accepted == long.class) { + return Long.parseLong(strValue); + } + + if (accepted == Integer.class || accepted == int.class) { + return Integer.parseInt(strValue); + } + + if (accepted == List.class) { + return Arrays.asList(strValue.split(",")); + } + + try { + return objectCreator.create(strValue, true); + } catch (Exception ignored) { + // Maybe not a class. + } + + throw new FlowException("Can't not resolve attribute [" + attribute.getName() + "] value with " + value); + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java similarity index 67% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java index 5663440..2227a06 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java @@ -1,9 +1,10 @@ -package org.smartboot.flow.core.component; +package org.smartboot.flow.core.attribute; +import org.smartboot.flow.core.DegradeCallback; +import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.util.AssertUtil; -import java.util.Arrays; import java.util.List; @@ -12,6 +13,7 @@ import java.util.List; * @date 2022-11-12 18:46:30 * @since 1.0.0 */ +@SuppressWarnings("unchecked") public enum Attributes { NAME("name", String.class) { @@ -26,9 +28,6 @@ public enum Attributes { @Override public void apply(Component component, Object value) { super.apply(component, value); - if (value instanceof String) { - value = Boolean.parseBoolean((String) value); - } component.setRollback((Boolean) value); } }, @@ -37,9 +36,6 @@ public enum Attributes { @Override public void apply(Component component, Object value) { super.apply(component, value); - if (value instanceof String) { - value = Boolean.parseBoolean((String) value); - } component.setDegradable((Boolean) value); } }, @@ -48,11 +44,6 @@ public enum Attributes { @Override public void apply(Component component, Object value) { super.apply(component, value); - - if (value instanceof String) { - value = Boolean.parseBoolean((String) value); - } - component.setAsync((Boolean) value); } }, @@ -61,11 +52,6 @@ public enum Attributes { @Override public void apply(Component component, Object value) { super.apply(component, value); - - if (value instanceof String) { - value = Long.parseLong((String) value); - } - component.setTimeout(((Number) value).longValue()); } @@ -75,39 +61,17 @@ public enum Attributes { } }, - DEPENDS_ON("dependsOn", Void.class) { + DEPENDS_ON("dependsOn", List.class) { @Override public void apply(Component component, Object value) { super.apply(component, value); - if (value instanceof String) { - String values = (String) value; - component.setDependsOn(Arrays.asList(values.split(",+"))); - } else if (value instanceof List) { + if (value instanceof List) { //noinspection unchecked component.setDependsOn((List)value); } else { AssertUtil.shouldNotReachHere(); } } - - @Override - public boolean accept(Object value) { - if (value instanceof String) { - return true; - } else if (value instanceof List) { - List values = (List) value; - for (Object item : values) { - if (!(item instanceof String)) { - return false; - } - } - - return true; - } - - AssertUtil.shouldNotReachHere(); - return true; - } }, /** @@ -128,9 +92,24 @@ public enum Attributes { } }, + /** + * 降级回调 + * + * @since 1.0.2 + */ + DEGRADE_CALLBACK("degrade-callback", DegradeCallback.class) { + @Override + public void apply(Component component, Object value) { + super.apply(component, value); + component.setDegradeCallback((DegradeCallback) value); + } + }, + ; private final String name; + private final boolean allowedNull; + /** * Attribute accepted type. */ @@ -139,6 +118,11 @@ public enum Attributes { Attributes(String name, Class accept) { this.name = name; this.accept = accept; + this.allowedNull = this.accept.isPrimitive(); + } + + public boolean allowedNull() { + return allowedNull; } public String getName() { @@ -146,13 +130,7 @@ public enum Attributes { } public boolean accept(Object value) { - boolean directInstance = accept.isInstance(value); - if (directInstance) { - return true; - } - - // String类型暂时返回true - return value instanceof String; + return accept.isInstance(value); } public void apply(Component component, Object value) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java index adb528b..6ccc39d 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java @@ -1,7 +1,8 @@ package org.smartboot.flow.core.builder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeValueResolver; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.util.AssertUtil; @@ -15,6 +16,8 @@ import java.util.Map; */ public abstract class AbstractComponentBuilder { + private final AttributeValueResolver valueResolver = new AttributeValueResolver(); + /** * Component attribute attributes. */ @@ -24,8 +27,11 @@ public abstract class AbstractComponentBuilder { public AbstractComponentBuilder apply(Attributes attributes, Object value) { AssertUtil.notNull(attributes, "Unknown attribute"); AssertUtil.notNull(value, "null"); - AssertUtil.isTrue(attributes.accept(value), "Un-matched type"); - this.settings.put(attributes, value); + + Object resolved = valueResolver.resolve(attributes, value); + + AssertUtil.isTrue(attributes.accept(resolved), "Un-matched type"); + this.settings.put(attributes, resolved); return this; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java index 7844778..8c52802 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.builder; import org.smartboot.flow.core.Condition; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.ChooseComponent; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.executable.Executable; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java index 506f8fe..79fd24d 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java @@ -1,7 +1,7 @@ package org.smartboot.flow.core.builder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.executable.Executable; import org.smartboot.flow.core.executable.ExecutableAdapter; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java index 8a2fad8..b5907f5 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.builder; import org.smartboot.flow.core.Condition; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.IfComponent; import org.smartboot.flow.core.executable.Executable; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java index 25f2415..4df34d2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java @@ -1,11 +1,13 @@ package org.smartboot.flow.core.component; +import org.smartboot.flow.core.DegradeCallback; import org.smartboot.flow.core.Describable; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Measurable; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.Validator; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.visitor.ComponentVisitor; import java.util.ArrayList; @@ -33,9 +35,18 @@ public abstract class Component implements Rollback, Describable, Va private List dependsOn; private String name; private boolean enabled = true; + private DegradeCallback degradeCallback; protected final List attributes = new ArrayList<>(0); + public DegradeCallback getDegradeCallback() { + return degradeCallback; + } + + public void setDegradeCallback(DegradeCallback degradeCallback) { + this.degradeCallback = degradeCallback; + } + public boolean isDegradable() { return degradable; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/PipelineExecuteException.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java similarity index 41% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/exception/PipelineExecuteException.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java index b6da7bc..7654a8c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/PipelineExecuteException.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java @@ -5,24 +5,26 @@ package org.smartboot.flow.core.exception; * @date 2022-11-11 21:10:03 * @since 1.0.0 */ -public class PipelineExecuteException extends RuntimeException { +public class FlowException extends RuntimeException { - public PipelineExecuteException() { + private static final long serialVersionUID = -7613637640003340281L; + + public FlowException() { } - public PipelineExecuteException(String message) { + public FlowException(String message) { super(message); } - public PipelineExecuteException(String message, Throwable cause) { + public FlowException(String message, Throwable cause) { super(message, cause); } - public PipelineExecuteException(Throwable cause) { + public FlowException(Throwable cause) { super(cause); } - public PipelineExecuteException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + public FlowException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java index b5423dc..000b24b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core.executable; +import org.smartboot.flow.core.DegradeCallback; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.component.Component; @@ -33,6 +34,19 @@ public class ExecutableAdapter extends Component implements Rollback< try { executable.execute(context); + } catch (Throwable e) { + // 非降级,直接throw + if (!isDegradable()) { + throw e; + } + + // 触发降级回调 + if (getDegradeCallback() != null) { + getDegradeCallback().doWithDegrade(context, e); + } else if (executable instanceof DegradeCallback) { + ((DegradeCallback) executable).doWithDegrade(context, e); + } + } finally { context.exit(this); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java index 4176901..971bb7b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java @@ -1,9 +1,10 @@ package org.smartboot.flow.core.manager; +import org.smartboot.flow.core.attribute.AttributeValueResolver; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.common.Uniqueness; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.metrics.Metrics; @@ -120,9 +121,13 @@ public class ComponentModel extends Uniqueness { @SuppressWarnings("unchecked") public void changeAttributes(List holders) { Map snapshot = new HashMap<>(this.holders); + AttributeValueResolver valueResolver = new AttributeValueResolver(); try { - holders.forEach(p -> p.getAttribute().apply(component, p.getValue())); + holders.forEach(p -> { + Object resolvedValue = valueResolver.resolve(p.getAttribute(), p.getValue()); + p.getAttribute().apply(component, resolvedValue); + }); addAttributes(holders); } catch (Exception e) { this.holders.clear(); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java index 1af1541..68d1f51 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java @@ -3,7 +3,7 @@ package org.smartboot.flow.core.manager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.util.AssertUtil; import java.util.ArrayList; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineManager.java index 92406ee..40d81b1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineManager.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineManager.java @@ -1,7 +1,7 @@ package org.smartboot.flow.core.manager; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import java.util.Collections; import java.util.List; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineModel.java index cd5ee5a..deebab1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/EngineModel.java @@ -3,7 +3,7 @@ package org.smartboot.flow.core.manager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.common.Uniqueness; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.metrics.Metrics; import java.util.HashMap; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java index 0193f4a..9b415ce 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.manager; import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.common.ComponentType; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.smartboot.flow.core.util.ContactUtils; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index ab373e8..99ad04b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -17,6 +17,8 @@ import org.smartboot.flow.core.parser.definition.EngineDefinition; import org.smartboot.flow.core.parser.definition.IfElementDefinition; import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition; import org.smartboot.flow.core.parser.definition.PipelineDefinition; +import org.smartboot.flow.core.parser.definition.ScriptDefinition; +import org.smartboot.flow.core.script.ScriptCondition; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.util.AuxiliaryUtils; @@ -37,6 +39,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { private final Map> namedPipelines = new ConcurrentHashMap<>(); private final Map> namedEngines = new ConcurrentHashMap<>(); private final Map> callbacks = new ConcurrentHashMap<>(); + private final Map scriptConditions = new ConcurrentHashMap<>(); private final ObjectCreator objectCreator; private final boolean useCache; @@ -47,7 +50,16 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { @Override public void visit(ElementDefinition ed) { - ed.visit(this); + if (ed instanceof ScriptDefinition) { + ScriptDefinition sed = (ScriptDefinition) ed; + ScriptCondition condition = objectCreator.create(sed.getType(), true); + condition.setName(sed.getName()); + condition.setScript(sed.getScript()); + scriptConditions.put(ed.getIdentifier(), condition); + } else { + ed.visit(this); + } + } @Override @@ -169,7 +181,10 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { } public T getInternalObject(String test, ParserContext context) { - return null; + ElementDefinition registered = context.getRegistered(test); + AssertUtil.notNull(registered, "registered condition def[" + test + "] not found"); + this.visit(registered); + return (T)scriptConditions.get(test); } @Override diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java index 07a4873..64b9a0e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ComponentElementParser.java @@ -34,9 +34,7 @@ public class ComponentElementParser extends AbstractElementParser { return; } - String type = elementDefinition.getExecute(); AssertUtil.notBlank(elementDefinition.getExecute(), "attribute [execute] cannot be null"); - context.register(elementDefinition); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java index f606b4c..6408f1b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java @@ -25,6 +25,7 @@ public class DefaultParser implements Parser { static { ALLOWED.add(ParseConstants.ENGINE); ALLOWED.add(ParseConstants.PIPELINE); + ALLOWED.add(ParseConstants.SCRIPT); } private BuilderDefinitionVisitor visitor; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java index 6a682b6..aafeb9a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java @@ -1,5 +1,7 @@ package org.smartboot.flow.core.parser; +import org.smartboot.flow.core.ScriptElementParser; + import java.util.HashMap; import java.util.Map; @@ -19,6 +21,7 @@ public class ElementParserRegistry { this.register("pipeline", new PipelineElementParser()); this.register("choose", new ChooseElementParser()); this.register("engine", new EngineElementParser()); + this.register("script", new ScriptElementParser()); } public static ElementParserRegistry getInstance() { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java index 35143ac..8ee5f57 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java @@ -1,7 +1,7 @@ package org.smartboot.flow.core.parser; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java index 7a0c9fc..b9b434c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java @@ -17,6 +17,7 @@ public interface ParseConstants { String IF = "if"; String CHOOSE = "choose"; String COMPONENT = "component"; + String SCRIPT = "script"; /** * Attributes; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java index fe0dbca..1aa0e4a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ElementDefinition.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.parser.definition; import org.smartboot.flow.core.Validator; import org.smartboot.flow.core.common.Uniqueness; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.executable.ExecutableAdapter; import org.smartboot.flow.core.parser.DefinitionVisitor; import org.smartboot.flow.core.parser.ElementUtils; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java new file mode 100644 index 0000000..bd5b059 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java @@ -0,0 +1,65 @@ +package org.smartboot.flow.core.parser.definition; + +import org.smartboot.flow.core.script.ScriptCondition; +import org.smartboot.flow.core.script.ScriptDetector; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.core.util.AuxiliaryUtils; + +/** + * @author qinluo + * @date 2022-11-15 13:00:20 + * @since 1.0.0 + */ +public class ScriptDefinition extends ElementDefinition { + + private String type; + private String script; + + @Override + public void validate() { + AssertUtil.notBlank(name, "script name must not be blank"); + AssertUtil.notBlank(type, "script type must not be blank"); + AssertUtil.notBlank(script, "script must not be blank"); + + Class javaType; + if (!AuxiliaryUtils.isType(type)) { + javaType = ScriptDetector.get().getJavaType(type); + } else { + javaType = AuxiliaryUtils.beType(type); + } + + AssertUtil.notNull(javaType, "script type must be a javaType"); + AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(javaType), "script type must be a subclass of ScriptCondition"); + AssertUtil.isTrue(ScriptCondition.class != javaType, "script type must be a subclass of ScriptCondition"); + } + + /** + * Return script java type. + * + * @return maybe null in spring container. + */ + public Class getJavaType() { + Class javaType = AuxiliaryUtils.beType(type); + if (javaType == null) { + javaType = ScriptDetector.get().getJavaType(type); + } + + return javaType; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java similarity index 72% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java index eef8118..b2fd5c5 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptCondition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java @@ -1,4 +1,6 @@ -package org.smartboot.flow.core; +package org.smartboot.flow.core.script; + +import org.smartboot.flow.core.NamedCondition; /** * @author qinluo @@ -26,4 +28,9 @@ public abstract class ScriptCondition extends NamedCondition { * @return type string */ public abstract String getType(); + + @Override + public String describe() { + return "script-" + getType(); + } } 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 new file mode 100644 index 0000000..1cf3080 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptConstants.java @@ -0,0 +1,13 @@ +package org.smartboot.flow.core.script; + +/** + * @author qinluo + * @date 2022/11/28 19:41 + * @since 1.0.0 + */ +public interface ScriptConstants { + + String REQ = "request"; + String RESULT = "result"; + String CONTEXT = "context"; +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java new file mode 100644 index 0000000..c577d0c --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java @@ -0,0 +1,60 @@ +package org.smartboot.flow.core.script; + +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.core.util.AuxiliaryUtils; + +import java.net.URL; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author qinluo + * @date 2022/11/28 19:41 + * @since 1.0.0 + */ +public class ScriptDetector { + + private static final String LOCATION = "META-INF/smart-flow-script"; + private final Map> javaTypes = new ConcurrentHashMap<>(); + + private static final ScriptDetector DETECTOR = new ScriptDetector(); + + private ScriptDetector() { + try { + Enumeration resources = this.getClass().getClassLoader().getResources(LOCATION); + while (resources.hasMoreElements()) { + URL url = resources.nextElement(); + + Properties properties = new Properties(); + properties.load(url.openStream()); + + Set keys = properties.stringPropertyNames(); + for (String key : keys) { + AssertUtil.notBlank(key, "script key must not be blank"); + String type = properties.getProperty(key); + AssertUtil.notBlank(type, "script " + key + " type must not be blank"); + Class javaType = AuxiliaryUtils.beType(type); + AssertUtil.notNull(javaType, "script " + key + " type must be a javaType"); + AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(javaType), "script " + key + " type must be a subclass of ScriptCondition"); + AssertUtil.isTrue(ScriptCondition.class != (javaType), "script " + key + " type must be a subclass of ScriptCondition"); + javaTypes.put(key, javaType); + } + } + } catch (Exception e) { + throw new FlowException(e); + } + + } + + public Class getJavaType(String type) { + return javaTypes.get(type); + } + + public static ScriptDetector get() { + return DETECTOR; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java index 9c6af05..56e1f85 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java @@ -1,5 +1,7 @@ package org.smartboot.flow.core.util; +import org.smartboot.flow.core.exception.FlowException; + import java.util.Objects; /** @@ -20,31 +22,37 @@ public final class AssertUtil { public static void notNull(Object value, String message) { if (value == null) { - throw new IllegalArgumentException(message); + throw new FlowException(message); } } public static void assertNull(Object value, String message) { if (value != null) { - throw new IllegalArgumentException(message); + throw new FlowException(message); } } public static void notBlank(String value, String message) { if (value == null || value.trim().length() == 0) { - throw new IllegalArgumentException(message); + throw new FlowException(message); } } public static void isTrue(boolean value, String message) { if (!value) { - throw new IllegalArgumentException(message); + throw new FlowException(message); + } + } + + public static void isFalse(boolean value, String message) { + if (value) { + throw new FlowException(message); } } public static void assertEquals(Object expect, Object actual, String message) { if (!Objects.equals(expect, actual)) { - throw new IllegalArgumentException(message); + throw new FlowException(message); } } } 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 a25db16..6e0f596 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 @@ -31,4 +31,12 @@ public final class AuxiliaryUtils { return false; } } + + public static Class beType(String typename) { + try { + return Class.forName(typename); + } catch (Exception e) { + return null; + } + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index 9602c7a..ffc7dad 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -1,8 +1,8 @@ package org.smartboot.flow.core.view.plantuml; import org.smartboot.flow.core.common.ComponentType; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.util.AuxiliaryUtils; import java.util.ArrayList; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java index 5eb8a41..fcc795b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.view.plantuml; import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.common.ComponentType; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; 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 9291070..24b5ed8 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 @@ -1,7 +1,7 @@ package org.smartboot.flow.core.visitor; import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.component.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.component.Component; import java.util.List; diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 1f5a864..9b41b96 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -69,6 +69,12 @@ + + + + + + @@ -77,11 +83,15 @@ - - + + + + + + - + @@ -112,7 +122,11 @@ - + + + + + @@ -134,7 +148,11 @@ - + + + + + @@ -144,13 +162,18 @@ - + + + + + + @@ -163,7 +186,7 @@ - + @@ -187,8 +210,13 @@ - + + + + + + @@ -207,8 +235,13 @@ - + + + + + + @@ -224,7 +257,7 @@ - + @@ -248,8 +281,17 @@ - + + + + + + + + + + @@ -268,8 +310,13 @@ - + + + + + + diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java new file mode 100644 index 0000000..6147942 --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java @@ -0,0 +1,24 @@ +package org.smartboot.flow.example; + + +import org.smartboot.flow.core.script.ScriptCondition; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-11 21:45:21 + * @since 1.0.0 + */ +public class AlwaysFalseCondition extends ScriptCondition { + + @Override + public Object test(Integer integer, String s) { + System.out.println("always false invoked " + script); + return true; + } + + @Override + public String getType() { + return "alwaysfalse"; + } +} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java new file mode 100644 index 0000000..1772632 --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java @@ -0,0 +1,25 @@ +package org.smartboot.flow.example; + + +import org.smartboot.flow.core.script.ScriptCondition; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-11 21:45:21 + * @since 1.0.0 + */ +@Service +public class AlwaysTrueCondition extends ScriptCondition { + + @Override + public Object test(Integer integer, String s) { + System.out.println("invoked " + script); + return true; + } + + @Override + public String getType() { + return "always"; + } +} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java new file mode 100644 index 0000000..fa35d91 --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java @@ -0,0 +1,24 @@ +package org.smartboot.flow.example; + +import org.smartboot.flow.core.DegradeCallback; +import org.smartboot.flow.core.EngineContext; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-28 21:20:11 + * @since 1.0.0 + */ +@Service +public class ExampleCallback implements DegradeCallback { + + @Override + public void doWithDegrade(EngineContext context, Throwable e) { + System.out.println("degrade callback called."); + } + + @Override + public String describe() { + return "example-callback"; + } +} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java new file mode 100644 index 0000000..0ccea2f --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java @@ -0,0 +1,33 @@ +package org.smartboot.flow.example; + +import org.smartboot.flow.core.DegradeCallback; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.spring.extension.NamedAbstractExecutable; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-29 21:20:11 + * @since 1.0.0 + */ +@Service +public class SelfCallbackComponent extends NamedAbstractExecutable implements DegradeCallback { + + @Override + public void execute(Integer integer, String s) { + System.out.println("SelfCallbackComponent executed"); + throw new FlowException("aaaa"); + } + + @Override + public void doWithDegrade(EngineContext context, Throwable e) { + System.out.println("SelfCallbackComponent-degrade callback called."); + System.out.println("SelfCallbackComponent-degrade e = " + e.getMessage()); + } + + @Override + public String describe() { + return "example-callback"; + } +} diff --git a/smart-flow-example/src/main/resources/META-INF/smart-flow-script b/smart-flow-example/src/main/resources/META-INF/smart-flow-script new file mode 100644 index 0000000..c11e6bc --- /dev/null +++ b/smart-flow-example/src/main/resources/META-INF/smart-flow-script @@ -0,0 +1 @@ +alwaysfalse=org.smartboot.flow.example.AlwaysFalseCondition \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 1f6038b..29b6765 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -36,6 +36,7 @@ + @@ -59,9 +60,20 @@ - + + + + + + + + + + req == 2 + + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/degrade-callback.xsd b/smart-flow-example/src/main/resources/degrade-callback.xsd new file mode 100644 index 0000000..afbdb5a --- /dev/null +++ b/smart-flow-example/src/main/resources/degrade-callback.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example3.xsd b/smart-flow-example/src/main/resources/flow-example3.xsd index 1ddc418..2d4bea8 100644 --- a/smart-flow-example/src/main/resources/flow-example3.xsd +++ b/smart-flow-example/src/main/resources/flow-example3.xsd @@ -12,4 +12,7 @@ + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd index ecb79d1..e62424f 100644 --- a/smart-flow-example/src/main/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -8,7 +8,7 @@ - + diff --git a/smart-flow-example/src/main/resources/script-use.xsd b/smart-flow-example/src/main/resources/script-use.xsd new file mode 100644 index 0000000..a690404 --- /dev/null +++ b/smart-flow-example/src/main/resources/script-use.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index adf41fb..f81f0e3 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -10,7 +10,7 @@ import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.IfComponent; import org.smartboot.flow.core.executable.AbstractExecutable; diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java index ac5ee41..8afab3a 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java @@ -9,7 +9,7 @@ import org.smartboot.flow.example.*; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.IfComponent; import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java index 36ceab7..0a5277c 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java @@ -10,7 +10,7 @@ import org.smartboot.flow.example.*; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; /** diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java index b668b0b..01fac1a 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java @@ -8,7 +8,7 @@ import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.example.*; import org.smartboot.flow.example.attributes.AttributeTest; diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java new file mode 100644 index 0000000..aa2515f --- /dev/null +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java @@ -0,0 +1,38 @@ +package org.smartboot.flow.example.degrade; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.manager.DefaultEngineManager; +import org.smartboot.flow.core.parser.DefaultParser; +import org.smartboot.flow.example.EngineTest; + +/** + * @author qinluo + * @date 2022-11-15 23:42:32 + * @since 1.0.0 + */ +public class DegradeCallbackTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); + + + @BeforeEach + public void setUp() { + DefaultEngineManager.getDefaultManager().detachAll(); + } + + @Test + public void testDegradeCallback() { + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/degrade-callback.xsd")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + EngineContext execute = testEngine.execute((Integer)null); + LOGGER.info("trace \n{}", execute.getTrace()); + } +} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java index 997b2b5..95ecaaf 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java @@ -16,8 +16,8 @@ import org.smartboot.flow.example.attributes.AttributeTest; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import java.util.Map; diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java new file mode 100644 index 0000000..0f57863 --- /dev/null +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java @@ -0,0 +1,38 @@ +package org.smartboot.flow.example.script; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.manager.DefaultEngineManager; +import org.smartboot.flow.core.parser.DefaultParser; +import org.smartboot.flow.example.EngineTest; + +/** + * @author qinluo + * @date 2022-11-15 23:42:32 + * @since 1.0.0 + */ +public class ScriptTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); + + + @BeforeEach + public void setUp() { + DefaultEngineManager.getDefaultManager().detachAll(); + } + + @Test + public void testScript() { + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/script-use.xsd")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + EngineContext execute = testEngine.execute((Integer)null); + LOGGER.info("trace \n{}", execute.getTrace()); + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java index 844d4c4..552420d 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java @@ -3,8 +3,8 @@ package org.smartboot.flow.manager.change; import com.alibaba.fastjson.JSON; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.manager.DefaultEngineManager; import org.smartboot.flow.core.manager.ManagerAction; import org.smartboot.flow.core.util.AssertUtil; diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index f475631..f80f571 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -1,7 +1,7 @@ package org.smartboot.flow.spring.extension; -import org.smartboot.flow.core.component.AttributeHolder; -import org.smartboot.flow.core.component.Attributes; +import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.parser.DefinitionVisitor; import org.smartboot.flow.core.parser.definition.ChooseDefinition; import org.smartboot.flow.core.parser.definition.ElementDefinition; @@ -9,6 +9,8 @@ import org.smartboot.flow.core.parser.definition.EngineDefinition; import org.smartboot.flow.core.parser.definition.IfElementDefinition; import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition; import org.smartboot.flow.core.parser.definition.PipelineDefinition; +import org.smartboot.flow.core.parser.definition.ScriptDefinition; +import org.smartboot.flow.core.script.ScriptCondition; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.springframework.beans.PropertyValue; @@ -36,7 +38,32 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { @Override public void visit(ElementDefinition ed) { - ed.visit(this); + if (ed instanceof ScriptDefinition) { + ScriptDefinition sed = (ScriptDefinition)ed; + Class javaType = sed.getJavaType(); + // Maybe a ref. + if (javaType == null) { + BeanDefinition beanDefinition = registry.getBeanDefinition(sed.getName()); + String beanClassName = beanDefinition.getBeanClassName(); + Class defJavaType = AuxiliaryUtils.beType(beanClassName); + AssertUtil.notNull(defJavaType, "bean " + sed.getName() + " javaType must be subclass of ScriptCondition"); + AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(defJavaType), "bean " + sed.getName() + " javaType must be subclass of ScriptCondition"); + + // Register script content. + beanDefinition.getPropertyValues().add("script", sed.getScript()); + } else { + RootBeanDefinition definition = new RootBeanDefinition(); + definition.setBeanClass(javaType); + PropertyValue script = new PropertyValue("script", sed.getScript()); + PropertyValue name = new PropertyValue("name", sed.getName()); + definition.getPropertyValues().addPropertyValue(name); + definition.getPropertyValues().addPropertyValue(script); + registry.registerBeanDefinition(ed.getIdentifier(), definition); + } + + } else { + ed.visit(this); + } } @Override @@ -48,6 +75,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); definition.getPropertyValues().addPropertyValue(pipeline); + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -69,6 +97,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { components.add(new RuntimeBeanReference(elementDef.getIdentifier())); } + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -83,6 +112,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.getPropertyValues().addPropertyValue(pipeline); appendAttributes(ed, definition); + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -90,7 +120,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { List attributes = ed.getAttributes(); for (AttributeHolder holder : attributes) { Attributes attribute = holder.getAttribute(); - if (attribute == Attributes.NAME) { + if (attribute == Attributes.NAME || attribute == Attributes.DEGRADE_CALLBACK) { continue; } PropertyValue value = new PropertyValue(attribute.getName(), holder.getValue()); @@ -117,7 +147,24 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.getPropertyValues().add("executable", new RuntimeBeanReference(ed.getExecute())); } + AttributeHolder degradeCallback = ed.getAttributes().stream() + .filter(p -> p.getAttribute() == Attributes.DEGRADE_CALLBACK).findFirst().orElse(null); + + if (degradeCallback != null) { + String callback = String.valueOf(degradeCallback.getValue()); + + if (isType(callback)) { + RootBeanDefinition conditionDef = new RootBeanDefinition(); + conditionDef.setBeanClassName(callback); + definition.getPropertyValues().add("degradeCallback", conditionDef); + } else { + AssertUtil.notBlank(callback, "component callback ref must not be null!"); + definition.getPropertyValues().add("degradeCallback", new RuntimeBeanReference(callback)); + } + } + appendAttributes(ed, definition); + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -160,6 +207,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } appendAttributes(ed, definition); + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -199,6 +247,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } appendAttributes(ed, definition); + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); registry.registerBeanDefinition(ed.getIdentifier(), definition); } } diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java index 64e473f..621c1b3 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java @@ -14,5 +14,6 @@ public class SpringNamespaceHandler extends NamespaceHandlerSupport { ProxyParser proxyParser = new ProxyParser(); this.registerBeanDefinitionParser("pipeline", proxyParser); this.registerBeanDefinitionParser("engine", proxyParser); + this.registerBeanDefinitionParser("script", proxyParser); } } -- Gitee From ada26c9b3869cca856f55d4f211d80c627dc5d37 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 29 Nov 2022 21:17:39 +0800 Subject: [PATCH 06/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E9=80=82?= =?UTF-8?q?=E9=85=8Dognl=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + smart-flow-example/pom.xml | 6 +++ .../src/main/resources/bean.xml | 4 +- .../src/main/resources/log4j.properties | 2 +- .../src/main/resources/log4j2.properties | 2 +- .../org/smartboot/flow/example/ParseTest.java | 5 ++ smart-flow-script-condition/pom.xml | 31 +++++++++++ .../smart-flow-script-ognl/pom.xml | 27 ++++++++++ .../extension/ognl/OgnlScriptCondition.java | 53 +++++++++++++++++++ .../main/resources/META-INF/smart-flow-script | 1 + 10 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 smart-flow-script-condition/pom.xml create mode 100644 smart-flow-script-condition/smart-flow-script-ognl/pom.xml create mode 100644 smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java create mode 100644 smart-flow-script-condition/smart-flow-script-ognl/src/main/resources/META-INF/smart-flow-script diff --git a/pom.xml b/pom.xml index 913c77d..b2f7d00 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ smart-flow-spring-extension smart-flow-manager smart-flow-example + smart-flow-script-condition diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml index 156fd6c..d98cd12 100644 --- a/smart-flow-example/pom.xml +++ b/smart-flow-example/pom.xml @@ -49,6 +49,12 @@ 2.0.3 + + + org.smartboot + smart-flow-script-ognl + 1.0.2 + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 29b6765..8573de2 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -72,8 +72,8 @@ - - req == 2 + + request == 2 \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/log4j.properties b/smart-flow-example/src/main/resources/log4j.properties index 05ad41f..70b2b16 100644 --- a/smart-flow-example/src/main/resources/log4j.properties +++ b/smart-flow-example/src/main/resources/log4j.properties @@ -24,7 +24,7 @@ log4j.appender.error.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### -log4j.rootLogger=info,stdout +log4j.rootLogger=debug,info,stdout #log4j.logger.org.hibernate=info #log4j.logger.org.hibernate=debug diff --git a/smart-flow-example/src/main/resources/log4j2.properties b/smart-flow-example/src/main/resources/log4j2.properties index fced116..e05109d 100644 --- a/smart-flow-example/src/main/resources/log4j2.properties +++ b/smart-flow-example/src/main/resources/log4j2.properties @@ -2,5 +2,5 @@ appender.console.type = Console appender.console.name = console appender.console.layout.type = PatternLayout -rootLogger.level = info +rootLogger.level = debug rootLogger.appenderRef.console.ref = console \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java index 8cdcda6..4afdbc8 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java @@ -31,6 +31,11 @@ public class ParseTest { testEngine.execute((Integer) null); + + LOGGER.info("========================================================================="); + EngineContext context1 = testEngine.execute(2); + LOGGER.info("trace\n {}", context1.getTrace()); + Thread.sleep(60000); } } diff --git a/smart-flow-script-condition/pom.xml b/smart-flow-script-condition/pom.xml new file mode 100644 index 0000000..437888e --- /dev/null +++ b/smart-flow-script-condition/pom.xml @@ -0,0 +1,31 @@ + + + + flow-engine + org.smartboot + 1.0.2 + + 4.0.0 + pom + + smart-flow-script-ognl + + + smart-flow-script-condition + + + 8 + 8 + + + + + org.smartboot + smart-flow-core + 1.0.2 + + + + \ No newline at end of file diff --git a/smart-flow-script-condition/smart-flow-script-ognl/pom.xml b/smart-flow-script-condition/smart-flow-script-ognl/pom.xml new file mode 100644 index 0000000..dcba2a1 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-ognl/pom.xml @@ -0,0 +1,27 @@ + + + + smart-flow-script-condition + org.smartboot + 1.0.2 + + 4.0.0 + + smart-flow-script-ognl + + + 8 + 8 + + + + + + ognl + ognl + 3.3.4 + + + \ No newline at end of file diff --git a/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java new file mode 100644 index 0000000..85a24b2 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java @@ -0,0 +1,53 @@ +package org.smartboot.flow.condition.extension.ognl; + +import ognl.Ognl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.script.ScriptCondition; +import org.smartboot.flow.core.script.ScriptConstants; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author qinluo + * @date 2022/11/29 21:01 + * @since 1.0.0 + */ +public class OgnlScriptCondition extends ScriptCondition { + + private static final Logger LOGGER = LoggerFactory.getLogger(OgnlScriptCondition.class); + + @Override + public Object test(EngineContext engineContext) { + try { + Map context = new HashMap<>(); + context.put(ScriptConstants.REQ, engineContext.getReq()); + context.put(ScriptConstants.RESULT, engineContext.getResult()); + context.put(ScriptConstants.CONTEXT, engineContext); + + Object value = Ognl.getValue(script, context); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("evaluate script {} finished", script); + LOGGER.debug("evaluate value {}", value); + } + + return value; + } catch (Exception e) { + throw new FlowException("Ognl evaluate failed, script : " + script, e); + } + } + + @Override + public Object test(T t, S s) { + // do nothing + return null; + } + + @Override + public String getType() { + return "OGNL"; + } +} diff --git a/smart-flow-script-condition/smart-flow-script-ognl/src/main/resources/META-INF/smart-flow-script b/smart-flow-script-condition/smart-flow-script-ognl/src/main/resources/META-INF/smart-flow-script new file mode 100644 index 0000000..a3d2334 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-ognl/src/main/resources/META-INF/smart-flow-script @@ -0,0 +1 @@ +ognl=org.smartboot.flow.condition.extension.ognl.OgnlScriptCondition \ No newline at end of file -- Gitee From ff67f5ac1d3cd69e59e4a2a0e31bc48e9c14b857 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 29 Nov 2022 21:21:48 +0800 Subject: [PATCH 07/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/smartboot/flow/core/ScriptElementParser.java | 2 +- .../java/org/smartboot/flow/core/script/ScriptDetector.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java index 2a85fea..b7daab4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java @@ -26,7 +26,7 @@ public class ScriptElementParser extends AbstractElementParser { elementDefinition.setName(name); elementDefinition.setIdentifier(name); elementDefinition.setType(type); - elementDefinition.setScript(element.getTextContent()); + elementDefinition.setScript(element.getTextContent().trim()); context.register(elementDefinition); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java index c577d0c..96cee1a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java @@ -6,6 +6,7 @@ import org.smartboot.flow.core.util.AuxiliaryUtils; import java.net.URL; import java.util.Enumeration; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -41,7 +42,7 @@ public class ScriptDetector { AssertUtil.notNull(javaType, "script " + key + " type must be a javaType"); AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(javaType), "script " + key + " type must be a subclass of ScriptCondition"); AssertUtil.isTrue(ScriptCondition.class != (javaType), "script " + key + " type must be a subclass of ScriptCondition"); - javaTypes.put(key, javaType); + javaTypes.put(key.toLowerCase(), javaType); } } } catch (Exception e) { @@ -51,7 +52,8 @@ public class ScriptDetector { } public Class getJavaType(String type) { - return javaTypes.get(type); + AssertUtil.notBlank(type, "type must not blank"); + return javaTypes.get(type.trim().toLowerCase()); } public static ScriptDetector get() { -- Gitee From 6c71cb46f5eee5a17442e1bf55cc03b1de40f05c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 29 Nov 2022 21:23:05 +0800 Subject: [PATCH 08/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/condition/extension/ognl/OgnlScriptCondition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java index 85a24b2..8867e6f 100644 --- a/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java +++ b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java @@ -30,7 +30,7 @@ public class OgnlScriptCondition extends ScriptCondition { Object value = Ognl.getValue(script, context); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("evaluate script {} finished", script); + LOGGER.debug("evaluate script [{}] finished", script); LOGGER.debug("evaluate value {}", value); } -- Gitee From 27a02ef9207d2ce957e85526d83c4ff52ee51e4a Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 30 Nov 2022 10:47:22 +0800 Subject: [PATCH 09/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Egroovy=20=20=20=20=20=20-=20=E6=96=B0=E5=A2=9Ejavascri?= =?UTF-8?q?pt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/core/script/ScriptCondition.java | 12 +++++ .../flow/core/script/ScriptDetector.java | 1 - smart-flow-example/pom.xml | 6 +++ .../flow/example/AlwaysFalseCondition.java | 3 +- .../flow/example/AlwaysTrueCondition.java | 3 +- .../src/main/resources/bean.xml | 5 +- .../org/smartboot/flow/example/ParseTest.java | 14 +++++ smart-flow-script-condition/pom.xml | 2 + .../smart-flow-script-groovy/pom.xml | 28 ++++++++++ .../groovy/GroovyScriptCondition.java | 54 +++++++++++++++++++ .../extension/groovy/JavaScriptCondition.java | 13 +++++ .../main/resources/META-INF/smart-flow-script | 2 + .../extension/ognl/OgnlScriptCondition.java | 6 --- 13 files changed, 138 insertions(+), 11 deletions(-) create mode 100644 smart-flow-script-condition/smart-flow-script-groovy/pom.xml create mode 100644 smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java create mode 100644 smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/JavaScriptCondition.java create mode 100644 smart-flow-script-condition/smart-flow-script-groovy/src/main/resources/META-INF/smart-flow-script diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java index b2fd5c5..f75ccc6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptCondition.java @@ -1,5 +1,6 @@ package org.smartboot.flow.core.script; +import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.NamedCondition; /** @@ -29,6 +30,17 @@ public abstract class ScriptCondition extends NamedCondition { */ public abstract String getType(); + /** + * Don't override this method. + */ + @Override + public final Object test(T t, S s) { + return null; + } + + @Override + public abstract Object test(EngineContext context); + @Override public String describe() { return "script-" + getType(); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java index 96cee1a..f95b713 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java @@ -6,7 +6,6 @@ import org.smartboot.flow.core.util.AuxiliaryUtils; import java.net.URL; import java.util.Enumeration; -import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml index d98cd12..e66efe2 100644 --- a/smart-flow-example/pom.xml +++ b/smart-flow-example/pom.xml @@ -55,6 +55,12 @@ smart-flow-script-ognl 1.0.2 + + + org.smartboot + smart-flow-script-groovy + 1.0.2 + \ No newline at end of file diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java index 6147942..627116e 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java @@ -1,6 +1,7 @@ package org.smartboot.flow.example; +import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.script.ScriptCondition; import org.springframework.stereotype.Service; @@ -12,7 +13,7 @@ import org.springframework.stereotype.Service; public class AlwaysFalseCondition extends ScriptCondition { @Override - public Object test(Integer integer, String s) { + public Object test(EngineContext context) { System.out.println("always false invoked " + script); return true; } diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java index 1772632..29b5449 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java @@ -1,6 +1,7 @@ package org.smartboot.flow.example; +import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.script.ScriptCondition; import org.springframework.stereotype.Service; @@ -13,7 +14,7 @@ import org.springframework.stereotype.Service; public class AlwaysTrueCondition extends ScriptCondition { @Override - public Object test(Integer integer, String s) { + public Object test(EngineContext context) { System.out.println("invoked " + script); return true; } diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 8573de2..e37753f 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -72,8 +72,9 @@ - - request == 2 + + var local = 2; + local == request; \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java index 4afdbc8..cb737c3 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java @@ -6,9 +6,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.script.ScriptDetector; import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; import org.springframework.context.support.ClassPathXmlApplicationContext; +import java.net.URL; +import java.util.Enumeration; + /** * @author yamikaze * @version 1.0.0 @@ -38,4 +42,14 @@ public class ParseTest { Thread.sleep(60000); } + + @Test + public void testGetExtension() throws Exception { + LOGGER.warn("{}", ScriptDetector.get().getJavaType("javaScript")); + + Enumeration resources = this.getClass().getClassLoader().getResources("META-INF/smart-flow-script"); + LOGGER.info("size {}", resources); + + LOGGER.info("class [}", Class.forName("org.smartboot.flow.condition.extension.groovy.GroovyScriptCondition")); + } } diff --git a/smart-flow-script-condition/pom.xml b/smart-flow-script-condition/pom.xml index 437888e..dff0dd7 100644 --- a/smart-flow-script-condition/pom.xml +++ b/smart-flow-script-condition/pom.xml @@ -9,8 +9,10 @@ 4.0.0 pom + smart-flow-script-ognl + smart-flow-script-groovy smart-flow-script-condition diff --git a/smart-flow-script-condition/smart-flow-script-groovy/pom.xml b/smart-flow-script-condition/smart-flow-script-groovy/pom.xml new file mode 100644 index 0000000..2318916 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-groovy/pom.xml @@ -0,0 +1,28 @@ + + + + smart-flow-script-condition + org.smartboot + 1.0.2 + + 4.0.0 + + smart-flow-script-groovy + + + 8 + 8 + + + + + + org.codehaus.groovy + groovy + 3.0.9 + + + + \ No newline at end of file diff --git a/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java new file mode 100644 index 0000000..e381315 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java @@ -0,0 +1,54 @@ +package org.smartboot.flow.condition.extension.groovy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.script.ScriptCondition; +import org.smartboot.flow.core.script.ScriptConstants; + +import javax.script.Bindings; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + +/** + * @author qinluo + * @date 2022/11/29 21:01 + * @since 1.0.0 + */ +public class GroovyScriptCondition extends ScriptCondition { + + private static final Logger LOGGER = LoggerFactory.getLogger(GroovyScriptCondition.class); + private static final ScriptEngineManager engineManager = new ScriptEngineManager(); + + protected String getScriptLang() { + return "groovy"; + } + + + @Override + public Object test(EngineContext engineContext) { + try { + ScriptEngine engine = engineManager.getEngineByName(getScriptLang()); + Bindings data = engine.createBindings(); + data.put(ScriptConstants.REQ, engineContext.getReq()); + data.put(ScriptConstants.RESULT, engineContext.getResult()); + data.put(ScriptConstants.CONTEXT, engineContext); + + Object value = engine.eval(script, data); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("evaluate script [{}] finished", script); + LOGGER.debug("evaluate value {}", value); + } + + return value; + } catch (Exception e) { + throw new FlowException(getScriptLang() + " evaluate failed, script : " + script, e); + } + } + + @Override + public String getType() { + return getScriptLang(); + } +} diff --git a/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/JavaScriptCondition.java b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/JavaScriptCondition.java new file mode 100644 index 0000000..e8dfccd --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/JavaScriptCondition.java @@ -0,0 +1,13 @@ +package org.smartboot.flow.condition.extension.groovy; + +/** + * @author qinluo + * @date 2022/11/29 21:01 + * @since 1.0.0 + */ +public class JavaScriptCondition extends GroovyScriptCondition { + + protected String getScriptLang() { + return "javascript"; + } +} diff --git a/smart-flow-script-condition/smart-flow-script-groovy/src/main/resources/META-INF/smart-flow-script b/smart-flow-script-condition/smart-flow-script-groovy/src/main/resources/META-INF/smart-flow-script new file mode 100644 index 0000000..f679dcb --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-groovy/src/main/resources/META-INF/smart-flow-script @@ -0,0 +1,2 @@ +groovy=org.smartboot.flow.condition.extension.groovy.GroovyScriptCondition +javascript=org.smartboot.flow.condition.extension.groovy.JavaScriptCondition \ No newline at end of file diff --git a/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java index 8867e6f..e930fcc 100644 --- a/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java +++ b/smart-flow-script-condition/smart-flow-script-ognl/src/main/java/org/smartboot/flow/condition/extension/ognl/OgnlScriptCondition.java @@ -40,12 +40,6 @@ public class OgnlScriptCondition extends ScriptCondition { } } - @Override - public Object test(T t, S s) { - // do nothing - return null; - } - @Override public String getType() { return "OGNL"; -- Gitee From 5c10be45158e0fe350c7b7d2d4a826dd81830590 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 30 Nov 2022 16:06:16 +0800 Subject: [PATCH 10/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 271 +++++------------- .../core/parser/ElementParserRegistry.java | 2 - .../{ => parser}/ScriptElementParser.java | 5 +- 3 files changed, 70 insertions(+), 208 deletions(-) rename smart-flow-core/src/main/java/org/smartboot/flow/core/{ => parser}/ScriptElementParser.java (83%) diff --git a/README.md b/README.md index 5dd0b8f..14bdf94 100644 --- a/README.md +++ b/README.md @@ -10,35 +10,39 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流程中常见的条件分支控制、子流程、业务组件异步和降级等功能。 +### 名词简介 +- Engine smart-flow管理流水线的对象,也是流程引擎进行调用的入口 +- Pipeline 由组件构成的线性流水线,流程引擎执行会按照流水线的配置线性执行 +- Component 业务逻辑的包装层,统一称为组件,smart-flow基于组件层提供各种能力,例如分支选择、降级、异步等 +- Context 执行上下文,用于存放流程引擎执行过程的中间信息 +- Condition 流程中用于分支判断和路由的组件 +- Executable 面向开发者的组件,开发者需要实现该接口,编写业务逻辑 ### 功能特性 -- [X] 支持If、 Switch、 子流程编排 -- [X] 支持组件异步、降级、回滚 -- [X] 支持XML配置解析 -- [X] 支持Spring Xml配置集成 -- [X] 支持引擎执行过程可视化 -- [X] 支持引擎结构可视化 -- [ ] 支持适配组件以复用公共子流程 -- [ ] 支持降级回调 -- [X] 支持引擎数据上报 -- [X] 支持组件管理,动态修改组件属性 -- [ ] 支持条件表达式 +#### 核心功能 +- [X] 支持基于Java代码或者XML配置的线性流程编排 +- [X] 支持IF、CHOOSE条件分支 +- [X] 支持组件异步执行以及组件执行依赖 +- [X] 支持组件降级以及降级回调 +- [X] 支持IF、CHOOSE、PIPELINE嵌套子流程 +- [X] 支持组件失败回滚 +- [X] 支持查看调用路径 -### 项目架构 +#### 高级功能 +- [X] 支持Spring环境XML配置集成 +- [X] 支持实时生成流程引擎结构图 +- [X] 支持多种条件表达式(Groovy、OGNL、JavaScript等) +#### 管理功能 +- [X] 支持自定义执行数据采集 +- [X] 支持HTTP方式引擎数据上报(包含执行数据) +- [X] 支持组件动态管理(动态降级、启用组件等功能) +- [ ] 自带管理后台 +- [ ] 支持引擎Reload -### 接入指南 - -#### 名词简介 - -- Engine smart-flow的调用入口,也是用户使用的直接对象 -- Pipeline 业务逻辑流水线,流水线中的每个步骤都是组件,组件可以理解为业务实现的一部分 -- Component 组件, smart-flow基于组件提供各种能力,降级、回滚、异步处理等操作,对使用者透明 -- Context 执行上下文,用于存放流程引擎执行过程的中间信息 -- Condition 流程中用于分支判断和路由的组件 -- Executable 面向使用者的组件,smart-flow中真正执行业务逻辑的组件 +### 快速接入 #### 依赖引入 @@ -50,206 +54,69 @@ cd smart-flow mvn clean install ``` 安装完毕后在项目中进行引入 - +`lastest.version` = 1.0.2 ```XML org.smartboot smart-flow-core - 1.0.0 + ${lastest.version} - - - - org.smartboot - smart-flow-spring-extension - 1.0.0 - - - ``` - - -#### 编码方式编排业务流程 - -smart-flow支持使用Builder风格的流程编排,各编排器如下: - -- ExecutableBuilder 将一个`Executable`封装为一个基本组件 -- EngineBuilder 构建一个Engine实例 -- PipelineBuilder 构建一个Pipeline实例,支持在PipelineBuilder构建子流程、If分支、Choose分支 -- IfComponentBuilder 构建一个IfComponent,支持then和else逻辑操作 -- ChooseComponentBuilder构建一个ChooseComponent,支持case和default逻辑操作 - -例如以下示例(构建名为main process的pipeline): - -```Java -// 构建一个EngineBuilder -EngineBuilder builder = new EngineBuilder<>(); -// 构建一个PipelineBuilder,其中pipeline的名字为main process -PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); - -ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); -// 构建一个基本component,其中Step5是一个Executable实例 -Component nested = execBuilder.newAdapter(new Step5()); -// step1; -// step2; -// if then step3 else ElseStep -// if then if then step5 -// choose: -// case 1 IntegerStep; -// case null NullStep -// default DefaultStep -// subprocess -// step4 -// ErrorStep -pipelineBuilder.next(new Step1()).next(new Step2()) - .next(new IfCondition()).then(new Step3(), new ElseStep()) - .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - .choose(new ChooseCondition()) - .newBranch("null", new NullStep()) - .newBranch(1, new IntegerStep()).end(new DefaultStep()) - .pipeline("subprocess").next(new Step4()).next(new ErrorStep()).end(); - -// 流程上下文 -EngineContext context = new EngineContext<>(); -context.setReq(1); -context.setResult("hello"); - -// 流程执行 -builder.pipeline(pipelineBuilder.build()).build().execute(context); - -LOGGER.info("trace {}", context.getTrace()); +#### 实现Executable +实现`Executable`接口,或者继承`AbstractExecutable`, 实现`execute`方法 +```java +public class ExampleExecutable extends AbstractExecutable { + + @Override + public void execute(Integer request, String result) { + // 执行业务逻辑 + } +} ``` +`Executable`接口自带泛型,分别为流程引擎的入参和出参,如果想要获取流程引擎上下文信息,覆盖另外的`execute`方法即可 +```java +@Override +public void execute(EngineContext context) { + // 执行业务逻辑 +} +``` +#### 编码方式编排业务流程 +smart-flow支持`Builder`风格的流程引擎编排,例如如下示例: +```java +// 创建名为defaultEngine的流程引擎 +EngineBuilder builder = new EngineBuilder<>("defaultEngine"); -#### xml格式编排业务流程 - -smart-flow还支持使用xml的形式对流程进行编排,使用xml的形式编排更加容易,也更加清晰。 相关xml标签的使用简介参考 (xml配置项说明) -使用示例如下: - -```XML - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// 创建一条流水线,名字叫main process, 包含2个步骤 +builder.pipeline(new PipelineBuilder<>("main process") + .next(new ExampleExecutable()) + .next(new ExampleExecutable()).build()); +// 创建引擎,引擎的名字为defaultEngine +FlowEngine engine = builder.build(); ``` -解析xml: - -```Java -DefaultParser parser = new DefaultParser(); -parser.parse(this.getClass().getResourceAsStream("/flow-example7.xsd")); -// 获取xml配置中有多少engine -LOGGER.info("engines {}", parser.getEngineNames()); - -// 获取名为testEngine的Engine实例 -FlowEngine testEngine = parser.getEngine("testEngine"); -EngineContext execute = testEngine.execute(1); -LOGGER.info("trace \n{}", execute.getTrace()); +#### 流程引擎执行 +流程引擎执行必须执行参数(参数可以为空),同时对于返回值可以在调用入口指定,也可以在流程引擎内部的组件指定。 +```java +FlowEngine engine = builder.build(); +engine.execute(1); // 指定入参 +engine.execute(1, ""); // 指定入参以及出参 +engine.execute((Integer)null); // 不指定入参 ``` +流程引擎执行后会返回一个context,可以通过`getResult`获取返回结果 +```java +EngineContext context = engine.execute(1); - -#### 与spring结合使用xml编排 - -在spring环境中的编排与单独使用XML并无不同, - -引入smart-flow的xsd约束文件即可。 - -示例如下: - -```XML - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +String result = context.getResult(); ``` -代码中引用,可直接通用依赖注入引用流程引擎实例 - -```Java -ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:bean.xml"); - -FlowEngine testEngine = (FlowEngine)context.getBean("testEngine", FlowEngine.class); -EngineContext executeContext = testEngine.execute(1); -LOGGER.info("trace\n {}", executeContext.getTrace()); -``` +### 更多使用文档 +请参阅链接 《smart-flow使用指南》 ### 组件介绍和高级特性 diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java index aafeb9a..30262cf 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java @@ -1,7 +1,5 @@ package org.smartboot.flow.core.parser; -import org.smartboot.flow.core.ScriptElementParser; - import java.util.HashMap; import java.util.Map; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ScriptElementParser.java similarity index 83% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ScriptElementParser.java index b7daab4..38dcec0 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ScriptElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ScriptElementParser.java @@ -1,8 +1,5 @@ -package org.smartboot.flow.core; +package org.smartboot.flow.core.parser; -import org.smartboot.flow.core.parser.AbstractElementParser; -import org.smartboot.flow.core.parser.ParseConstants; -import org.smartboot.flow.core.parser.ParserContext; import org.smartboot.flow.core.parser.definition.ScriptDefinition; import org.smartboot.flow.core.util.AssertUtil; import org.w3c.dom.Element; -- Gitee From e74f64075f52cd960a5f8b3230805a0c50d444a7 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 30 Nov 2022 23:38:28 +0800 Subject: [PATCH 11/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 284 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 172 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 14bdf94..e8dfc6f 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ -## smart-flow - -### 项目背景 +# 项目背景 业务系统在发展的过程中,业务的逻辑越来越复杂,简单的逻辑步骤拆分已经不能快速适应业务的变化,大部分时候都是在主流程上打补丁的方式进行业务支持。 而且大量的业务逻辑被隐藏在实现细节中,无法从全局看到整体的业务流程。所以在此背景下,需要一个业务编排框架帮助我们将代码逻辑以组件化的方式组织起来,达到快速配置和快速了解业务全貌的作用。 -### 项目介绍 +# 项目介绍 smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流程中常见的条件分支控制、子流程、业务组件异步和降级等功能。 -### 名词简介 +# 名词简介 - Engine smart-flow管理流水线的对象,也是流程引擎进行调用的入口 - Pipeline 由组件构成的线性流水线,流程引擎执行会按照流水线的配置线性执行 - Component 业务逻辑的包装层,统一称为组件,smart-flow基于组件层提供各种能力,例如分支选择、降级、异步等 @@ -18,9 +16,9 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - Condition 流程中用于分支判断和路由的组件 - Executable 面向开发者的组件,开发者需要实现该接口,编写业务逻辑 -### 功能特性 +# 功能特性 -#### 核心功能 +## 核心功能 - [X] 支持基于Java代码或者XML配置的线性流程编排 - [X] 支持IF、CHOOSE条件分支 - [X] 支持组件异步执行以及组件执行依赖 @@ -29,12 +27,12 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [X] 支持组件失败回滚 - [X] 支持查看调用路径 -#### 高级功能 +## 高级功能 - [X] 支持Spring环境XML配置集成 - [X] 支持实时生成流程引擎结构图 - [X] 支持多种条件表达式(Groovy、OGNL、JavaScript等) -#### 管理功能 +## 管理功能 - [X] 支持自定义执行数据采集 - [X] 支持HTTP方式引擎数据上报(包含执行数据) - [X] 支持组件动态管理(动态降级、启用组件等功能) @@ -42,9 +40,9 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [ ] 支持引擎Reload -### 快速接入 +# 快速接入 -#### 依赖引入 +## 依赖引入 smart-flow暂未发布至maven仓库,使用者需要手动将工程克隆至本地进行安装 @@ -63,7 +61,7 @@ mvn clean install ``` -#### 实现Executable +## 实现Executable 实现`Executable`接口,或者继承`AbstractExecutable`, 实现`execute`方法 ```java public class ExampleExecutable extends AbstractExecutable { @@ -83,7 +81,7 @@ public void execute(EngineContext context) { } ``` -#### 编码方式编排业务流程 +## 编码方式编排业务流程 smart-flow支持`Builder`风格的流程引擎编排,例如如下示例: ```java // 创建名为defaultEngine的流程引擎 @@ -98,7 +96,7 @@ builder.pipeline(new PipelineBuilder<>("main process") FlowEngine engine = builder.build(); ``` -#### 流程引擎执行 +## 流程引擎执行 流程引擎执行必须执行参数(参数可以为空),同时对于返回值可以在调用入口指定,也可以在流程引擎内部的组件指定。 ```java FlowEngine engine = builder.build(); @@ -115,43 +113,94 @@ String result = context.getResult(); ``` -### 更多使用文档 -请参阅链接 《smart-flow使用指南》 - -### 组件介绍和高级特性 +# 核心功能介绍 -#### Executable 组件 +## Executable 组件 -`Executable`是smart-flow中面向业务, 用于执行真实业务逻辑的组件, -用户需要实现该接口进行业务逻辑的开发。 +`Executable`是smart-flow中唯一面向开发者的组件,用户需要使用该接口进行业务逻辑的开发。 为了方便用户使用,smart-flow提供了抽象实现`AbstractExecutable`, 用户可以继承`AbstractExecutable` -实现`execute`方法进行快速开发。 例如以下例子: +实现`execute`方法进行快速开发。 + +Tip: 为了后续流程维护,推荐覆盖`describe()`方法,返回当前组件的信息。 + +## 基于Java Builder的流程编排方式 +smart-flow提供了基于`Builder`风格的流程编排方式,用户可以使用相应的Builder快速对流程进行编排。 +以下为smart-flow提供的Builder列表: +* 流程引擎构造 +* 流水线构造 +* 组件构造 + +### 流程引擎构造 +smart-flow中负责流程引擎构造的Builder类是`EngineBuilder`, `EngineBuilder`接受一个name作为构造入参, +对于`EngineBuilder`以下几个参数是必须的: +* name smart-flow中的每个引擎都必须有名字 +* pipeline 流水线作为流程引擎的执行构建,也是必须的 +* executor 仅当流程中含有异步组件时必须指定 + +### 流水线构造 +smart-flow中负责流程引擎构造的Builder类是`PipelineBuilder`, `PipelineBuilder`与`EngineBuilder`类似,必须为其指定名字, +对于该Builder方法介绍如下: +* `next(Component/Executable)`接受组件/可执行接口作为流水线的下一步 +* `next(Condition)` 接受一个`Condition`条件, `PipelineBuilder`会返回一个表示IF条件分支的builder对象 +* `choose(Condition)` 接受一个`Condition`条件, `PipelineBuilder`会返回一个表示CHOOSE条件分支的builder对象 +* `pipeline(name)` 表示为当前流水线添加一个名为name的子流程,`PipelineBuilder`会返回一个新的`PipelineBuilder` + +需要注意的是,如果通过`PipelineBuilder`产生的子流程需要作用到父流程,需要调用`end()`方法而不是`build()`方法。 + +### 组件构造 + +#### 普通组件构造 +smart-flow中表示基本组件构造的是`ExecutableBuilder`, 该组件接受一个`Executable`实例,返回一个普通组件对象。 +```JAVA +Component component = ExecutableBuiler.newBuilder().newAdapter(new ExampleExecutable()); +``` -```Java -/** - * 业务的出入参数为Integer、String - */ -public class Step1 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step1 == " + integer); - } -} +#### IF组件构造 +smart-flow中表示IF组件构造的是`IfComponentBuilder`, smart-flow中if分支选择支持指定then/else +* `then(Component)` -``` +只有then,没有else +* `then(Component, Component)` + +第一个参数表示then,第二个参数表示else + +同时为了方便使用,还提供了相应的`Executable`接口,含义与以上两个接口一致: +* `then(Executable)` +* `then(Executable, Executable)` + +#### CHOOSE组件构造 +smart-flow中表示IF组件构造的是`ChooseBuilder`, smart-flow中choose分支选择支持指定case和default,等价于Java中的switch语句。 +* `newBranch(Object, Component)` +* `newBranch(Object, Executable)` + +表示新增一个分支选择,分支选择的值为Object, 分支执行步骤为Component/Executable +* `end()` -`AbstractExecutable`带有泛型,用户可以根据业务实际情况定义不同的类型,但请保证在一条pipeline中的所有Executable实现泛型都是一致的。 +结束当前choose分支构造,并且将构造完成的choose组件放置到pipeline中 +* `end(Component/Executable)` + +结束当前choose分支构造, 分支的默认逻辑为end方法的参数,并且将构造完成的choose组件放置到pipeline中 + +#### 子流程的嵌套 +可以通过`PipelineBuilder`的build方法,产生一个包含子流程的组件 + +#### 属性设置 +相关组件Builder提供了以下方法,用于设置组件的属性。smart-flow会基于为组件设置的属性进行相关的操作,例如降级、回滚等操作。 +```JAVA +builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); +``` +例如以上示例为组件设置了异步属性,同时异步超时时间为1000ms, 更多关于可设置的属性请参阅`Attributes`枚举。 -如想在多条不同的pipeline中复用同样的子流程片段,后续smart-flow会提供适配组件进行支持。 +需要注意的是,部分属性对于IF、CHOOSE、子流程组件可能不会生效, +例如`rollback`, 这是因为他们属于包装类型的组件,是否需要回滚取决于真实组件的属性。 -Tip: 如果在spring环境中,推荐继承`NamedAbstractExecutable`。 +## 基于XML的编排方式 -#### **组件回滚** +## **组件回滚** smart-flow中所有组件默认都是不可回滚的,需要使用者手动配置回滚属性。 回滚属性rollback=true, -在流程引擎执行失败或者手动设置回滚后,将按照已执行组件的执行顺序逆序执行回滚方法。 +在流程引擎执行失败或者手动设置回滚后,将按照已执行组件的执行顺序逆序执行回滚方法。 * builder设置回滚属性 ```java builder.apply(Attributes.ROLLBACK, true); @@ -165,13 +214,13 @@ builder.apply(Attributes.ROLLBACK, true); 关于回滚方法定义,请参考`org.smartboot.flow.core.Rollback`, 同时`Executable`接口继承于`Rollback`, 而为了方便使用,`AbstractExecutable`对相关rollback方法进行了空实现,业务上想要实现业务回滚覆盖相应的方法即可。 -需要注意的是, 回滚组件会在以下2种场景下失效: +需要注意的是, 回滚组件会在以下几种场景下失效: * 该组件还未执行到,流程便终止了 * 该组件同时是可降级组件,且降级后的后续组件并未发生异常,正常执行完毕 +## **组件降级与回调** -#### **组件降级** - +### 组件降级 smart-flow中所有组件默认都是不可降级的,需要使用者手动配置可降级属性degradable=true, 在流程引擎执行失败后,如果组件是可降级组件,将不会中断流程,而是会继续往下执行。 * builder设置属性 @@ -184,7 +233,21 @@ builder.apply(Attributes.DEGRADABLE, true); ``` -#### 组件异步 +### 降级回调 +降级回调仅对基本组件生效,在基本组件的`Executable`执行失败后,如果当前组件设置了degradable=true,将触发降级回调。 +降级回调接口参照`org.smartboot.flow.core.DegradeCallback`。 + +* builder设置属性 +```java +builder.apply(Attributes.DEGRADE_CALLBACK, "degrade-callback classname or object"); +``` +* XML方式设置属性 + +```xml + +``` + +## 组件异步 smart-flow支持组件异步执行,只需要进行2步即可开启异步执行。 @@ -193,10 +256,7 @@ smart-flow支持组件异步执行,只需要进行2步即可开启异步执行 若使用builder方式构建流程时,可以通过以下方式设置属性: ```java -ExecutableBuilder builder = ExecutableBuilder.newBuilder(); builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); -// 得到含有异步属性的组件 -Component asyncComponent = builder.newAdapter(new Step1()); ``` 若使用XML方式进行编排,只需为组件添加2个属性即可 ```xml @@ -209,7 +269,7 @@ Component asyncComponent = builder.newAdapter(new Step1()); ``` -#### 优雅中断流程 +## 优雅中断流程 smart-flow在发生异常时,会对流程进行终止,并对已执行组件进行回滚。 相比这种异常中断的方式而言,smart-flow提供了一种更优雅的中断方式。 使用者可以通过执行上文手动终止/回滚流程。 ```java @@ -223,7 +283,7 @@ public class Step1 extends AbstractExecutable { } ``` -#### 组件静默 +## 组件静默 smart-flow中所有组件默认都是开启可执行状态,如果需要跳过某个组件的执行,可以通过设置属性enabled=false进行跳过 * builder设置属性 ```java @@ -235,61 +295,18 @@ builder.apply(Attributes.ENABLED, false); ``` -#### 组件适配 -待开发 - -#### 组件管理 -smart-flow中的每一个`FlowEngine`实例默认都会加入`EngineManager`的管理, -用户可以通过使用`DefaultEngineManager`查看指定名称的engine组件数据,并动态地修改组件属性。 +## 组件适配 -例如以下例子,动态禁用某个组件: -```java -EngineManager defaultManager = DefaultEngineManager.getDefaultManager(); -// 通过engine名称获取engine模型数据 -EngineModel engineModel = defaultManager.getEngineModel("defaultEngine"); -// 获取该engine下所有的组件(包括嵌套子流程、if和choose分支) -Map components = engineModel.getComponents(); -String identifier = null; -// 获取组件的identifier唯一标识符 -for (Map.Entry modelEntry : components.entrySet()) { - if (modelEntry.getValue().getDescribe().contains("pipeline##subprocess##2")) { - identifier = modelEntry.getKey(); - } -} - -// 使用标识符修改enabled属性为false,禁用该组件 -AttributeHolder attributeHolder = new AttributeHolder(Attributes.ENABLED, false); -defaultManager.changeAttributes(identifier, attributeHolder); - -// 再次执行,查看调用路径,可以看到组件子流程未执行 -context = engine.execute(1); -LOGGER.info("trace {}", context.getTrace()); - -``` - -注意:由于组件的名称并不是必须的,所有组件的identifier是由`EngineManager`动态生成, -但组件的名称也会是identifier的一部分构成,所以建议所有组件都指定名称。 以下为指定与不指定的对比: -```TEXT -不指定 -defaultEngine-subprocess##2-none-qiewmdn4 -指定为step5 -identifier defaultEngine-DefaultPipeline-step5-5tqygjpx -``` - - -#### 查看执行调用路径 +## 查看组件执行路径 smart-flow默认提供执行路径日志, 在一次执行完毕后,可以通过`context.getTrace()`获取本次调用路径日志, 能够帮助开发者更加清晰的了解调用过程。具体使用以及效果如下: - -完整代码见`AsyncTest.java` - ```Java FlowEngine engine = builder.pipeline(pipelineBuilder.build()).executor(Executors.newFixedThreadPool(10)).build(); engine.execute(context); LOGGER.info("trace {}", context.getTrace()); ``` -输出效果如下(异步组件的调用使用~~~进行表示): +输出效果如下(异步组件的调用使用~~~进行表示): ```text flow-engine##defaultEngine escaped 310ms @@ -326,6 +343,67 @@ flow-engine##defaultEngine escaped 310ms ``` +# 高级功能介绍 + +## 实时生成流程引擎结构图 +smart-flow内嵌plantuml图像生成处理器,通过使用`PlantumlEngineVisitor`访问生成的`FlowEngine`实例, +在项目指定位置生成plantuml文件,例如以下示例,将在项目根目录下生成名为`engine-flow`的文件 +```Java +// Generate plantuml file named 'engine-flow' +PlantumlEngineVisitor plantumlEngineVisitor = new PlantumlEngineVisitor("engine-flow"); +// engine :需要生成流程图的流程实例 +plantumlEngineVisitor.visit(engine); +``` + +效果如下图(可在编译器中安装PlantUML插件进行查看): + + +![img.png](doc/engine-flow.png) + +如果想要生成其他形式图片,可以实现`EngineVisitor`, 对`FlowEngine`进行结构遍历,然后通过遍历得到的数据生成图片/文件 + + +# 管理功能 + +## 组件管理接口 +smart-flow中的每一个`FlowEngine`实例默认都会加入`EngineManager`的管理, +用户可以通过使用`DefaultEngineManager`查看指定名称的engine组件数据,并动态地修改组件属性。 + +例如以下例子,动态禁用某个组件: +```java +EngineManager defaultManager = DefaultEngineManager.getDefaultManager(); +// 通过engine名称获取engine模型数据 +EngineModel engineModel = defaultManager.getEngineModel("defaultEngine"); +// 获取该engine下所有的组件(包括嵌套子流程、if和choose分支) +Map components = engineModel.getComponents(); +String identifier = null; +// 获取组件的identifier唯一标识符 +for (Map.Entry modelEntry : components.entrySet()) { + if (modelEntry.getValue().getDescribe().contains("pipeline##subprocess##2")) { + identifier = modelEntry.getKey(); + } +} + +// 使用标识符修改enabled属性为false,禁用该组件 +AttributeHolder attributeHolder = new AttributeHolder(Attributes.ENABLED, false); +defaultManager.changeAttributes(identifier, attributeHolder); + +// 再次执行,查看调用路径,可以看到组件子流程未执行 +context = engine.execute(1); +LOGGER.info("trace {}", context.getTrace()); + +``` + +注意:由于组件的名称并不是必须的,所有组件的identifier是由`EngineManager`动态生成, +但组件的名称也会是identifier的一部分构成,所以建议所有组件都指定名称。 以下为指定与不指定的对比: +```TEXT +不指定 +defaultEngine-subprocess##2-none-qiewmdn4 +指定为step5 +identifier defaultEngine-DefaultPipeline-step5-5tqygjpx +``` + + #### xml配置项说明 相关xml标签的使用简介如下: @@ -357,25 +435,7 @@ flow-engine##defaultEngine escaped 310ms - async boolean类型,表示是否可异步 - timeout number类型,表示异步超时的时间 -### 流程可视化 - -#### PlantUML可视化展示 -smart-flow内嵌plantuml图像生成处理器,通过使用`PlantumlEngineVisitor`访问生成的`FlowEngine`实例, -在项目指定位置生成plantuml文件,例如以下示例,将在项目根目录下生成名为`engine-flow`的文件 -```Java -// Generate plantuml file named 'engine-flow' -PlantumlEngineVisitor plantumlEngineVisitor = new PlantumlEngineVisitor("engine-flow"); -// engine :需要生成流程图的流程实例 -plantumlEngineVisitor.visit(engine); -``` - -效果如下图(可在编译器中安装PlantUML插件进行查看): - - -![img.png](doc/engine-flow.png) - -如果想要生成其他形式图片,可以实现`EngineVisitor`, 对`FlowEngine`进行结构遍历,然后通过遍历得到的数据生成图片/文件 -- Gitee From 4857d1d18d8c951abc2d5f0459bda170009fa91a Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 30 Nov 2022 23:49:07 +0800 Subject: [PATCH 12/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e8dfc6f..33d3567 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ String result = context.getResult(); ## Executable 组件 -`Executable`是smart-flow中唯一面向开发者的组件,用户需要使用该接口进行业务逻辑的开发。 +`Executable`是smart-flow中面向开发者的组件,用户需要使用该接口进行业务逻辑的开发。 为了方便用户使用,smart-flow提供了抽象实现`AbstractExecutable`, 用户可以继承`AbstractExecutable` 实现`execute`方法进行快速开发。 @@ -157,7 +157,7 @@ Component component = ExecutableBuiler.newBuil ``` #### IF组件构造 -smart-flow中表示IF组件构造的是`IfComponentBuilder`, smart-flow中if分支选择支持指定then/else +smart-flow中表示IF组件构造的是`IfComponentBuilder`, smart-flow中if分支选择支持then/else * `then(Component)` 只有then,没有else @@ -199,7 +199,7 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); ## **组件回滚** -smart-flow中所有组件默认都是不可回滚的,需要使用者手动配置回滚属性。 回滚属性rollback=true, +smart-flow中所有组件默认都是不可回滚的,需要使用者手动配置回滚属性rollback=true, 在流程引擎执行失败或者手动设置回滚后,将按照已执行组件的执行顺序逆序执行回滚方法。 * builder设置回滚属性 ```java @@ -211,8 +211,8 @@ builder.apply(Attributes.ROLLBACK, true); ``` -关于回滚方法定义,请参考`org.smartboot.flow.core.Rollback`, 同时`Executable`接口继承于`Rollback`, -而为了方便使用,`AbstractExecutable`对相关rollback方法进行了空实现,业务上想要实现业务回滚覆盖相应的方法即可。 +关于回滚方法定义,请参考`org.smartboot.flow.core.Rollback`。 `Executable`接口继承于`Rollback`, +而为了方便使用,`AbstractExecutable`对rollback方法进行了空实现,如果想要实现业务回滚覆盖相应的方法即可。 需要注意的是, 回滚组件会在以下几种场景下失效: * 该组件还未执行到,流程便终止了 @@ -221,7 +221,7 @@ builder.apply(Attributes.ROLLBACK, true); ## **组件降级与回调** ### 组件降级 -smart-flow中所有组件默认都是不可降级的,需要使用者手动配置可降级属性degradable=true, +smart-flow中所有组件默认都是不可降级的,需要使用者手动配置属性degradable=true, 在流程引擎执行失败后,如果组件是可降级组件,将不会中断流程,而是会继续往下执行。 * builder设置属性 ```java @@ -233,6 +233,7 @@ builder.apply(Attributes.DEGRADABLE, true); ``` + ### 降级回调 降级回调仅对基本组件生效,在基本组件的`Executable`执行失败后,如果当前组件设置了degradable=true,将触发降级回调。 降级回调接口参照`org.smartboot.flow.core.DegradeCallback`。 @@ -247,6 +248,10 @@ builder.apply(Attributes.DEGRADE_CALLBACK, "degrade-callback classname or object ``` +为了便于使用,如果基本组件的`Executable`对象同时也是`DegradeCallback`的子类,那么`Executable`也将被当作降级回调对象触发降级回调, +但显示指定降级回调对象的回调优先级大于`Executable` + + ## 组件异步 smart-flow支持组件异步执行,只需要进行2步即可开启异步执行。 @@ -270,8 +275,9 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); ``` ## 优雅中断流程 -smart-flow在发生异常时,会对流程进行终止,并对已执行组件进行回滚。 相比这种异常中断的方式而言,smart-flow提供了一种更优雅的中断方式。 -使用者可以通过执行上文手动终止/回滚流程。 +smart-flow默认发生异常时,会对流程进行终止,并对已执行组件进行回滚。 如果业务上想要中断流程,只能以异常的形式进行中断,但这可能会触发回滚 +相比这种异常中断的方式而言,smart-flow提供了一种更优雅的中断方式。 +使用者可以通过执行上下文对象手动终止/回滚流程。 ```java public class Step1 extends AbstractExecutable { -- Gitee From 2534b223384bd783c96103312c3addcd184f0eeb Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 1 Dec 2022 15:41:53 +0800 Subject: [PATCH 13/54] qinluo: - qlexpress - readme --- README.md | 386 ++++++++++++++++-- .../src/main/resources/flow-example7.xsd | 2 +- smart-flow-script-condition/pom.xml | 1 + .../smart-flow-script-qlexpress/pom.xml | 27 ++ .../qlexpress/QlExpressScriptCondition.java | 47 +++ .../main/resources/META-INF/smart-flow-script | 1 + 6 files changed, 437 insertions(+), 27 deletions(-) create mode 100644 smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml create mode 100644 smart-flow-script-condition/smart-flow-script-qlexpress/src/main/java/org/smartboot/flow/condition/extension/qlexpress/QlExpressScriptCondition.java create mode 100644 smart-flow-script-condition/smart-flow-script-qlexpress/src/main/resources/META-INF/smart-flow-script diff --git a/README.md b/README.md index 33d3567..c75afa3 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 # 功能特性 + + ## 核心功能 - [X] 支持基于Java代码或者XML配置的线性流程编排 - [X] 支持IF、CHOOSE条件分支 @@ -27,11 +29,15 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [X] 支持组件失败回滚 - [X] 支持查看调用路径 + + ## 高级功能 - [X] 支持Spring环境XML配置集成 - [X] 支持实时生成流程引擎结构图 - [X] 支持多种条件表达式(Groovy、OGNL、JavaScript等) + + ## 管理功能 - [X] 支持自定义执行数据采集 - [X] 支持HTTP方式引擎数据上报(包含执行数据) @@ -40,8 +46,12 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [ ] 支持引擎Reload + + # 快速接入 + + ## 依赖引入 smart-flow暂未发布至maven仓库,使用者需要手动将工程克隆至本地进行安装 @@ -61,6 +71,8 @@ mvn clean install ``` + + ## 实现Executable 实现`Executable`接口,或者继承`AbstractExecutable`, 实现`execute`方法 ```java @@ -81,6 +93,8 @@ public void execute(EngineContext context) { } ``` + + ## 编码方式编排业务流程 smart-flow支持`Builder`风格的流程引擎编排,例如如下示例: ```java @@ -96,6 +110,8 @@ builder.pipeline(new PipelineBuilder<>("main process") FlowEngine engine = builder.build(); ``` + + ## 流程引擎执行 流程引擎执行必须执行参数(参数可以为空),同时对于返回值可以在调用入口指定,也可以在流程引擎内部的组件指定。 ```java @@ -113,8 +129,12 @@ String result = context.getResult(); ``` + + # 核心功能介绍 + + ## Executable 组件 `Executable`是smart-flow中面向开发者的组件,用户需要使用该接口进行业务逻辑的开发。 @@ -124,6 +144,8 @@ String result = context.getResult(); Tip: 为了后续流程维护,推荐覆盖`describe()`方法,返回当前组件的信息。 + + ## 基于Java Builder的流程编排方式 smart-flow提供了基于`Builder`风格的流程编排方式,用户可以使用相应的Builder快速对流程进行编排。 以下为smart-flow提供的Builder列表: @@ -131,6 +153,8 @@ smart-flow提供了基于`Builder`风格的流程编排方式,用户可以使 * 流水线构造 * 组件构造 + + ### 流程引擎构造 smart-flow中负责流程引擎构造的Builder类是`EngineBuilder`, `EngineBuilder`接受一个name作为构造入参, 对于`EngineBuilder`以下几个参数是必须的: @@ -138,6 +162,8 @@ smart-flow中负责流程引擎构造的Builder类是`EngineBuilder`, `EngineBui * pipeline 流水线作为流程引擎的执行构建,也是必须的 * executor 仅当流程中含有异步组件时必须指定 + + ### 流水线构造 smart-flow中负责流程引擎构造的Builder类是`PipelineBuilder`, `PipelineBuilder`与`EngineBuilder`类似,必须为其指定名字, 对于该Builder方法介绍如下: @@ -148,14 +174,20 @@ smart-flow中负责流程引擎构造的Builder类是`PipelineBuilder`, `Pipelin 需要注意的是,如果通过`PipelineBuilder`产生的子流程需要作用到父流程,需要调用`end()`方法而不是`build()`方法。 + + ### 组件构造 + + #### 普通组件构造 smart-flow中表示基本组件构造的是`ExecutableBuilder`, 该组件接受一个`Executable`实例,返回一个普通组件对象。 ```JAVA Component component = ExecutableBuiler.newBuilder().newAdapter(new ExampleExecutable()); ``` + + #### IF组件构造 smart-flow中表示IF组件构造的是`IfComponentBuilder`, smart-flow中if分支选择支持then/else * `then(Component)` @@ -169,6 +201,8 @@ smart-flow中表示IF组件构造的是`IfComponentBuilder`, smart-flow中if分 * `then(Executable)` * `then(Executable, Executable)` + + #### CHOOSE组件构造 smart-flow中表示IF组件构造的是`ChooseBuilder`, smart-flow中choose分支选择支持指定case和default,等价于Java中的switch语句。 * `newBranch(Object, Component)` @@ -182,9 +216,13 @@ smart-flow中表示IF组件构造的是`ChooseBuilder`, smart-flow中choose分 结束当前choose分支构造, 分支的默认逻辑为end方法的参数,并且将构造完成的choose组件放置到pipeline中 + + #### 子流程的嵌套 可以通过`PipelineBuilder`的build方法,产生一个包含子流程的组件 + + #### 属性设置 相关组件Builder提供了以下方法,用于设置组件的属性。smart-flow会基于为组件设置的属性进行相关的操作,例如降级、回滚等操作。 ```JAVA @@ -195,9 +233,188 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); 需要注意的是,部分属性对于IF、CHOOSE、子流程组件可能不会生效, 例如`rollback`, 这是因为他们属于包装类型的组件,是否需要回滚取决于真实组件的属性。 + + ## 基于XML的编排方式 + +### 引入xsd约束 +为了在使用xml方式编排时有相应提示,smart-flow提供了基于xsd格式的约束,开发者可以参考以下的示例进行引入 +```xml + + + +``` +* http://org.smartboot/smart-flow http://org.smartboot/smart-flow-1.0.1.xsd +* xml的root元素必须engines + + + +### xsd各项标签介绍 +* engines 根元素,所有的标签必须在engines标签内部 +* engine 定义一个engine +* pipeline 定义一个流水线 +* if 新增一个分支 +* choose 新增choose分支 +* script 新增条件表达式 +* component 新增一个普通组件 + + + +### 标签约束 + + + +#### engines标签 +engines标签下只能存在engine、pipeline、以及script标签 + + + +#### engine标签 +engine标签下不能含有子标签,且必须为其指定属性: +* name 表示引擎的名称 +* pipeline 引擎包含流水线的名称 + +示例: +```xml + +``` + + + +#### pipeline标签 +pipeline标签用于定义一条流水线,必须为其指定: +* name 表示引擎的名称,且不存存在重复的流水线 +* 至少2个以及以上的子标签 + +pipeline支持的子标签列表: +* pipeline 用于嵌套子流程 +* if 新增if分支处理 +* choose 新增choose分支处理 +* component 新增普通步骤 + + + +#### component标签 +component标签用于定义一个基本组件或者嵌套子流程,component标签支持以下属性设置 +* subprocess 用来嵌套一个子流程,subprocess的值为嵌套子流程的名称 +* execute 可执行器的class类名 + +同时为component设置subprocess和execute,优先识别subprocess。 + +例如以下例子component将被解析为嵌套子流程组件,组件包含的pipeline为subprocess#2: +```xml + +``` + + + +#### if标签 +if标签用于定义if条件分支,以下设置对于if标签是必须的: +* test 指定条件class或者是一个script标签的名字 +* 必须含有then标签,但else标签不是必须的 +* then和else标签最多出现一次 + +then/else标签类似于component标签和pipeline标签,开发者可以通过属性指定属性`execute`的值为可执行器的类名, +也可以在then/else标签下面嵌套pipeline、if、choose等标签。 + +但如果同时为then/else指定execute属性和子标签,smart-flow将优先以execute的情况进行解析 + +以下为示例: +```xml + + + + + + + + + + + +``` + + + +#### choose标签 +choose标签用于定义choose条件分支,choose标签的约束与if标签是类型的: +* test 指定条件class或者是一个script标签的名字 +* case标签必须出现2次以及以上,default标签最多存在一次 + +case/default标签约束与if中then/else标签一致,区别在于case标签还必须额外指定属性`when`, +表示什么情况下选择当前分支。 + +以下为示例: +```xml + + + + + + + + +``` + + + +#### script标签 +script标签用于定义条件表达式,if/choose标签的`test`属性可以指定为script的名字,script标签以下属性是必须的 +* name 唯一标识script,同时也是if/choose标签引用的依据 +* type 指定script脚本类型,type的值支持class和短名称,class优先级 > 短名称 + * class必须为ScriptCondition类的一个子类 + * 短名称,现支持短名称列表:OGNL、Groovy、JavaScript、qlExpress +* 必须为script指定脚本,script中几个默认参数为: + * request 业务请求入参 + * result 业务请求出参 + * context smart-flow流程引擎执行上下文 + +以下为相关示例: +```xml + + var local = 2; + local == request; + +``` + + + +### 为标签设置属性 +与builder方式类似,你可以通过直接在component、if、then等标签上指定属性名进行属性的设置, +smart-flow会识别提取在`Attributes`中定义的属性,并将他们设置到组件上去。 + + + +### Xml的解析 +smart-flow提供默认的Parser解析`DefaultParser`,`DefaultParser`接受一串流或者一串文件作为解析参数,同时提供解析结果的获取。 +* `getEngineNames` 获取当前解析到的engine名称列表 +* `getEngines` 获取当前解析得到的所有engines,返回值为map,key为engine名称,value为engine实例 +* `getEngine(String)` 获取名为参数的engine + +以下为使用示例: +```java +DefaultParser parser = new DefaultParser(); +parser.parse(this.getClass().getResourceAsStream("/flow-example7.xsd")); +LOGGER.info("parsed engines {}", parser.getEngineNames()); + +FlowEngine testEngine = parser.getEngine("testEngine"); +EngineContext execute = testEngine.execute(1); +LOGGER.info("trace \n{}", execute.getTrace()); +``` + + + +### 完整xml示例 +参考文件 [flow-example7.xsd](https://gitee.com/smartboot/smart-flow/blob/master/smart-flow-example/src/main/resources/flow-example7.xsd) + + + + ## **组件回滚** smart-flow中所有组件默认都是不可回滚的,需要使用者手动配置回滚属性rollback=true, 在流程引擎执行失败或者手动设置回滚后,将按照已执行组件的执行顺序逆序执行回滚方法。 @@ -218,8 +435,12 @@ builder.apply(Attributes.ROLLBACK, true); * 该组件还未执行到,流程便终止了 * 该组件同时是可降级组件,且降级后的后续组件并未发生异常,正常执行完毕 + + ## **组件降级与回调** + + ### 组件降级 smart-flow中所有组件默认都是不可降级的,需要使用者手动配置属性degradable=true, 在流程引擎执行失败后,如果组件是可降级组件,将不会中断流程,而是会继续往下执行。 @@ -234,6 +455,7 @@ builder.apply(Attributes.DEGRADABLE, true); ``` + ### 降级回调 降级回调仅对基本组件生效,在基本组件的`Executable`执行失败后,如果当前组件设置了degradable=true,将触发降级回调。 降级回调接口参照`org.smartboot.flow.core.DegradeCallback`。 @@ -252,6 +474,8 @@ builder.apply(Attributes.DEGRADE_CALLBACK, "degrade-callback classname or object 但显示指定降级回调对象的回调优先级大于`Executable` + + ## 组件异步 smart-flow支持组件异步执行,只需要进行2步即可开启异步执行。 @@ -274,6 +498,8 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); ``` + + ## 优雅中断流程 smart-flow默认发生异常时,会对流程进行终止,并对已执行组件进行回滚。 如果业务上想要中断流程,只能以异常的形式进行中断,但这可能会触发回滚 相比这种异常中断的方式而言,smart-flow提供了一种更优雅的中断方式。 @@ -289,6 +515,8 @@ public class Step1 extends AbstractExecutable { } ``` + + ## 组件静默 smart-flow中所有组件默认都是开启可执行状态,如果需要跳过某个组件的执行,可以通过设置属性enabled=false进行跳过 * builder设置属性 @@ -301,8 +529,12 @@ builder.apply(Attributes.ENABLED, false); ``` + + ## 组件适配 + + ## 查看组件执行路径 smart-flow默认提供执行路径日志, 在一次执行完毕后,可以通过`context.getTrace()`获取本次调用路径日志, 能够帮助开发者更加清晰的了解调用过程。具体使用以及效果如下: @@ -349,8 +581,123 @@ flow-engine##defaultEngine escaped 310ms ``` + + # 高级功能介绍 + + +## 条件表达式 +smart-flow中表达条件表达式的类为抽象类`ScriptCondition`,您可以在xml编排中使用script标签来定义一个条件表达式。 +smart-flow中默认提供了常用条件表达式的实现,您只需要在script标签的type属性指定相应的短语即可(需要引入相关依赖)。 +* OGNL 条件表达式为ognl +```xml + + org.smartboot + smart-flow-script-ognl + 1.0.2 + +``` + +* groovy 条件表达式为groovy脚本 +* javascript 条件表达式为javascript + +groovy与javascript使用相同的依赖 +```xml + + org.smartboot + smart-flow-script-groovy + 1.0.2 + +``` + +* qlexpress 条件表达式为qlexpress脚本 + +```xml + + org.smartboot + smart-flow-script-qlexpress + 1.0.2 + +``` +为了方便使用,当使用短语时,您可以不必区分大小写,例如Groovy与GROOVY、groovy都是等价的。 + + + + +### 接入新的条件表达式 +接入新的条件表达式仅需实现抽象类`ScriptCondition`即可,如果想要在smart-flow使用短语来识别新的条件表达式实例, +也只需要在类路径下META-INF下新增名为smart-flow-script的文件,文件的内容为kv键值对,key为短语,v为相应的类名,示例如下: +```text +groovy=org.smartboot.flow.condition.extension.groovy.GroovyScriptCondition +javascript=org.smartboot.flow.condition.extension.groovy.JavaScriptCondition +``` + + + + + +## 与Spring集成 + + + + +### 依赖引入 +如果想要在spring环境下使用smart-flow,需要引入依赖 +```xml + + org.smartboot + smart-flow-spring-extension + 1.0.2 + +``` + + + +### XML编排方式的改变 +与独立使用smart-flow不同,在spring环境中嵌套smart-flow的标签并不需要所有标签都在engines下, +只需要在相关bean文件中引入xsd约束即可开启使用 +```xml + + + +``` + + + + +#### 普通组件标签的改变 +if、choose、component、then等组件在单独使用时需要单独指定classname,但在spring环境中,可以替换为bean的名称。 +但请保证相关bean的类型是正确的,即: +* test属性指向的bean必须为Condition的子类 +* execute属性指向的bean必须为Executable的子类 + +但在spring环境下,您仍可以指定classname。 + + + + +#### script标签的改变 +script标签的改变在于type不再是必须的,但必须遵循以下规则: +* script的name属性必须为已存在的bean名称 +* script的name属性指向的bean必须为ScriptCondition的一个子类 + +在这种情况下,smart-flow会自动为name指向的bean设置script脚本。 + + + + +### spring bean完整示例 +完整示例请参照文件[bean.xml](https://gitee.com/smartboot/smart-flow/blob/master/smart-flow-example/src/main/resources/bean.xml) + + + ## 实时生成流程引擎结构图 smart-flow内嵌plantuml图像生成处理器,通过使用`PlantumlEngineVisitor`访问生成的`FlowEngine`实例, 在项目指定位置生成plantuml文件,例如以下示例,将在项目根目录下生成名为`engine-flow`的文件 @@ -369,8 +716,14 @@ plantumlEngineVisitor.visit(engine); 如果想要生成其他形式图片,可以实现`EngineVisitor`, 对`FlowEngine`进行结构遍历,然后通过遍历得到的数据生成图片/文件 + + + + # 管理功能 + + ## 组件管理接口 smart-flow中的每一个`FlowEngine`实例默认都会加入`EngineManager`的管理, 用户可以通过使用`DefaultEngineManager`查看指定名称的engine组件数据,并动态地修改组件属性。 @@ -410,37 +763,18 @@ identifier defaultEngine-DefaultPipeline-step5-5tqygjpx ``` -#### xml配置项说明 - 相关xml标签的使用简介如下: +## 引擎数据上报 + + + +## 组件管理 + -- engines smart-flow以单独的xml形式进行编排时,engines标签必须为Root标签, engines标签下允许出现engine、pipeline以及component标签 -- engine engine标签定义一个流程引擎,必须为engine标签指定name和pipeline属性,其中pipeline属性表示某个pipeline的名称 -- component 可以使用component定义一个组件,使用component标签必须指定type或者ref、subprocess其中任意一个属性,他们优先级从高到低如下 - - type表示一个`Executable`的实现全称限定类名 - - ref表示一个`Executable`的bean名称,仅在spring环境下生效 - - subprocess表示一个pipeline,它的值为pipeline的名称 -- pipeline 可以使用pipeline定义一条流程,其中name属性是必须的,pipeline下允许存在以下标签 - - pipeline, 用户可以在pipeline下使用pipeline来定义一条匿名子流程,在这种情况下,name不是必须的 - - component 定义一个组件或者引用一条子流程,引用子流程的情况下与使用pipeline是等价的 - - if 定义一个if分支选择 - - choose 定义一个switch分支选择 -- if 等同于Java中的if条件,其中test属性是必须的 - - test表示一个`Condition`的子类的全程限定类名 - - ref属性,在spring环境下,可以不指定test属性,但必须指定ref属性,ref的值表示一个`Condition`的子类bean - - 子标签then和else表示分支处理,其中then是必须的,then和else使用类似与Component,但它们也支持像pipeline一样直接定义子流程 -- choose 等于Java中的switch语句块 - - 条件和属性与if一致 - - 子标签case和default, 其中case是必须的,且必须出现2次以及2次以上,case和default的行为与then和else一致 -其他: if、choose、else、then、case、 default、component支持定义任意属性,其中能够被smart-flow识别的属性将会被设置到组件上去,例如: -- name string类型 表示名称 -- rollback boolean类型 表示是否可回滚 -- degradable boolean类型 表示是否可降级 -- async boolean类型,表示是否可异步 -- timeout number类型,表示异步超时的时间 +## reload机制 diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd index e62424f..ecb79d1 100644 --- a/smart-flow-example/src/main/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -8,7 +8,7 @@ - + diff --git a/smart-flow-script-condition/pom.xml b/smart-flow-script-condition/pom.xml index dff0dd7..0514d75 100644 --- a/smart-flow-script-condition/pom.xml +++ b/smart-flow-script-condition/pom.xml @@ -13,6 +13,7 @@ smart-flow-script-ognl smart-flow-script-groovy + smart-flow-script-qlexpress smart-flow-script-condition diff --git a/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml b/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml new file mode 100644 index 0000000..6417326 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml @@ -0,0 +1,27 @@ + + + + smart-flow-script-condition + org.smartboot + 1.0.2 + + 4.0.0 + + smart-flow-script-qlexpress + + + 8 + 8 + + + + + + com.alibaba + QLExpress + 3.3.0 + + + \ No newline at end of file diff --git a/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/java/org/smartboot/flow/condition/extension/qlexpress/QlExpressScriptCondition.java b/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/java/org/smartboot/flow/condition/extension/qlexpress/QlExpressScriptCondition.java new file mode 100644 index 0000000..4623cc4 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/java/org/smartboot/flow/condition/extension/qlexpress/QlExpressScriptCondition.java @@ -0,0 +1,47 @@ +package org.smartboot.flow.condition.extension.qlexpress; + +import com.ql.util.express.DefaultContext; +import com.ql.util.express.ExpressRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.script.ScriptCondition; +import org.smartboot.flow.core.script.ScriptConstants; + +/** + * @author qinluo + * @date 2022/11/29 21:01 + * @since 1.0.0 + */ +public class QlExpressScriptCondition extends ScriptCondition { + + private static final Logger LOGGER = LoggerFactory.getLogger(QlExpressScriptCondition.class); + + @Override + public Object test(EngineContext engineContext) { + try { + + DefaultContext qlContext = new DefaultContext<>(); + qlContext.put(ScriptConstants.REQ, engineContext.getReq()); + qlContext.put(ScriptConstants.RESULT, engineContext.getResult()); + qlContext.put(ScriptConstants.CONTEXT, engineContext); + + ExpressRunner runner = new ExpressRunner(); + Object value = runner.execute(script, qlContext, null, true, false); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("evaluate script [{}] finished", script); + LOGGER.debug("evaluate value {}", value); + } + + return value; + } catch (Exception e) { + throw new FlowException("Ognl evaluate failed, script : " + script, e); + } + } + + @Override + public String getType() { + return "qlexpress"; + } +} diff --git a/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/resources/META-INF/smart-flow-script b/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/resources/META-INF/smart-flow-script new file mode 100644 index 0000000..ec9ffd1 --- /dev/null +++ b/smart-flow-script-condition/smart-flow-script-qlexpress/src/main/resources/META-INF/smart-flow-script @@ -0,0 +1 @@ +qlexpress=org.smartboot.flow.condition.extension.qlexpress.QlExpressScriptCondition \ No newline at end of file -- Gitee From 743a150713f186c73357e52e8129222321bb9909 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 1 Dec 2022 21:27:49 +0800 Subject: [PATCH 14/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c75afa3..e1e5546 100644 --- a/README.md +++ b/README.md @@ -425,7 +425,7 @@ builder.apply(Attributes.ROLLBACK, true); * XML方式设置回滚属性 ```xml - + ``` 关于回滚方法定义,请参考`org.smartboot.flow.core.Rollback`。 `Executable`接口继承于`Rollback`, @@ -451,7 +451,7 @@ builder.apply(Attributes.DEGRADABLE, true); * XML方式设置属性 ```xml - + ``` @@ -467,7 +467,7 @@ builder.apply(Attributes.DEGRADE_CALLBACK, "degrade-callback classname or object * XML方式设置属性 ```xml - + ``` 为了便于使用,如果基本组件的`Executable`对象同时也是`DegradeCallback`的子类,那么`Executable`也将被当作降级回调对象触发降级回调, @@ -489,13 +489,13 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); ``` 若使用XML方式进行编排,只需为组件添加2个属性即可 ```xml - + ``` 异步组件可与dependsOn结合使用,若组件1和组件2异步调用,组件3需要等待组件1和组件2执行完毕,那么可以为组件3设置dependsOn属性 ```xml - + ``` @@ -526,7 +526,7 @@ builder.apply(Attributes.ENABLED, false); * XML方式设置属性 ```xml - + ``` -- Gitee From a12b7f12b1c50a3b4873acd86be9203d378ffede Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 3 Dec 2022 23:44:56 +0800 Subject: [PATCH 15/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20readme=20=20?= =?UTF-8?q?=20=20=20=20-=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 98 +- doc/report.json | 948 ++++++++++++++++++ pom.xml | 1 - smart-flow-core/pom.xml | 9 +- .../smartboot/flow/core/EngineContext.java | 6 +- .../flow/core/ExecutionListener.java | 3 + .../flow/core/ExecutionListenerSupport.java | 10 + .../flow/core/ExecutionListeners.java | 22 + .../org/smartboot/flow/core/FlowEngine.java | 19 +- .../flow/core/attribute/Attributes.java | 6 - .../flow/core/common/ComponentType.java | 1 - ...port.java => DefaultExceptionHandler.java} | 4 +- .../flow/core/exception/FlowException.java | 7 - .../flow/core/manager/ComponentModel.java | 9 +- .../core/metrics/MetricExecutionListener.java | 17 +- .../flow/core/metrics/MetricKind.java | 1 - .../flow/core/metrics/NamedMetrics.java | 17 + .../flow/core/parser/ParseConstants.java | 2 - .../src/main/resources/bean.xml | 2 +- .../src/main/resources/log4j.properties | 2 +- .../org/smartboot/flow/example/ParseTest.java | 4 +- smart-flow-manager/pom.xml | 2 +- .../flow/manager/change/HttpManager.java | 8 +- .../flow/manager/report/HttpReporter.java | 7 +- 24 files changed, 1145 insertions(+), 60 deletions(-) create mode 100644 doc/report.json rename smart-flow-core/src/main/java/org/smartboot/flow/core/exception/{ExceptionHandlerSupport.java => DefaultExceptionHandler.java} (72%) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/NamedMetrics.java diff --git a/README.md b/README.md index e1e5546..465165a 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ smart-flow暂未发布至maven仓库,使用者需要手动将工程克隆至 ```shell git clone https://gitee.com/smartboot/smart-flow.git cd smart-flow -mvn clean install +mvn -DskipTests=true clean install ``` 安装完毕后在项目中进行引入 `lastest.version` = 1.0.2 @@ -248,7 +248,7 @@ builder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000); xsi:schemaLocation="http://org.smartboot/smart-flow http://org.smartboot/smart-flow-1.0.1.xsd"> -``` +``` * http://org.smartboot/smart-flow http://org.smartboot/smart-flow-1.0.1.xsd * xml的root元素必须engines @@ -725,7 +725,7 @@ plantumlEngineVisitor.visit(engine); ## 组件管理接口 -smart-flow中的每一个`FlowEngine`实例默认都会加入`EngineManager`的管理, +smart-flow中的每个`FlowEngine`实例默认都会加入`EngineManager`的管理, 用户可以通过使用`DefaultEngineManager`查看指定名称的engine组件数据,并动态地修改组件属性。 例如以下例子,动态禁用某个组件: @@ -753,29 +753,111 @@ LOGGER.info("trace {}", context.getTrace()); ``` -注意:由于组件的名称并不是必须的,所有组件的identifier是由`EngineManager`动态生成, -但组件的名称也会是identifier的一部分构成,所以建议所有组件都指定名称。 以下为指定与不指定的对比: +注意:组件的名称并不是必须的,但组件的名称也会是identifier的一部分构成,如果没有指定名字,将会以NULL代替, +为了便于管理,建议所有组件都指定名称。 以下为指定与不指定的对比: ```TEXT 不指定 -defaultEngine-subprocess##2-none-qiewmdn4 +defaultEngine-subprocess##2-null 指定为step5 -identifier defaultEngine-DefaultPipeline-step5-5tqygjpx +identifier defaultEngine-DefaultPipeline-step5 +``` + + +TIP: +> EngineManager生成组件、流水线的唯一标识Identifier基于父组件名称,例如名为testEngine的引擎下组件和流水线的Identifier都将以 +> testEngine开头。同时smart-flow为了能在分布式环境下唯一确定一个组件,生成的Identifier并不包含随机因素,所以请保证组件名称不会有重复。 + + +## 自定义数据采集 +smart-flow提供了Listener机制,可以在流程引擎组件执行前后、回滚前后进行相应操作,例如统计执行时间、执行次数等操作。 + +```java +public interface ExecutionListener { + + void start(EngineContext context); + void completed(EngineContext context); + void beforeExecute(EngineContext context, Object object); + void afterExecute(EngineContext context, Object object); + void beforeRollback(EngineContext context, Object object); + void afterRollback(EngineContext context, Object object); +} + ``` +* context +> 当前上下文信息 + +* object +> 当前执行对象,可能是Engine、Pipeline、Component中的任何一个 + + +默认自带数据采集Listener `org.smartboot.flow.core.metrics.MetricExecutionListener`。 +您也可以自定义采集,例如需要以业务线维度进行采集,可以通过context识别到具体业务,然后设置统计模型创建器 +```java +MetricsManager.setMetricsCreator(new CustomMetricsCreator()); +``` ## 引擎数据上报 +smart-flow默认提供了基于smart-http的上报组件,默认会以引擎维度上报引擎的结构以及统计数据相关信息。 +```xml + + + + + +``` +例如以上示例,会将数据上报至指定链接,5s上报一次。上报数据结构见示例[http上报数据示例](https://gitee.com/smartboot/smart-flow/blob/master/doc/report.json) +当然您也可以通过组件管理接口获取数据,自定义上报数据。 ## 组件管理 +smart-flow默认提供了基于smart-http拉模式的http管理器,可以定时从服务器拉取相关操作指令,对引擎数据进行调整。 + +例如以下示例:每隔5s请求远程链接获取指令 +```xml + + + + + + +``` + +### 请求参数模型 +```json +{ + "address": "localhost", + "ip": "127.0.0.1", + "timestamp": 1669960706283, + "engineNames": ["testEngine"] +} + +``` +### 返回指令模型 +例如以下指令:将组件step5禁用(enabled=false) +```json +[ + { + "action": "CHANGE_ATTRIBUTES", + "timestamp": 1669960706283, + "identifier": "defaultEngine-DefaultPipeline-step5", + "value": "false", + "name": "enabled" + } +] +``` +* timestamp是必须的,默认不会执行小于请求timestamp的指令 +* identifier是必须的,用于确定组件/引擎 +* action是必须的,用于确定操作类型,具体见[ManagerAction](https://gitee.com/smartboot/smart-flow/blob/master/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java) +* name和value,变更组件属性CHANGE_ATTRIBUTES必须的 ## reload机制 - diff --git a/doc/report.json b/doc/report.json new file mode 100644 index 0000000..f66eda1 --- /dev/null +++ b/doc/report.json @@ -0,0 +1,948 @@ +{ + "address":"192.168.102.79", + "data":{ + "identifier":"testEngine", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":742 + }, + "execute-total":{ + "value":975 + }, + "execute-count":{ + "value":3 + } + } + }, + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step1", + "executable":"org.smartboot.flow.example.Step1", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step1", + "degradable":"true", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-step1", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step1", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step2", + "executable":"org.smartboot.flow.example.Step2", + "holders":{ + "rollback":"true", + "async":"false", + "name":"step2", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-step2", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step2", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"example-callback", + "executable":"example-callback", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step112", + "degradable":"true", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-step112", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":1 + }, + "execute-total":{ + "value":1 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step112", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"pipeline@subprocess9", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess9", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-subprocess9", + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.AsyncStep1", + "executable":"org.smartboot.flow.example.AsyncStep1", + "holders":{ + "rollback":"true", + "async":"false", + "name":"step100", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess9-subprocess9-step100", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step100", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.AsyncStep2", + "executable":"org.smartboot.flow.example.AsyncStep2", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step102", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess9-subprocess9-step102", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":102 + }, + "execute-total":{ + "value":303 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step102", + "type":"BASIC" + } + ], + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess9-subprocess9", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":103 + }, + "execute-total":{ + "value":304 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"subprocess9" + }, + "type":"PIPELINE" + }, + { + "components":{ + + }, + "describe":"pipeline@subprocess2", + "holders":{ + + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess2", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-subprocess2", + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step3", + "executable":"org.smartboot.flow.example.Step3", + "holders":{ + "rollback":"true", + "async":"false", + "name":"step3", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess2-subprocess2-step3", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step3", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step4", + "executable":"org.smartboot.flow.example.Step4", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step4", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess2-subprocess2-step4", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"step4", + "type":"BASIC" + } + ], + "identifier":"testEngine-subprocess1-anonymous-pipeline-wrapper-subprocess2-subprocess2", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"subprocess2" + }, + "type":"PIPELINE" + }, + { + "components":{ + "else":{ + "components":{ + + }, + "describe":"org.smartboot.flow.example.DefaultStep", + "executable":"org.smartboot.flow.example.DefaultStep", + "holders":{ + "rollback":"false", + "async":"false", + "name":"default", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-default", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":2 + } + } + }, + "name":"default", + "type":"BASIC" + }, + "then":{ + "components":{ + + }, + "describe":"pipeline@anonymous-pipeline-6", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-7", + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step5", + "executable":"org.smartboot.flow.example.Step5", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step5", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-step5", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step5", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step6", + "executable":"org.smartboot.flow.example.Step6", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step6", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-step6", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step6", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"pipeline@subprocess3", + "holders":{ + + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-anonymous-pipeline-wrapper-subprocess3", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-subprocess3", + "pipeline":{ + "components":[ + { + "components":{ + "then":{ + "components":{ + + }, + "describe":"org.smartboot.flow.example.AsyncStep1", + "executable":"org.smartboot.flow.example.AsyncStep1", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step7", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-anonymous-pipeline-wrapper-subprocess3-subprocess3-anonymous-if-step7", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step7", + "type":"BASIC" + } + }, + "condition":"org.smartboot.flow.example.IfCondition2", + "describe":"if@org.smartboot.flow.example.IfCondition2", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-anonymous-pipeline-wrapper-subprocess3-subprocess3-anonymous-if", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"anonymous-if", + "type":"IF" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.AsyncStep2", + "executable":"org.smartboot.flow.example.AsyncStep2", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step8", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-anonymous-pipeline-wrapper-subprocess3-subprocess3-step8", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":103 + }, + "execute-total":{ + "value":103 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step8", + "type":"BASIC" + } + ], + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6-anonymous-pipeline-wrapper-subprocess3-subprocess3", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":103 + }, + "execute-total":{ + "value":103 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"subprocess3" + }, + "type":"PIPELINE" + } + ], + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-7-anonymous-pipeline-6", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":103 + }, + "execute-total":{ + "value":103 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"anonymous-pipeline-6" + }, + "type":"PIPELINE" + } + }, + "condition":"org.smartboot.flow.example.IfCondition", + "describe":"if@org.smartboot.flow.example.IfCondition", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":103 + }, + "execute-total":{ + "value":103 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"anonymous-if", + "type":"IF" + }, + { + "components":{ + "1":{ + "branch":"1", + "components":{ + + }, + "describe":"pipeline@anonymous-pipeline-14", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-choose-branch-1", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-15", + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.IntegerStep", + "executable":"org.smartboot.flow.example.IntegerStep", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step9", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-choose-branch-1-anonymous-pipeline-14-step9", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step9", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.AsyncStep3", + "executable":"org.smartboot.flow.example.AsyncStep3", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step10", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-choose-branch-1-anonymous-pipeline-14-step10", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":204 + }, + "execute-total":{ + "value":204 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step10", + "type":"BASIC" + } + ], + "identifier":"testEngine-subprocess1-anonymous-choose-branch-1-anonymous-pipeline-14", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":204 + }, + "execute-total":{ + "value":204 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"anonymous-pipeline-14" + }, + "type":"PIPELINE" + }, + "default":{ + "branch":"default", + "components":{ + + }, + "describe":"org.smartboot.flow.example.DefaultStep", + "executable":"org.smartboot.flow.example.DefaultStep", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-choose-default", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"", + "type":"BASIC" + }, + "null":{ + "branch":"null", + "components":{ + + }, + "describe":"org.smartboot.flow.example.NullStep", + "executable":"org.smartboot.flow.example.NullStep", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"true", + "enabled":"true", + "timeout":"0", + "degrade-callback":"exampleCallback" + }, + "identifier":"testEngine-subprocess1-anonymous-choose-branch-null", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"", + "type":"BASIC" + } + }, + "condition":"org.smartboot.flow.example.ChooseCondition", + "describe":"choose@org.smartboot.flow.example.ChooseCondition", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-choose", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":204 + }, + "execute-total":{ + "value":205 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"anonymous-choose", + "type":"CHOOSE" + }, + { + "components":{ + "then":{ + "components":{ + + }, + "describe":"pipeline@anonymous-pipeline-20", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-21", + "metrics":{ + "metrics":{ + + } + }, + "name":"anonymous-pipeline-wrapper-21", + "pipeline":{ + "components":[ + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step5", + "executable":"org.smartboot.flow.example.Step5", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step5", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-21-anonymous-pipeline-20-step5", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step5", + "type":"BASIC" + }, + { + "components":{ + + }, + "describe":"org.smartboot.flow.example.Step6", + "executable":"org.smartboot.flow.example.Step6", + "holders":{ + "rollback":"false", + "async":"false", + "name":"step6", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-21-anonymous-pipeline-20-step6", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"step6", + "type":"BASIC" + } + ], + "identifier":"testEngine-subprocess1-anonymous-if-anonymous-pipeline-wrapper-21-anonymous-pipeline-20", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":0 + }, + "execute-total":{ + "value":0 + }, + "execute-count":{ + "value":1 + } + } + }, + "name":"anonymous-pipeline-20" + }, + "type":"PIPELINE" + } + }, + "condition":"script-javascript", + "describe":"if@script-javascript", + "holders":{ + "rollback":"false", + "async":"false", + "degradable":"false", + "enabled":"true", + "timeout":"0" + }, + "identifier":"testEngine-subprocess1-anonymous-if", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":332 + }, + "execute-total":{ + "value":360 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"anonymous-if", + "type":"IF" + } + ], + "identifier":"testEngine-subprocess1", + "metrics":{ + "metrics":{ + "execute-max":{ + "value":740 + }, + "execute-total":{ + "value":973 + }, + "execute-count":{ + "value":3 + } + } + }, + "name":"subprocess1" + } + }, + "host":"xxx-MacBook-Pro.local", + "timestamp":1669960706283 +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index b2f7d00..6b731b6 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,6 @@ - flow-engine diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index 6b2cc8d..a2a2b49 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -36,14 +36,7 @@ org.slf4j slf4j-api - 2.0.3 - - - - org.slf4j - slf4j-log4j12 - 2.0.3 - test + 2.0.5 diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 6aa5b36..abff39a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -36,7 +36,7 @@ public class EngineContext { private boolean rollback; private final Map> asyncInvokes = new ConcurrentHashMap<>(); private String engineName; - private ExecutionListener listener; + ExecutionListener listener; /** * 执行状态 */ @@ -144,9 +144,9 @@ public class EngineContext { public void enter(Object obj) { String message = this.executing == ROLLBACK ? "rollback " : ""; if (obj instanceof Describable) { - message += ("rollback " + ((Describable) obj).describe()); + message += (((Describable) obj).describe()); } else if (obj instanceof String) { - message += ("rollback " + obj); + message += (obj); } this.tracer.enter(message); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java index 8832875..d9b624f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java @@ -7,6 +7,9 @@ package org.smartboot.flow.core; */ public interface ExecutionListener { + void start(EngineContext context); + void completed(EngineContext context); + void beforeExecute(EngineContext context, Object object); void afterExecute(EngineContext context, Object object); void beforeRollback(EngineContext context, Object object); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java index f8062d7..c502bc0 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java @@ -7,6 +7,16 @@ package org.smartboot.flow.core; */ public class ExecutionListenerSupport implements ExecutionListener { + @Override + public void start(EngineContext context) { + + } + + @Override + public void completed(EngineContext context) { + + } + @Override public void beforeExecute(EngineContext context, Object object) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java index 5e62709..e4eb249 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java @@ -20,6 +20,28 @@ public class ExecutionListeners implements ExecutionListener { this.listeners = listeners; } + @Override + public void start(EngineContext context) { + for (ExecutionListener listener : listeners) { + try { + listener.start(context); + } catch (Throwable e) { + LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e); + } + } + } + + @Override + public void completed(EngineContext context) { + for (ExecutionListener listener : listeners) { + try { + listener.completed(context); + } catch (Throwable e) { + LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e); + } + } + } + @Override public void beforeExecute(EngineContext context, Object object) { for (ExecutionListener listener : listeners) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java index 3389146..3c6a802 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core; +import org.smartboot.flow.core.exception.DefaultExceptionHandler; import org.smartboot.flow.core.exception.ExceptionHandler; import org.smartboot.flow.core.manager.DefaultEngineManager; import org.smartboot.flow.core.metrics.MetricExecutionListener; @@ -19,7 +20,7 @@ import java.util.concurrent.ExecutorService; public class FlowEngine implements Describable, Validator, Measurable { private Pipeline pipeline; - private ExceptionHandler exceptionHandler; + private ExceptionHandler exceptionHandler = new DefaultExceptionHandler(); private String name; private volatile boolean validateCalled = false; @@ -44,6 +45,9 @@ public class FlowEngine implements Describable, Validator, Measurable { initContext(context); + // fire start + start(context); + context.enter(this); boolean rollback = false; @@ -65,6 +69,9 @@ public class FlowEngine implements Describable, Validator, Measurable { context.setExecuting(EngineContext.EXECUTING); context.exit(this); + // complete execute. + complete(context); + if (context.getFatal() != null && exceptionHandler != null) { context.getHandler().handle(context, context.getFatal()); } @@ -72,6 +79,16 @@ public class FlowEngine implements Describable, Validator, Measurable { return context; } + private void start(EngineContext context) { + context.listener.start(context); + } + + private void complete(EngineContext context) { + context.listener.completed(context); + } + + + protected void initContext(EngineContext context) { context.clear(); context.setHandler(exceptionHandler); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java index 2227a06..4f27c9e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java @@ -108,7 +108,6 @@ public enum Attributes { ; private final String name; - private final boolean allowedNull; /** * Attribute accepted type. @@ -118,11 +117,6 @@ public enum Attributes { Attributes(String name, Class accept) { this.name = name; this.accept = accept; - this.allowedNull = this.accept.isPrimitive(); - } - - public boolean allowedNull() { - return allowedNull; } public String getName() { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java index 288a406..51c5149 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java @@ -11,5 +11,4 @@ public enum ComponentType { CHOOSE, PIPELINE, - ; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/ExceptionHandlerSupport.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/DefaultExceptionHandler.java similarity index 72% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/exception/ExceptionHandlerSupport.java rename to smart-flow-core/src/main/java/org/smartboot/flow/core/exception/DefaultExceptionHandler.java index 2b251e0..6d74b84 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/ExceptionHandlerSupport.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/DefaultExceptionHandler.java @@ -8,11 +8,11 @@ import org.smartboot.flow.core.EngineContext; * @date 2022-11-11 21:11:59 * @since 1.0.0 */ -public class ExceptionHandlerSupport implements ExceptionHandler { +public class DefaultExceptionHandler implements ExceptionHandler { @Override public void handle(EngineContext context, Throwable e) { - + throw new FlowException(e); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java index 7654a8c..356f936 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/exception/FlowException.java @@ -9,9 +9,6 @@ public class FlowException extends RuntimeException { private static final long serialVersionUID = -7613637640003340281L; - public FlowException() { - } - public FlowException(String message) { super(message); } @@ -23,8 +20,4 @@ public class FlowException extends RuntimeException { public FlowException(Throwable cause) { super(cause); } - - public FlowException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java index 971bb7b..697b540 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java @@ -4,7 +4,6 @@ import org.smartboot.flow.core.attribute.AttributeValueResolver; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.common.Uniqueness; import org.smartboot.flow.core.attribute.AttributeHolder; -import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.metrics.Metrics; @@ -21,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; @SuppressWarnings("rawtypes") public class ComponentModel extends Uniqueness { - private final Map holders = new ConcurrentHashMap<>(); + private final Map holders = new ConcurrentHashMap<>(); private final Component component; private final String name; private final String describe; @@ -44,13 +43,13 @@ public class ComponentModel extends Uniqueness { this.metrics = component.getMetrics(); } - public Map getHolders() { + public Map getHolders() { return holders; } public void addAttributes(List attributes) { for (AttributeHolder holder : attributes) { - this.holders.put(holder.getAttribute(), holder.getValue()); + this.holders.put(holder.getAttribute().getName(), holder.getValue()); } } @@ -120,7 +119,7 @@ public class ComponentModel extends Uniqueness { @SuppressWarnings("unchecked") public void changeAttributes(List holders) { - Map snapshot = new HashMap<>(this.holders); + Map snapshot = new HashMap<>(this.holders); AttributeValueResolver valueResolver = new AttributeValueResolver(); try { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java index 0d441c7..b9d5463 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java @@ -2,6 +2,7 @@ package org.smartboot.flow.core.metrics; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.ExecutionListener; +import org.smartboot.flow.core.ExecutionListenerSupport; import org.smartboot.flow.core.Key; import org.smartboot.flow.core.Measurable; @@ -13,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap; * @date 2022-11-25 21:23:28 * @since 1.0.0 */ -public class MetricExecutionListener implements ExecutionListener { +public class MetricExecutionListener extends ExecutionListenerSupport { private static final ExecutionListener INSTANCE = new MetricExecutionListener(); @@ -36,7 +37,7 @@ public class MetricExecutionListener implements ExecutionListener { Measurable measurable = (Measurable) object; Metrics metrics = measurable.getMetrics(); - metrics.addMetric("execute-count", 1); + metrics.addMetric(NamedMetrics.EXECUTE, 1); escaped.put(object, System.currentTimeMillis()); } @@ -59,11 +60,11 @@ public class MetricExecutionListener implements ExecutionListener { Measurable measurable = (Measurable) object; Metrics metrics = measurable.getMetrics(); if (context.getFatal() != null) { - metrics.addMetric("execute-fail-count", 1); + metrics.addMetric(NamedMetrics.FAIL, 1); } long now = System.currentTimeMillis(); - metrics.addMetric("execute-total", (now - start)); - metrics.addMetric(MetricKind.MAX,"execute-max", (now - start)); + metrics.addMetric(NamedMetrics.TOTAL_ESCAPE, (now - start)); + metrics.addMetric(MetricKind.MAX, NamedMetrics.MAX_ESCAPE, (now - start)); } @Override @@ -79,7 +80,7 @@ public class MetricExecutionListener implements ExecutionListener { Measurable measurable = (Measurable) object; Metrics metrics = measurable.getMetrics(); - metrics.addMetric("rollback-count", 1); + metrics.addMetric(NamedMetrics.ROLLBACK, 1); escaped.put(object, System.currentTimeMillis()); } @@ -102,7 +103,7 @@ public class MetricExecutionListener implements ExecutionListener { Measurable measurable = (Measurable) object; Metrics metrics = measurable.getMetrics(); long now = System.currentTimeMillis(); - metrics.addMetric("rollback-total", (now - start)); - metrics.addMetric(MetricKind.MAX,"rollback-max", (now - start)); + metrics.addMetric(NamedMetrics.ROLLBACK_TOTAL_ESCAPE, (now - start)); + metrics.addMetric(MetricKind.MAX, NamedMetrics.ROLLBACK_MAX_ESCAPE, (now - start)); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java index e779d07..c2f80b8 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java @@ -10,5 +10,4 @@ public enum MetricKind { ACCUMULATE, MAX, - ; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/NamedMetrics.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/NamedMetrics.java new file mode 100644 index 0000000..7a81a92 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/NamedMetrics.java @@ -0,0 +1,17 @@ +package org.smartboot.flow.core.metrics; + +/** + * @author qinluo + * @date 2022/11/23 21:45 + * @since 1.0.0 + */ +public interface NamedMetrics { + + String EXECUTE = "execute"; + String FAIL = "fail"; + String ROLLBACK = "rollback"; + String MAX_ESCAPE = "maxEscape"; + String TOTAL_ESCAPE = "totalEscape"; + String ROLLBACK_MAX_ESCAPE = "rollbackMaxEscape"; + String ROLLBACK_TOTAL_ESCAPE = "rollbackTotalEscape"; +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java index b9b434c..1dc3fed 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java @@ -6,8 +6,6 @@ package org.smartboot.flow.core.parser; */ public interface ParseConstants { - String NAMESPACE = "http://org.smartboot/smart-flow"; - /** * tags */ diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index e37753f..8e82f14 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -60,7 +60,7 @@ - + diff --git a/smart-flow-example/src/main/resources/log4j.properties b/smart-flow-example/src/main/resources/log4j.properties index 70b2b16..b9a23dd 100644 --- a/smart-flow-example/src/main/resources/log4j.properties +++ b/smart-flow-example/src/main/resources/log4j.properties @@ -24,7 +24,7 @@ log4j.appender.error.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### -log4j.rootLogger=debug,info,stdout +log4j.rootLogger=debug,stdout #log4j.logger.org.hibernate=info #log4j.logger.org.hibernate=debug diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java index cb737c3..1185d0d 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java @@ -33,7 +33,9 @@ public class ParseTest { EngineContext executeContext = testEngine.execute(1); LOGGER.info("trace\n {}", executeContext.getTrace()); - testEngine.execute((Integer) null); + LOGGER.info("========================================================================="); + executeContext = testEngine.execute((Integer) null); + LOGGER.info("trace\n {}", executeContext.getTrace()); LOGGER.info("========================================================================="); diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 970e954..5b06e3b 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -32,7 +32,7 @@ com.alibaba fastjson - 2.0.19 + 2.0.20.graal diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java index 552420d..aafb589 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java @@ -70,14 +70,18 @@ public class HttpManager { headers.forEach(post::addHeader); } + long timestamp = lastest; + try { RequestModel model = new RequestModel(); model.setAddress(HostUtils.getHostIp()); model.setHost(HostUtils.getHostName()); - model.setTimestamp(lastest); + model.setTimestamp(timestamp); // 只请求当前机器有的engines model.setEngineNames(DefaultEngineManager.getDefaultManager().getRegisteredEngineNames()); + + String json = JSON.toJSONString(model); byte[] bytes = json.getBytes(StandardCharsets.UTF_8); @@ -104,7 +108,7 @@ public class HttpManager { continue; } - if (cm.getTimestamp() < lastest) { + if (cm.getTimestamp() < timestamp) { continue; } diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java index 7c7d3d5..d59d9b0 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java @@ -1,6 +1,7 @@ package org.smartboot.flow.manager.report; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.manager.EngineModel; @@ -62,9 +63,13 @@ public class HttpReporter extends AbstractReporter { reportModel.setTimestamp(System.currentTimeMillis()); reportModel.setData(model); - String json = JSON.toJSONString(reportModel); + String json = JSON.toJSONString(reportModel, SerializerFeature.WriteEnumUsingToString); byte[] bytes = json.getBytes(StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("report engine data, engine = {}, data = {}", model.getIdentifier(), json); + } + post.addHeader(HeaderNameEnum.CONTENT_TYPE.getName(), "application/json;charset=UTF-8"); post.addHeader(HeaderNameEnum.CONTENT_LENGTH.getName(), String.valueOf(bytes.length)); -- Gitee From 2ff97ea1c9653874ee5f8b1bae5c3bcef2100be1 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 4 Dec 2022 00:06:42 +0800 Subject: [PATCH 16/54] qinluo: - optimized attribute --- .../attribute/AttributeValueResolver.java | 51 +++++++++++++++++-- .../flow/core/attribute/Attributes.java | 21 ++------ .../flow/core/parser/ElementUtils.java | 2 +- .../flow/manager/change/HttpManager.java | 2 +- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java index faa8313..8e204e8 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java @@ -3,7 +3,9 @@ package org.smartboot.flow.core.attribute; import org.smartboot.flow.core.exception.FlowException; import org.smartboot.flow.core.parser.DefaultObjectCreator; import org.smartboot.flow.core.parser.ObjectCreator; +import org.smartboot.flow.core.util.AssertUtil; +import java.math.BigDecimal; import java.util.Arrays; import java.util.List; @@ -33,22 +35,61 @@ public class AttributeValueResolver { // Must as string String strValue = String.valueOf(value); + // For string + if (attribute.accept(strValue)) { + return strValue; + } + + // For boolean if (accepted == Boolean.class || accepted == boolean.class) { return Boolean.parseBoolean(strValue); } - if (accepted == Long.class || accepted == long.class) { - return Long.parseLong(strValue); - } + // For numbers + if (Number.class.isAssignableFrom(accepted) || accepted.isPrimitive()) { + Double numeric = Double.valueOf(strValue); + + if (accepted == Long.class || accepted == long.class) { + return numeric.longValue(); + } + + if (accepted == Double.class || accepted == double.class) { + return numeric; + } + + if (accepted == Integer.class || accepted == int.class) { + return numeric.intValue(); + } + + if (accepted == Float.class || accepted == float.class) { + return numeric.floatValue(); + } + + if (accepted == Short.class || accepted == short.class) { + return numeric.shortValue(); + } + + if (accepted == Byte.class || accepted == byte.class) { + return numeric.byteValue(); + } + + if (accepted == Character.class || accepted == char.class) { + return (char)numeric.intValue(); + } + + if (accepted == BigDecimal.class) { + return new BigDecimal(strValue); + } - if (accepted == Integer.class || accepted == int.class) { - return Integer.parseInt(strValue); + AssertUtil.shouldNotReachHere(); } + // For string list. if (accepted == List.class) { return Arrays.asList(strValue.split(",")); } + // for classname. try { return objectCreator.create(strValue, true); } catch (Exception ignored) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java index 4f27c9e..bc9eafe 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java @@ -3,7 +3,6 @@ package org.smartboot.flow.core.attribute; import org.smartboot.flow.core.DegradeCallback; import org.smartboot.flow.core.component.Component; -import org.smartboot.flow.core.util.AssertUtil; import java.util.List; @@ -54,23 +53,14 @@ public enum Attributes { super.apply(component, value); component.setTimeout(((Number) value).longValue()); } - - @Override - public boolean accept(Object value) { - return value instanceof Long || value instanceof Integer || value instanceof String; - } }, DEPENDS_ON("dependsOn", List.class) { @Override public void apply(Component component, Object value) { super.apply(component, value); - if (value instanceof List) { - //noinspection unchecked - component.setDependsOn((List)value); - } else { - AssertUtil.shouldNotReachHere(); - } + //noinspection unchecked + component.setDependsOn((List)value); } }, @@ -83,11 +73,6 @@ public enum Attributes { @Override public void apply(Component component, Object value) { super.apply(component, value); - - if (value instanceof String) { - value = Boolean.parseBoolean((String) value); - } - component.setEnabled((Boolean) value); } }, @@ -131,7 +116,7 @@ public enum Attributes { component.addAttribute(new AttributeHolder(this, value)); } - public static Attributes with(String name) { + public static Attributes byName(String name) { for (Attributes v : values()) { if (v.name.equals(name)) { return v; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java index 8ee5f57..66921fb 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementUtils.java @@ -27,7 +27,7 @@ public final class ElementUtils { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); Attributes attribute; - if ((attribute = Attributes.with(item.getNodeName())) == null) { + if ((attribute = Attributes.byName(item.getNodeName())) == null) { continue; } diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java index aafb589..861e09f 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java @@ -115,7 +115,7 @@ public class HttpManager { if (action == ManagerAction.CHANGE_ATTRIBUTES) { AssertUtil.notBlank(cm.getIdentifier(), "identifier must not be null"); AssertUtil.notBlank(cm.getValue(), "value must not be null"); - Attributes attribute = Attributes.with(cm.getName()); + Attributes attribute = Attributes.byName(cm.getName()); if (attribute == null) { LOGGER.error("unknown supported attribute {}, please check version", cm.getName()); continue; -- Gitee From 9d2ec5cd8e113149840b8de5ac7e4de24e254de3 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 7 Dec 2022 15:11:23 +0800 Subject: [PATCH 17/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20spring?= =?UTF-8?q?=E9=9B=86=E6=88=90=E4=BC=98=E5=8C=96=20=20=20=20=20=20-=20?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=B7=BB=E5=8A=A0=20=20=20=20=20=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BE=BF=E4=BA=8E=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../attribute/AttributeValueResolver.java | 2 +- .../flow/core/metrics/MetricsCreator.java | 2 +- .../core/parser/DefaultObjectCreator.java | 6 ++ .../flow/core/parser/DefaultParser.java | 2 +- .../parser/definition/ScriptDefinition.java | 4 +- .../flow/core/script/ScriptConstants.java | 13 +++ .../flow/core/script/ScriptDetector.java | 22 +++-- .../org/smartboot/flow/core/trace/Node.java | 6 +- .../org/smartboot/flow/core/trace/Tracer.java | 6 ++ .../flow/core/useful/AbstractEngineQuery.java | 21 +++++ .../core/useful/AbstractExecutorSelector.java | 43 ++++++++++ .../flow/core/useful/DefaultEngineQuery.java | 24 ++++++ .../core/useful/DefaultExecutorSelector.java | 28 +++++++ .../core/useful/EngineExecutorManager.java | 83 +++++++++++++++++++ .../flow/core/useful/ExecutorSelector.java | 23 +++++ .../smartboot/flow/core/util/AssertUtil.java | 2 +- .../flow/core/util/AuxiliaryUtils.java | 2 +- .../groovy/GroovyScriptCondition.java | 1 - .../extension/BeanDefinitionRegister.java | 28 +++++++ .../extension/BeanDefinitionVisitor.java | 82 ++++++++++++------ .../flow/spring/extension/ProxyParser.java | 2 +- 22 files changed, 362 insertions(+), 44 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractEngineQuery.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractExecutorSelector.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultEngineQuery.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultExecutorSelector.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/EngineExecutorManager.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/useful/ExecutorSelector.java create mode 100644 smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java diff --git a/README.md b/README.md index 465165a..623ce27 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [X] 支持自定义执行数据采集 - [X] 支持HTTP方式引擎数据上报(包含执行数据) - [X] 支持组件动态管理(动态降级、启用组件等功能) -- [ ] 自带管理后台 -- [ ] 支持引擎Reload +- [ ] 自带简易管理后台 +- [ ] 支持从数据库等存储介质重新加载 diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java index 8e204e8..86e7e28 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java @@ -16,7 +16,7 @@ import java.util.List; */ public class AttributeValueResolver { - private ObjectCreator objectCreator = new DefaultObjectCreator(); + private ObjectCreator objectCreator = DefaultObjectCreator.getInstance(); public void setObjectCreator(ObjectCreator objectCreator) { this.objectCreator = objectCreator; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsCreator.java index 4eabcb9..231b2a4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsCreator.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsCreator.java @@ -8,7 +8,7 @@ package org.smartboot.flow.core.metrics; public interface MetricsCreator { /** - * 创建一个metrics实力 + * 创建一个metrics实例 * * @return metrics */ diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java index 84d7fe4..66df9a7 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java @@ -13,6 +13,8 @@ import java.util.concurrent.ConcurrentHashMap; @SuppressWarnings("unchecked") public class DefaultObjectCreator implements ObjectCreator { + private static final ObjectCreator INSTANCE = new DefaultObjectCreator(); + private final Map, Object> cachedObjects = new ConcurrentHashMap<>(); private static Class check(String type) { @@ -23,6 +25,10 @@ public class DefaultObjectCreator implements ObjectCreator { } } + public static ObjectCreator getInstance() { + return INSTANCE; + } + @Override public T create(String typename, boolean useCache) { AssertUtil.notBlank(typename, "type must not be blank!"); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java index 6408f1b..cfd54ee 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultParser.java @@ -101,7 +101,7 @@ public class DefaultParser implements Parser { } protected ObjectCreator getObjectCreator() { - return new DefaultObjectCreator(); + return DefaultObjectCreator.getInstance(); } public FlowEngine getEngine(String name) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java index bd5b059..72d31a2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/ScriptDefinition.java @@ -25,7 +25,7 @@ public class ScriptDefinition extends ElementDefinition { if (!AuxiliaryUtils.isType(type)) { javaType = ScriptDetector.get().getJavaType(type); } else { - javaType = AuxiliaryUtils.beType(type); + javaType = AuxiliaryUtils.asClass(type); } AssertUtil.notNull(javaType, "script type must be a javaType"); @@ -39,7 +39,7 @@ public class ScriptDefinition extends ElementDefinition { * @return maybe null in spring container. */ public Class getJavaType() { - Class javaType = AuxiliaryUtils.beType(type); + Class javaType = AuxiliaryUtils.asClass(type); if (javaType == null) { javaType = ScriptDetector.get().getJavaType(type); } 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 1cf3080..8d20f40 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 @@ -1,13 +1,26 @@ package org.smartboot.flow.core.script; /** + * Constants definitions in script. + * * @author qinluo * @date 2022/11/28 19:41 * @since 1.0.0 */ public interface ScriptConstants { + /** + * Request params. + */ String REQ = "request"; + + /** + * Result mode. + */ String RESULT = "result"; + + /** + * Flow engine execution context. + */ String CONTEXT = "context"; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java index f95b713..989b0b2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/script/ScriptDetector.java @@ -18,26 +18,42 @@ import java.util.concurrent.ConcurrentHashMap; */ public class ScriptDetector { + /** + * The phrase for {@link org.smartboot.flow.core.script.ScriptCondition} location. + */ private static final String LOCATION = "META-INF/smart-flow-script"; + + /** + * The stored phrase for {@link org.smartboot.flow.core.script.ScriptCondition} + */ private final Map> javaTypes = new ConcurrentHashMap<>(); + /** + * The singleton instance for detector. + */ private static final ScriptDetector DETECTOR = new ScriptDetector(); + public static ScriptDetector get() { + return DETECTOR; + } + private ScriptDetector() { try { Enumeration resources = this.getClass().getClassLoader().getResources(LOCATION); while (resources.hasMoreElements()) { URL url = resources.nextElement(); + // phrase files must be properties. Properties properties = new Properties(); properties.load(url.openStream()); + // key : phrase, value: full java classname. Set keys = properties.stringPropertyNames(); for (String key : keys) { AssertUtil.notBlank(key, "script key must not be blank"); String type = properties.getProperty(key); AssertUtil.notBlank(type, "script " + key + " type must not be blank"); - Class javaType = AuxiliaryUtils.beType(type); + Class javaType = AuxiliaryUtils.asClass(type); AssertUtil.notNull(javaType, "script " + key + " type must be a javaType"); AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(javaType), "script " + key + " type must be a subclass of ScriptCondition"); AssertUtil.isTrue(ScriptCondition.class != (javaType), "script " + key + " type must be a subclass of ScriptCondition"); @@ -54,8 +70,4 @@ public class ScriptDetector { AssertUtil.notBlank(type, "type must not blank"); return javaTypes.get(type.trim().toLowerCase()); } - - public static ScriptDetector get() { - return DETECTOR; - } } 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 74eb46b..12b214c 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 @@ -116,17 +116,17 @@ public class Node { } } - private String generatePrefix(String prefix, boolean async, boolean i) { + private String generatePrefix(String prefix, boolean async, boolean hasNext) { if (prefix == null || prefix.length() == 0) { return "|---"; } if (prefix.length() == 4) { - return (i ? "|" : " ") + " |" + (async ? "~~~" : "---"); + return (hasNext ? "|" : " ") + " |" + (async ? "~~~" : "---"); } int length = prefix.length() - 5; - return prefix.substring(0, length) + (i ? " |" : " ") + " |" + (async ? "~~~" : "---"); + return prefix.substring(0, length) + (hasNext ? " |" : " ") + " |" + (async ? "~~~" : "---"); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java index 406327e..1548213 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java @@ -1,6 +1,8 @@ package org.smartboot.flow.core.trace; /** + * 以类似栈的方式记录调用路径(支持追踪异步调用路径) + * * @author qinluo * @date 2022-11-11 21:53:04 * @since 1.0.0 @@ -13,6 +15,10 @@ public class Tracer { * Record invoking tree path string. */ private String trace; + + /** + * The root node. + */ private Node root; public String getTrace() { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractEngineQuery.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractEngineQuery.java new file mode 100644 index 0000000..b7bdbd6 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractEngineQuery.java @@ -0,0 +1,21 @@ +package org.smartboot.flow.core.useful; + +import java.io.Serializable; + +/** + * @author qinluo + * @version 1.0.0 + * @since 2019-05-20 14:23 + */ +public abstract class AbstractEngineQuery implements Serializable { + + private static final long serialVersionUID = -4493559976724466867L; + + /** + * 得到组装字符串 + * + * @return 组装的字符串,由各个实现自由决定 + */ + public abstract String getKey(); + +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractExecutorSelector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractExecutorSelector.java new file mode 100644 index 0000000..eae0904 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/AbstractExecutorSelector.java @@ -0,0 +1,43 @@ +package org.smartboot.flow.core.useful; + + +import org.smartboot.flow.core.FlowEngine; + +import java.util.Map; + +/** + * @author qinluo + * @version 1.0.0 + * @date 2020-04-07 15:13 + */ +@SuppressWarnings({"rawtypes"}) +public abstract class AbstractExecutorSelector implements ExecutorSelector { + + private String selectorName; + + public String getSelectorName() { + return selectorName; + } + + public void setSelectorName(String selectorName) { + this.selectorName = selectorName; + } + + @Override + public FlowEngine select(Map engineMap, AbstractEngineQuery query) { + if (engineMap == null || engineMap.size() == 0) { + throw new IllegalStateException(selectorName + " there are no available executors, because map is empty!"); + } + + return doSelect(engineMap, query); + } + + /** + * Select a engine executor. + * + * @param engineMap candidate engine executor + * @param query engine query + * @return engine executor + */ + public abstract FlowEngine doSelect(Map engineMap, AbstractEngineQuery query); +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultEngineQuery.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultEngineQuery.java new file mode 100644 index 0000000..4c9cca2 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultEngineQuery.java @@ -0,0 +1,24 @@ +package org.smartboot.flow.core.useful; + +/** + * 通过engineName查询engine + * + * @author qinluo + * @date 2022-12-07 14:30:08 + * @since 1.0.0 + */ +public class DefaultEngineQuery extends AbstractEngineQuery { + + private static final long serialVersionUID = -383072247314629042L; + + private final String engineName; + + public DefaultEngineQuery(String name) { + this.engineName = name; + } + + @Override + public String getKey() { + return engineName; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultExecutorSelector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultExecutorSelector.java new file mode 100644 index 0000000..db681dc --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/DefaultExecutorSelector.java @@ -0,0 +1,28 @@ +package org.smartboot.flow.core.useful; + +import org.smartboot.flow.core.FlowEngine; + +import java.util.Map; +import java.util.Objects; + +/** + * @author qinluo + * @date 2022-12-06 21:29:32 + * @since 1.0.0 + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class DefaultExecutorSelector extends AbstractExecutorSelector { + + @Override + public FlowEngine doSelect(Map engineMap, AbstractEngineQuery query) { + String key = query.getKey(); + + for (FlowEngine flowEngine : engineMap.values()) { + if (Objects.equals(key, flowEngine.getName())) { + return flowEngine; + } + } + + return null; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/EngineExecutorManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/EngineExecutorManager.java new file mode 100644 index 0000000..4a26934 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/EngineExecutorManager.java @@ -0,0 +1,83 @@ +package org.smartboot.flow.core.useful; + + + +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.Validator; +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.util.AssertUtil; + +import java.util.Map; + +/** + * 引擎管理器抽象类 + * + * @author qinluo + * @version 1.0.0 + * @since 2019-05-20 14:18 + */ +@SuppressWarnings({"rawtypes"}) +public class EngineExecutorManager implements Validator { + + /** + * Managed engines. + */ + private Map flowEngines; + + /** + * Default selector by name. + */ + private ExecutorSelector selector = new DefaultExecutorSelector(); + + public ExecutorSelector getSelector() { + return selector; + } + + public void setSelector(ExecutorSelector selector) { + if (selector == null) { + throw new IllegalStateException("selector must not be null!"); + } + this.selector = selector; + } + + public void setSelectorName(String selectorName) { + if (selector instanceof AbstractExecutorSelector) { + ((AbstractExecutorSelector) selector).setSelectorName(selectorName); + } + } + + public Map getFlowEngines() { + return flowEngines; + } + + public void setFlowEngines(Map flowEngines) { + this.flowEngines = flowEngines; + } + + public FlowEngine getEngine(AbstractEngineQuery query) { + AssertUtil.notNull(query, "engine query must not be null!"); + + this.validate(); + + FlowEngine engineExecutor = selector.select(flowEngines, query); + if (engineExecutor == null) { + throw new FlowException("select engine executor error. selector return null!"); + } + + return engineExecutor; + } + + public FlowEngine getEngine(String engineName) { + AssertUtil.notBlank(engineName, "engineName must not be blank"); + return getEngine(new DefaultEngineQuery(engineName)); + } + + @Override + public void validate() { + if (flowEngines == null || flowEngines.size() == 0) { + throw new FlowException("there is no available engine, please check!"); + } + + AssertUtil.notNull(selector, "selector must not be null!"); + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/ExecutorSelector.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/ExecutorSelector.java new file mode 100644 index 0000000..7236ff8 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/useful/ExecutorSelector.java @@ -0,0 +1,23 @@ +package org.smartboot.flow.core.useful; + + +import org.smartboot.flow.core.FlowEngine; + +import java.util.Map; + +/** + * @author qinluo + * @version 1.0.0 + * @since 2019-06-04 15:55 + */ +@SuppressWarnings("rawtypes") +public interface ExecutorSelector { + + /** + * 从候选执行引擎中选择一个返回 + * @param engineMap 执行引擎列表Map + * @param query 查询对象 + * @return 选中的执行引擎 + */ + FlowEngine select(Map engineMap, AbstractEngineQuery query); +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java index 56e1f85..f23d8a4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AssertUtil.java @@ -17,7 +17,7 @@ public final class AssertUtil { public static void shouldNotReachHere() { - throw new IllegalStateException("should not reach here"); + throw new FlowException("should not reach here"); } public static void notNull(Object value, String message) { 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 6e0f596..ed890c3 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 @@ -32,7 +32,7 @@ public final class AuxiliaryUtils { } } - public static Class beType(String typename) { + public static Class asClass(String typename) { try { return Class.forName(typename); } catch (Exception e) { diff --git a/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java index e381315..b464d08 100644 --- a/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java +++ b/smart-flow-script-condition/smart-flow-script-groovy/src/main/java/org/smartboot/flow/condition/extension/groovy/GroovyScriptCondition.java @@ -25,7 +25,6 @@ public class GroovyScriptCondition extends ScriptCondition { return "groovy"; } - @Override public Object test(EngineContext engineContext) { try { diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java new file mode 100644 index 0000000..075e45a --- /dev/null +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java @@ -0,0 +1,28 @@ +package org.smartboot.flow.spring.extension; + +import org.springframework.beans.factory.config.BeanDefinition; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author qinluo + * @date 2022-12-06 20:47:23 + * @since 1.0.0 + */ +public class BeanDefinitionRegister { + + private final Map registered = new HashMap<>(32); + + public BeanDefinition getBeanDefinition(String identifier) { + return registered.get(identifier); + } + + public void registerBeanDefinition(String identifier, BeanDefinition def) { + registered.put(identifier, def); + } + + public boolean containsBeanDefinition(String identifier) { + return registered.containsKey(identifier); + } +} diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index f80f571..d0a1d6b 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -3,6 +3,7 @@ package org.smartboot.flow.spring.extension; import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.parser.DefinitionVisitor; +import org.smartboot.flow.core.parser.ParserContext; import org.smartboot.flow.core.parser.definition.ChooseDefinition; import org.smartboot.flow.core.parser.definition.ElementDefinition; import org.smartboot.flow.core.parser.definition.EngineDefinition; @@ -31,9 +32,16 @@ import java.util.List; public class BeanDefinitionVisitor implements DefinitionVisitor { private final BeanDefinitionRegistry registry; + private final ParserContext context; - public BeanDefinitionVisitor(BeanDefinitionRegistry registry) { + /** + * Temporary def register. + */ + private final BeanDefinitionRegister register = new BeanDefinitionRegister(); + + public BeanDefinitionVisitor(BeanDefinitionRegistry registry, ParserContext context) { this.registry = registry; + this.context = context; } @Override @@ -45,7 +53,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { if (javaType == null) { BeanDefinition beanDefinition = registry.getBeanDefinition(sed.getName()); String beanClassName = beanDefinition.getBeanClassName(); - Class defJavaType = AuxiliaryUtils.beType(beanClassName); + Class defJavaType = AuxiliaryUtils.asClass(beanClassName); AssertUtil.notNull(defJavaType, "bean " + sed.getName() + " javaType must be subclass of ScriptCondition"); AssertUtil.isTrue(ScriptCondition.class.isAssignableFrom(defJavaType), "bean " + sed.getName() + " javaType must be subclass of ScriptCondition"); @@ -84,7 +92,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { RootBeanDefinition definition = new RootBeanDefinition(); PropertyValue name = new PropertyValue("name", ed.getName()); - ManagedList components = new ManagedList<>(); + ManagedList components = new ManagedList<>(); definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); definition.getPropertyValues().add("components", components); @@ -92,13 +100,22 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { ed.getChildren().forEach(p -> p.visit(this)); for (ElementDefinition elementDef : ed.getChildren()) { - BeanDefinition beanDefinition = registry.getBeanDefinition(elementDef.getIdentifier()); + // Fire sub visit. + elementDef.visit(this); + + BeanDefinition beanDefinition = register.getBeanDefinition(elementDef.getIdentifier()); AssertUtil.notNull(beanDefinition, elementDef.getIdentifier() + " not exist"); - components.add(new RuntimeBeanReference(elementDef.getIdentifier())); + //components.add(new RuntimeBeanReference(elementDef.getIdentifier())); + components.add(beanDefinition); } - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + if (isAnonymous(ed.getIdentifier())) { + AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + register.registerBeanDefinition(ed.getIdentifier(), definition); + } else { + AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + registry.registerBeanDefinition(ed.getIdentifier(), definition); + } } @Override @@ -109,11 +126,22 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); - definition.getPropertyValues().addPropertyValue(pipeline); + + // definition.getPropertyValues().addPropertyValue(pipeline); + if (isAnonymous(ed.getPipeline())) { + context.getRegistered(ed.getPipeline()).visit(this); + definition.getPropertyValues().add("pipeline", register.getBeanDefinition(ed.getPipeline())); + } else { + definition.getPropertyValues().addPropertyValue(pipeline); + } appendAttributes(ed, definition); - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + register.registerBeanDefinition(ed.getIdentifier(), definition); + } + + private boolean isAnonymous(String name) { + return name.contains("anonymous-pipeline"); } private void appendAttributes(ElementDefinition ed, RootBeanDefinition definition) { @@ -164,8 +192,8 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } appendAttributes(ed, definition); - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + register.registerBeanDefinition(ed.getIdentifier(), definition); } private boolean isType(String type) { @@ -195,20 +223,22 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } ed.getIfThenRef().visit(this); - BeanDefinition beanDefinition = registry.getBeanDefinition(ed.getIfThenRef().getIdentifier()); + BeanDefinition beanDefinition = register.getBeanDefinition(ed.getIfThenRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getIfThenRef().getIdentifier() + " not exist"); - definition.getPropertyValues().add("thenComponent", new RuntimeBeanReference(ed.getIfThenRef().getIdentifier())); + //definition.getPropertyValues().add("thenComponent", new RuntimeBeanReference(ed.getIfThenRef().getIdentifier())); + definition.getPropertyValues().add("thenComponent", beanDefinition); if (ed.getIfElseRef() != null) { ed.getIfElseRef().visit(this); - beanDefinition = registry.getBeanDefinition(ed.getIfElseRef().getIdentifier()); + beanDefinition = register.getBeanDefinition(ed.getIfElseRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getIfElseRef().getIdentifier() + " not exist"); - definition.getPropertyValues().add("elseComponent", new RuntimeBeanReference(ed.getIfElseRef().getIdentifier())); + //definition.getPropertyValues().add("elseComponent", new RuntimeBeanReference(ed.getIfElseRef().getIdentifier())); + definition.getPropertyValues().add("elseComponent", beanDefinition); } appendAttributes(ed, definition); - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + register.registerBeanDefinition(ed.getIdentifier(), definition); } @Override @@ -228,26 +258,28 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.getPropertyValues().add("condition", new RuntimeBeanReference(ed.getTest())); } - ManagedMap managedMap = new ManagedMap<>(); + ManagedMap managedMap = new ManagedMap<>(); List chooseCaseList = ed.getChooseCaseList(); for (ElementDefinition caseDef : chooseCaseList) { caseDef.visit(this); - BeanDefinition beanDefinition = registry.getBeanDefinition(caseDef.getIdentifier()); + BeanDefinition beanDefinition = register.getBeanDefinition(caseDef.getIdentifier()); AssertUtil.notNull(beanDefinition, "case " + caseDef.getWhen() + " " + ed.getChooseDefaultRef().getIdentifier() + " not exist"); - managedMap.put(caseDef.getWhen(), new RuntimeBeanReference(caseDef.getIdentifier())); + //managedMap.put(caseDef.getWhen(), new RuntimeBeanReference(caseDef.getIdentifier())); + managedMap.put(caseDef.getWhen(), beanDefinition); } definition.getPropertyValues().add("branches", managedMap); if (ed.getChooseDefaultRef() != null) { ed.getChooseDefaultRef().visit(this); - BeanDefinition beanDefinition = registry.getBeanDefinition(ed.getChooseDefaultRef().getIdentifier()); + BeanDefinition beanDefinition = register.getBeanDefinition(ed.getChooseDefaultRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getChooseDefaultRef().getIdentifier() + " not exist"); - definition.getPropertyValues().add("defaultBranch", new RuntimeBeanReference(ed.getChooseDefaultRef().getIdentifier())); + //definition.getPropertyValues().add("defaultBranch", new RuntimeBeanReference(ed.getChooseDefaultRef().getIdentifier())); + definition.getPropertyValues().add("defaultBranch", beanDefinition); } appendAttributes(ed, definition); - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); + register.registerBeanDefinition(ed.getIdentifier(), definition); } } diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java index 59e4f8e..e151da6 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java @@ -26,7 +26,7 @@ public class ProxyParser implements BeanDefinitionParser { AssertUtil.notNull(parser, "Could not find parse for element " + ElementUtils.getName(element)); parser.parseElement(element, context); - BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(parserContext.getRegistry()); + BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(parserContext.getRegistry(), context); context.getRegistered().forEach(visitor::visit); return null; } -- Gitee From 822dbac00242409abad34a587bbb7c92f641673c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 7 Dec 2022 15:21:42 +0800 Subject: [PATCH 18/54] qinluo: - plugins --- pom.xml | 59 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 6b731b6..5d99066 100644 --- a/pom.xml +++ b/pom.xml @@ -18,27 +18,44 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - -XDignore.symbol.file - - - -parameters - - UTF-8 - true - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + true + UTF-8 + + -parameters + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + true + + + + package + + jar + + + + attach-sources + deploy + + + + \ No newline at end of file -- Gitee From cfbb4706d53947137e19666d0b0a39328327fab4 Mon Sep 17 00:00:00 2001 From: huqiang Date: Wed, 7 Dec 2022 20:19:50 +0800 Subject: [PATCH 19/54] support adapter component --- .../java/org/smartboot/flow/core/Adapter.java | 34 ++++++++ .../smartboot/flow/core/EngineContext.java | 18 ++++- .../flow/core/builder/AdapterBuilder.java | 31 +++++++ .../flow/core/builder/PipelineBuilder.java | 5 ++ .../flow/core/component/AdapterComponent.java | 80 +++++++++++++++++++ .../smartboot/flow/example/AdapterTest.java | 28 +++++++ .../org/smartboot/flow/example/NewStep1.java | 16 ++++ .../smartboot/flow/example/EngineTest.java | 34 ++++++++ 8 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java new file mode 100644 index 0000000..9009d7a --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java @@ -0,0 +1,34 @@ +package org.smartboot.flow.core; + +import com.sun.tools.javac.util.Pair; + +/** + * 适配器组件 + *

+ * 应用场景:将两个参数类型不同的业务组件适配成统一的类型 + * + *

+ * + * @author huqiang + * @since 2022/12/7 14:35 + */ +public interface Adapter extends Describable { + + + /** + * 适配前处理 + * + * @param context 流程上下文 + * @return 返回需要适配的组件的入参和出参 + */ + Pair before(EngineContext context); + + /** + * 适配后置处理 + * + * @param origin 原流程上下文 + * @param newContext 适配的组件返回的上下文 + */ + void after(EngineContext origin, EngineContext newContext); + +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index abff39a..69e1e92 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -18,7 +18,7 @@ import java.util.concurrent.Future; * @date 2022-11-12 21:00:58 * @since 1.0.0 */ -public class EngineContext { +public class EngineContext implements Cloneable{ public static final int DISABLED = -1; public static final int EXECUTING = 1; @@ -34,7 +34,7 @@ public class EngineContext { private Throwable fatal; private ExceptionHandler handler; private boolean rollback; - private final Map> asyncInvokes = new ConcurrentHashMap<>(); + private final Map asyncInvokes = new ConcurrentHashMap<>(); private String engineName; ExecutionListener listener; /** @@ -42,6 +42,20 @@ public class EngineContext { */ private int executing; + public EngineContext newContext(Object req, Object result) { + EngineContext newContext = new EngineContext<>(); + try { + newContext = (EngineContext)this.clone(); + newContext.extensions.putAll(this.extensions); + newContext.asyncInvokes.putAll(this.asyncInvokes); + newContext.setReq(req); + newContext.setResult(result); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + return newContext; + } + /** * Returns current invoked trace. * diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java new file mode 100644 index 0000000..9b3c08b --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java @@ -0,0 +1,31 @@ +package org.smartboot.flow.core.builder; + +import org.smartboot.flow.core.Adapter; +import org.smartboot.flow.core.component.AdapterComponent; +import org.smartboot.flow.core.component.Component; + +/** + * @author huqiang + * @since 2022/12/7 19:36 + */ +public class AdapterBuilder extends ExecutableBuilder { + + private Adapter adapter; + + private Component component; + + private AdapterComponent adapterComponent; + + public AdapterBuilder(Adapter adapter, Component component) { + adapterComponent = new AdapterComponent(); + adapterComponent.setAdapter(adapter); + adapterComponent.setComponent(component); + applyValues(adapterComponent); + } + + public AdapterComponent build() { + return adapterComponent; + } + + +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java index 4b5adff..2fc6a76 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core.builder; +import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.Condition; import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.component.Component; @@ -59,6 +60,10 @@ public class PipelineBuilder { return new IfComponentBuilder<>(this, condition); } + public PipelineBuilder adapter(Adapter adapter, Component component) { + return this.next(new AdapterBuilder(adapter, component).build()); + } + public ChooseBuilder choose(Condition condition) { AssertUtil.notNull(condition, "must not be null"); return new ChooseBuilder<>(this, condition); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java new file mode 100644 index 0000000..e2c1b70 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -0,0 +1,80 @@ +package org.smartboot.flow.core.component; + +import com.sun.tools.javac.util.Pair; +import org.smartboot.flow.core.Adapter; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.core.visitor.ComponentVisitor; + +/** + * 适配器组件 + * + * @author huqiang + * @since 2022/12/7 19:01 + */ +public class AdapterComponent extends Component { + + /** + * 业务适配器接口定义 + */ + private Adapter adapter; + + /** + * 待执行的适配流程组件 + */ + private Component component; + + public Adapter getAdapter() { + return this.adapter; + } + + public Component getComponent() { + return this.component; + } + + public void setAdapter(Adapter adapter) { + this.adapter = adapter; + } + + public void setComponent(Component component) { + this.component = component; + } + + @Override + public String describe() { + return "adapter@" + adapter.describe(); + } + + @Override + public void rollback(EngineContext context) { + component.rollback(context); + } + + @Override + public void validate() { + AssertUtil.notNull(adapter, "adapter[" + getName() + "] adapter must not be null"); + AssertUtil.notNull(component, "component[" + getName() + "] component must not be null"); + } + + @Override + public int invoke(EngineContext context) throws Exception { + Pair pair = adapter.before(context); + AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); + EngineContext newContext = context.newContext(pair.fst, pair.snd); + int invoke = 1; + try { + invoke = component.invoke(newContext); + } finally { + context.setFatal(newContext.getFatal()); + context.setRollback(newContext.getRollback()); + context.broken(newContext.isBroken()); + } + adapter.after(context, newContext); + return invoke; + } + + @Override + public void visit(ComponentVisitor visitor) { + visitor.visitComponent(this); + } +} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java new file mode 100644 index 0000000..bd5e9cf --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java @@ -0,0 +1,28 @@ +package org.smartboot.flow.example; + +import com.sun.tools.javac.util.Pair; +import org.smartboot.flow.core.Adapter; +import org.smartboot.flow.core.EngineContext; + +/** + * @author huqiang + * @since 2022/12/7 19:54 + */ +public class AdapterTest implements Adapter { + + @Override + public Pair before(EngineContext context) { + return Pair.of("req", "response"); + } + + @Override + public void after(EngineContext origin, EngineContext newContext) { + System.out.println("origin req = " + origin.getReq() + ", origin response = " + origin.getResult()); + System.out.println("req=" + newContext.getReq() + ", response=" + newContext.getResult()); + } + + @Override + public String describe() { + return this.getClass().getName(); + } +} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java new file mode 100644 index 0000000..a62f1fe --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java @@ -0,0 +1,16 @@ +package org.smartboot.flow.example; + +import org.smartboot.flow.core.executable.AbstractExecutable; + +/** + * @author huqiang + * @since 2022/12/7 19:57 + */ +public class NewStep1 extends AbstractExecutable { + + @Override + public void execute(String s, String s2) { + System.out.println("new step" + " req=" + s + ", response=" + s2); + + } +} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index f81f0e3..f9c86be 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -13,6 +13,7 @@ import org.smartboot.flow.core.builder.PipelineBuilder; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.IfComponent; +import org.smartboot.flow.core.component.PipelineComponent; import org.smartboot.flow.core.executable.AbstractExecutable; import org.smartboot.flow.core.executable.ExecutableAdapter; @@ -168,6 +169,39 @@ public class EngineTest { engine.execute(context); } + + @Test + public void testAdapterPipeline(){ + EngineBuilder builder = new EngineBuilder<>("defaultEngine"); + + + + + PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); + + PipelineBuilder adapterPipelineBuilder = new PipelineBuilder(pipelineBuilder, "adapter process"); + adapterPipelineBuilder.next(new NewStep1()).next(new NewStep1()); + + ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); + execBuilder.apply(Attributes.ROLLBACK, true); + Component nested = execBuilder.newAdapter(new Step5()); + + + pipelineBuilder.next(new Step1()).next(new Step2()) + .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) + .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) + .adapter(new AdapterTest(), new PipelineComponent(adapterPipelineBuilder.build())); + + + EngineContext context = new EngineContext<>(); + context.setReq(1); + context.setResult("hello"); + + builder.pipeline(pipelineBuilder.build()).build().execute(context); + + LOGGER.info("trace {}", context.getTrace()); + } + @Test public void testBuildPipeline() { EngineBuilder builder = new EngineBuilder<>("defaultEngine"); -- Gitee From c7d8e8187d9556ac6f420d1696c084244a3e3e02 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 7 Dec 2022 21:43:54 +0800 Subject: [PATCH 20/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/smartboot/flow/core/Adapter.java | 9 +++-- .../flow/core/builder/AdapterBuilder.java | 14 +++---- .../flow/core/builder/ChooseBuilder.java | 6 +-- .../flow/core/builder/ExecutableBuilder.java | 8 ++++ .../flow/core/builder/IfComponentBuilder.java | 10 ++--- .../flow/core/builder/PipelineBuilder.java | 4 +- .../org/smartboot/flow/core/common/Pair.java | 39 +++++++++++++++++++ .../flow/core/component/AdapterComponent.java | 33 +++++++--------- .../core/parser/BuilderDefinitionVisitor.java | 2 +- .../smartboot/flow/example/AdapterTest.java | 8 ++-- .../smartboot/flow/example/EngineTest.java | 4 +- 11 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/common/Pair.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java index 9009d7a..c08960b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Adapter.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core; -import com.sun.tools.javac.util.Pair; + +import org.smartboot.flow.core.common.Pair; /** * 适配器组件 @@ -12,7 +13,7 @@ import com.sun.tools.javac.util.Pair; * @author huqiang * @since 2022/12/7 14:35 */ -public interface Adapter extends Describable { +public interface Adapter extends Describable { /** @@ -21,7 +22,7 @@ public interface Adapter extends Describable { * @param context 流程上下文 * @return 返回需要适配的组件的入参和出参 */ - Pair before(EngineContext context); + Pair before(EngineContext context); /** * 适配后置处理 @@ -29,6 +30,6 @@ public interface Adapter extends Describable { * @param origin 原流程上下文 * @param newContext 适配的组件返回的上下文 */ - void after(EngineContext origin, EngineContext newContext); + void after(EngineContext origin, EngineContext newContext); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java index 9b3c08b..816021d 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java @@ -8,22 +8,22 @@ import org.smartboot.flow.core.component.Component; * @author huqiang * @since 2022/12/7 19:36 */ -public class AdapterBuilder extends ExecutableBuilder { +public class AdapterBuilder extends ExecutableBuilder { - private Adapter adapter; + private Adapter adapter; - private Component component; + private Component component; - private AdapterComponent adapterComponent; + private AdapterComponent adapterComponent; - public AdapterBuilder(Adapter adapter, Component component) { - adapterComponent = new AdapterComponent(); + public AdapterBuilder(Adapter adapter, Component component) { + adapterComponent = new AdapterComponent<>(); adapterComponent.setAdapter(adapter); adapterComponent.setComponent(component); applyValues(adapterComponent); } - public AdapterComponent build() { + public AdapterComponent build() { return adapterComponent; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java index 8c52802..b2b3447 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java @@ -44,7 +44,7 @@ public class ChooseBuilder extends ExecutableBuilder { public ChooseBuilder newBranch(Object branch, Executable executable) { AssertUtil.notNull(branch, "branch must not be null"); - branches.put(branch, newAdapter(executable)); + branches.put(branch, asComponent(executable)); return this; } @@ -53,7 +53,7 @@ public class ChooseBuilder extends ExecutableBuilder { } public PipelineBuilder end(Executable defaultBranch) { - return end(newAdapter(defaultBranch)); + return end(asComponent(defaultBranch)); } public Component build(Component defaultBranch) { @@ -67,7 +67,7 @@ public class ChooseBuilder extends ExecutableBuilder { } public Component build(Executable defaultBranch) { - return build(newAdapter(defaultBranch)); + return build(asComponent(defaultBranch)); } public PipelineBuilder end(Component defaultBranch) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java index 79fd24d..db2e27e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ExecutableBuilder.java @@ -21,6 +21,14 @@ public class ExecutableBuilder extends AbstractComponentBuilder { return adapter; } + /** + * Created as pure component. + */ + public Component asComponent(Executable executable) { + AssertUtil.notNull(executable, "must not be null"); + return new ExecutableAdapter<>(executable); + } + public ExecutableBuilder apply(Attributes attributes, Object value) { super.apply(attributes, value); return this; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java index b5907f5..f38b266 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/IfComponentBuilder.java @@ -51,13 +51,13 @@ public class IfComponentBuilder extends ExecutableBuilder{ } public PipelineBuilder then(Executable executable) { - Component execute = super.newAdapter(executable); + Component execute = super.asComponent(executable); return this.then(execute, null); } public PipelineBuilder then(Executable executable, Executable otherwise) { - Component execute = super.newAdapter(executable); - Component component = otherwise != null ? super.newAdapter(otherwise) : null; + Component execute = super.asComponent(executable); + Component component = otherwise != null ? super.asComponent(otherwise) : null; return then(execute, component); } @@ -74,8 +74,8 @@ public class IfComponentBuilder extends ExecutableBuilder{ } public Component build(Executable executable, Executable otherwise) { - Component execute = super.newAdapter(executable); - Component component = otherwise != null ? super.newAdapter(otherwise) : null; + Component execute = super.asComponent(executable); + Component component = otherwise != null ? super.asComponent(otherwise) : null; return this.build(execute, component); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java index 2fc6a76..a7df4cc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/PipelineBuilder.java @@ -60,8 +60,8 @@ public class PipelineBuilder { return new IfComponentBuilder<>(this, condition); } - public PipelineBuilder adapter(Adapter adapter, Component component) { - return this.next(new AdapterBuilder(adapter, component).build()); + public PipelineBuilder adapter(Adapter adapter, Component component) { + return this.next(new AdapterBuilder<>(adapter, component).build()); } public ChooseBuilder choose(Condition condition) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/common/Pair.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/Pair.java new file mode 100644 index 0000000..4ef734d --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/Pair.java @@ -0,0 +1,39 @@ +package org.smartboot.flow.core.common; + +import java.io.Serializable; + +/** + * @author qinluo + * @date 2022/12/7 21:14 + * @since 1.0.0 + */ +public class Pair implements Serializable { + + private static final long serialVersionUID = -6226657512890578902L; + + private T left; + private S right; + + public static Pair of(T left, S right) { + Pair pair = new Pair<>(); + pair.left = left; + pair.right = right; + return pair; + } + + public T getLeft() { + return left; + } + + public void setLeft(T left) { + this.left = left; + } + + public S getRight() { + return right; + } + + public void setRight(S right) { + this.right = right; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index e2c1b70..69c2277 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -1,8 +1,8 @@ package org.smartboot.flow.core.component; -import com.sun.tools.javac.util.Pair; import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.common.Pair; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -12,31 +12,23 @@ import org.smartboot.flow.core.visitor.ComponentVisitor; * @author huqiang * @since 2022/12/7 19:01 */ -public class AdapterComponent extends Component { +public class AdapterComponent extends Component { /** * 业务适配器接口定义 */ - private Adapter adapter; + private Adapter adapter; /** * 待执行的适配流程组件 */ - private Component component; + private Component component; - public Adapter getAdapter() { - return this.adapter; - } - - public Component getComponent() { - return this.component; - } - - public void setAdapter(Adapter adapter) { + public void setAdapter(Adapter adapter) { this.adapter = adapter; } - public void setComponent(Component component) { + public void setComponent(Component component) { this.component = component; } @@ -46,8 +38,11 @@ public class AdapterComponent extends Component { } @Override - public void rollback(EngineContext context) { - component.rollback(context); + public void rollback(EngineContext context) { + Pair pair = adapter.before(context); + AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); + EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); + component.rollback(newContext); } @Override @@ -57,10 +52,10 @@ public class AdapterComponent extends Component { } @Override - public int invoke(EngineContext context) throws Exception { - Pair pair = adapter.before(context); + public int invoke(EngineContext context) throws Exception { + Pair pair = adapter.before(context); AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); - EngineContext newContext = context.newContext(pair.fst, pair.snd); + EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); int invoke = 1; try { invoke = component.invoke(newContext); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index 99ad04b..9a6b910 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -137,7 +137,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { // resolve value type. builder.apply(p.getAttribute(), p.getValue()); }); - Component component = builder.newAdapter((Executable) newInstance(ed.getExecute())); + Component component = builder.asComponent((Executable) newInstance(ed.getExecute())); namedComponents.put(ed.getIdentifier(), component); } diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java index bd5e9cf..8286a5a 100644 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java @@ -1,22 +1,22 @@ package org.smartboot.flow.example; -import com.sun.tools.javac.util.Pair; import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.common.Pair; /** * @author huqiang * @since 2022/12/7 19:54 */ -public class AdapterTest implements Adapter { +public class AdapterTest implements Adapter { @Override - public Pair before(EngineContext context) { + public Pair before(EngineContext context) { return Pair.of("req", "response"); } @Override - public void after(EngineContext origin, EngineContext newContext) { + public void after(EngineContext origin, EngineContext newContext) { System.out.println("origin req = " + origin.getReq() + ", origin response = " + origin.getResult()); System.out.println("req=" + newContext.getReq() + ", response=" + newContext.getResult()); } diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index f9c86be..710e014 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -179,7 +179,7 @@ public class EngineTest { PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); - PipelineBuilder adapterPipelineBuilder = new PipelineBuilder(pipelineBuilder, "adapter process"); + PipelineBuilder adapterPipelineBuilder = new PipelineBuilder<>("adapter process"); adapterPipelineBuilder.next(new NewStep1()).next(new NewStep1()); ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); @@ -190,7 +190,7 @@ public class EngineTest { pipelineBuilder.next(new Step1()).next(new Step2()) .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - .adapter(new AdapterTest(), new PipelineComponent(adapterPipelineBuilder.build())); + .adapter(new AdapterTest(), new PipelineComponent<>(adapterPipelineBuilder.build())); EngineContext context = new EngineContext<>(); -- Gitee From a1f18d56c1d58b50aa2c44817fdce14712b4b192 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 7 Dec 2022 22:33:54 +0800 Subject: [PATCH 21/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/smartboot/flow/core/AsyncCallResult.java | 2 +- .../src/main/java/org/smartboot/flow/core/Pipeline.java | 2 +- .../src/test/java/org/smartboot/flow/example/EngineTest.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index 06a273f..3082775 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -61,7 +61,7 @@ public class AsyncCallResult { this.future.get(this.timeout, TimeUnit.MILLISECONDS); } catch (Throwable e) { if (source.isDegradable()) { - context.broken(false); + EngineContext.LOGGER.warn("degrade component {}", source.getName(), e); } else { EngineContext.LOGGER.error("wait component async-execute failed {}", source.describe(), e); context.setFatal(e); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index b9d8457..956d257 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -94,7 +94,7 @@ public class Pipeline implements Rollback, Describable, Validator, M component.invoke(context); } catch (Throwable e) { if (component.isDegradable()) { - context.broken(false); + EngineContext.LOGGER.warn("degrade component {}", component.getName(), e); } else { EngineContext.LOGGER.error("execute component failed {}", component.describe(), e); context.setFatal(e); diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index 710e014..81c7276 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -190,7 +190,8 @@ public class EngineTest { pipelineBuilder.next(new Step1()).next(new Step2()) .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - .adapter(new AdapterTest(), new PipelineComponent<>(adapterPipelineBuilder.build())); + .adapter(new AdapterTest(), new PipelineComponent<>(adapterPipelineBuilder.build())) + .next(new Step3()); EngineContext context = new EngineContext<>(); -- Gitee From 35efe02f10de95f508b51381005df097e1b60e6d Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 8 Dec 2022 09:32:28 +0800 Subject: [PATCH 22/54] qinluo: - optimize --- .../src/main/java/org/smartboot/flow/core/Pipeline.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index 956d257..607b0dc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -88,8 +88,8 @@ public class Pipeline implements Rollback, Describable, Validator, M } private int executeComponent(Component component, - EngineContext context, - List> executed) { + EngineContext context, + List> executed) { try { component.invoke(context); } catch (Throwable e) { -- Gitee From 19595bfd874aa2300abbf46d51a63fd0fd626984 Mon Sep 17 00:00:00 2001 From: huqiang Date: Thu, 8 Dec 2022 12:01:26 +0800 Subject: [PATCH 23/54] support adapter xml parser --- .../core/parser/AdapterElementParser.java | 39 ++++++++++++++++++ .../core/parser/BuilderDefinitionVisitor.java | 21 ++++++++++ .../flow/core/parser/DefinitionVisitor.java | 6 ++- .../core/parser/ElementParserRegistry.java | 1 + .../flow/core/parser/ParseConstants.java | 1 + .../flow/core/parser/ParserContext.java | 1 + .../parser/definition/AdapterDefinition.java | 40 +++++++++++++++++++ .../src/main/resources/smart-flow-1.0.1.xsd | 19 +++++++++ .../src/main/resources/flow-example7.xsd | 6 +++ .../smartboot/flow/example/EngineTest.java | 5 ++- .../extension/BeanDefinitionVisitor.java | 26 ++++++++++++ 11 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/AdapterDefinition.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java new file mode 100644 index 0000000..98b1418 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java @@ -0,0 +1,39 @@ +package org.smartboot.flow.core.parser; + +import org.smartboot.flow.core.parser.definition.AdapterDefinition; +import org.smartboot.flow.core.parser.definition.ElementDefinition; +import org.smartboot.flow.core.util.AssertUtil; +import org.w3c.dom.Element; + +import java.util.List; + +/** + * @author huqiang + * @since 2022/12/8 11:08 + */ +public class AdapterElementParser extends AbstractElementParser{ + @Override + public String getElementName() { + return ParseConstants.ADAPTER; + } + + @Override + public void doParse(Element element, ParserContext context) { + AdapterDefinition definition = new AdapterDefinition(); + String identifier = getIdentifier(element, context); + + // Check has any elements. + List elements = ElementUtils.subElements(element); + AssertUtil.isTrue(elements.size() != 0, "[adapter] element's sub elements must not be empty"); + + definition.setName(element.getAttribute(ParseConstants.NAME)); + definition.setExecute(element.getAttribute(ParseConstants.EXECUTE)); + definition.setIdentifier(identifier); + definition.getAttributes().addAll(ElementUtils.extraAttributes(element)); + + ElementDefinition def = parseElementsAsPipeline(element, context); + definition.setPipelineElement(def); + context.register(definition); + + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index 9a6b910..251e33e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -1,16 +1,20 @@ package org.smartboot.flow.core.parser; +import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.Condition; import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.builder.AdapterBuilder; import org.smartboot.flow.core.builder.ChooseBuilder; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.IfComponentBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; +import org.smartboot.flow.core.component.AdapterComponent; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.PipelineComponent; import org.smartboot.flow.core.executable.Executable; +import org.smartboot.flow.core.parser.definition.AdapterDefinition; import org.smartboot.flow.core.parser.definition.ChooseDefinition; import org.smartboot.flow.core.parser.definition.ElementDefinition; import org.smartboot.flow.core.parser.definition.EngineDefinition; @@ -228,6 +232,23 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { this.namedComponents.put(ed.getIdentifier(), build); } + @Override + public void visit(AdapterDefinition ed) { + String execute = ed.getExecute(); + Object adapter; + if (AuxiliaryUtils.isType(execute)) { + adapter = newInstance(execute); + } else { + adapter = ed.getContext().getRegistered(execute); + } + AssertUtil.notNull(adapter, "can't find adapter , execute=" + execute); + + ed.getPipelineElement().visit(this); + Component component = namedComponents.get(ed.getPipelineElement().getIdentifier()); + AdapterComponent adapterComponent = new AdapterBuilder((Adapter) adapter, component).build(); + this.namedComponents.put(ed.getIdentifier(), adapterComponent); + } + /** * Return all parsed engine names. * diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefinitionVisitor.java index 229db01..aa76f68 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefinitionVisitor.java @@ -1,5 +1,6 @@ package org.smartboot.flow.core.parser; +import org.smartboot.flow.core.parser.definition.AdapterDefinition; import org.smartboot.flow.core.parser.definition.ChooseDefinition; import org.smartboot.flow.core.parser.definition.ElementDefinition; import org.smartboot.flow.core.parser.definition.EngineDefinition; @@ -37,8 +38,11 @@ public interface DefinitionVisitor { void visit(PipelineComponentDefinition ed); - void visitBasic(ElementDefinition ed); + void visit(IfElementDefinition ed); + void visit(ChooseDefinition ed); + + void visit(AdapterDefinition adapterDefinition); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java index 30262cf..250a95b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ElementParserRegistry.java @@ -20,6 +20,7 @@ public class ElementParserRegistry { this.register("choose", new ChooseElementParser()); this.register("engine", new EngineElementParser()); this.register("script", new ScriptElementParser()); + this.register("adapter", new AdapterElementParser()); } public static ElementParserRegistry getInstance() { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java index 1dc3fed..2689c8d 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseConstants.java @@ -15,6 +15,7 @@ public interface ParseConstants { String IF = "if"; String CHOOSE = "choose"; String COMPONENT = "component"; + String ADAPTER = "adapter"; String SCRIPT = "script"; /** diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java index 4ba8b5c..d15e1ed 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParserContext.java @@ -26,6 +26,7 @@ public class ParserContext { ALLOWED.add(ParseConstants.IF); ALLOWED.add(ParseConstants.CHOOSE); ALLOWED.add(ParseConstants.COMPONENT); + ALLOWED.add(ParseConstants.ADAPTER); } /** diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/AdapterDefinition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/AdapterDefinition.java new file mode 100644 index 0000000..6a91dc0 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/definition/AdapterDefinition.java @@ -0,0 +1,40 @@ +package org.smartboot.flow.core.parser.definition; + +import org.smartboot.flow.core.component.AdapterComponent; +import org.smartboot.flow.core.parser.DefinitionVisitor; +import org.smartboot.flow.core.util.AssertUtil; + +/** + * 适配器定义 + * + * @author huqiang + * @since 2022/12/8 10:58 + */ +public class AdapterDefinition extends ElementDefinition { + + private ElementDefinition pipelineElement; + + public ElementDefinition getPipelineElement() { + return this.pipelineElement; + } + + public void setPipelineElement(ElementDefinition pipelineElement) { + this.pipelineElement = pipelineElement; + } + + @Override + public void validate() { + AssertUtil.notBlank(getExecute(), " attribute[execute] must not be null"); + AssertUtil.notNull(pipelineElement, "pipeline children must not be empty"); + } + + @Override + public Class resolveType() { + return AdapterComponent.class; + } + + @Override + protected void visit0(DefinitionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 9b41b96..918682c 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -143,6 +143,7 @@ + @@ -179,6 +180,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd index ecb79d1..dd76941 100644 --- a/smart-flow-example/src/main/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -10,6 +10,12 @@ + + + + + + diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index 81c7276..c48874d 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -219,7 +219,10 @@ public class EngineTest { .choose(new ChooseCondition()) .newBranch("null", new NullStep()) .newBranch(1, new IntegerStep()).end(new DefaultStep()) - .pipeline("subprocess").next(new Step4()).next(new ErrorStep()).end(); + .pipeline("subprocess") + .next(new Step4()) + .next(new ErrorStep()) + .end(); EngineContext context = new EngineContext<>(); diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index d0a1d6b..2e51ec3 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -4,6 +4,7 @@ import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.parser.DefinitionVisitor; import org.smartboot.flow.core.parser.ParserContext; +import org.smartboot.flow.core.parser.definition.AdapterDefinition; import org.smartboot.flow.core.parser.definition.ChooseDefinition; import org.smartboot.flow.core.parser.definition.ElementDefinition; import org.smartboot.flow.core.parser.definition.EngineDefinition; @@ -282,4 +283,29 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); register.registerBeanDefinition(ed.getIdentifier(), definition); } + + @Override + public void visit(AdapterDefinition ed) { + RootBeanDefinition definition = new RootBeanDefinition(); + PropertyValue name = new PropertyValue("name", ed.getName()); + + definition.setBeanClass(ed.resolveType()); + definition.getPropertyValues().addPropertyValue(name); + + if (isType(ed.getExecute())) { + RootBeanDefinition adapterDef = new RootBeanDefinition(); + adapterDef.setBeanClassName(ed.getExecute()); + definition.getPropertyValues().add("adapter", adapterDef); + } else { + AssertUtil.notNull(ed.getExecute(), "adapter[execute] must not be null"); + definition.getPropertyValues().add("adapter", new RuntimeBeanReference(ed.getExecute())); + } + + ed.getPipelineElement().visit(this); + BeanDefinition beanDefinition = registry.getBeanDefinition(ed.getPipelineElement().getIdentifier()); + definition.getPropertyValues().add("component", beanDefinition); + + + + } } -- Gitee From 4f79a765b2499db6b260524f526ae094acc49797 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 8 Dec 2022 14:29:09 +0800 Subject: [PATCH 24/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=99=A8=E7=94=9F=E6=88=90=E5=9B=BE=E5=83=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/core/builder/AdapterBuilder.java | 16 ++++++++-------- .../flow/core/common/ComponentType.java | 1 + .../flow/core/component/AdapterComponent.java | 5 ++++- .../core/parser/BuilderDefinitionVisitor.java | 9 ++++++++- .../core/view/plantuml/PlantumlComponent.java | 16 ++++++++++++---- .../view/plantuml/PlantumlComponentVisitor.java | 2 ++ .../view/plantuml/PlantumlPipelineVisitor.java | 3 +++ 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java index 816021d..74fa9ff 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java @@ -10,20 +10,20 @@ import org.smartboot.flow.core.component.Component; */ public class AdapterBuilder extends ExecutableBuilder { - private Adapter adapter; + private final Adapter adapter; - private Component component; - - private AdapterComponent adapterComponent; + private final Component component; public AdapterBuilder(Adapter adapter, Component component) { - adapterComponent = new AdapterComponent<>(); - adapterComponent.setAdapter(adapter); - adapterComponent.setComponent(component); - applyValues(adapterComponent); + this.adapter = adapter; + this.component = component; } public AdapterComponent build() { + AdapterComponent adapterComponent = new AdapterComponent<>(); + adapterComponent.setAdapter(adapter); + adapterComponent.setComponent(component); + applyValues(adapterComponent); return adapterComponent; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java index 51c5149..942b9f2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/common/ComponentType.java @@ -10,5 +10,6 @@ public enum ComponentType { IF, CHOOSE, PIPELINE, + ADAPTER, } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 69c2277..3692e6c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -53,6 +53,7 @@ public class AdapterComponent extends Component { @Override public int invoke(EngineContext context) throws Exception { + context.enter(this); Pair pair = adapter.before(context); AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); @@ -64,12 +65,14 @@ public class AdapterComponent extends Component { context.setRollback(newContext.getRollback()); context.broken(newContext.isBroken()); } + context.exit(this); adapter.after(context, newContext); return invoke; } @Override public void visit(ComponentVisitor visitor) { - visitor.visitComponent(this); + ComponentVisitor componentVisitor = visitor.visitComponent(component); + component.visit(componentVisitor); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index 251e33e..a46856e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -245,7 +245,14 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { ed.getPipelineElement().visit(this); Component component = namedComponents.get(ed.getPipelineElement().getIdentifier()); - AdapterComponent adapterComponent = new AdapterBuilder((Adapter) adapter, component).build(); + + AdapterBuilder adapterBuilder = new AdapterBuilder((Adapter) adapter, component); + ed.getAttributes().forEach(p -> { + // resolve value type. + adapterBuilder.apply(p.getAttribute(), p.getValue()); + }); + + AdapterComponent adapterComponent = adapterBuilder.build(); this.namedComponents.put(ed.getIdentifier(), adapterComponent); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index ffc7dad..bba5d5e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -101,8 +101,9 @@ public class PlantumlComponent { public void generate(StringBuilder content) { String nodeName = AuxiliaryUtils.isBlank(name) ? describe : name; + ComponentType type = getType(); - if (getType() == ComponentType.BASIC) { + if (type == ComponentType.BASIC) { String serialAttributes = serialAttributes(); content.append(getColor()).append(":").append(nodeName).append(";\n"); @@ -111,7 +112,7 @@ public class PlantumlComponent { .append("\nend note\n"); } - } else if (getType() == ComponentType.IF) { + } else if (type == ComponentType.IF) { content.append("if (").append(condition).append(") then (true)\n"); components.get(0).generate(content); if (components.size() >= 2) { @@ -120,7 +121,7 @@ public class PlantumlComponent { } content.append("endif\n"); - } else if (getType() == ComponentType.CHOOSE) { + } else if (type == ComponentType.CHOOSE) { content.append("switch (").append(condition).append(")\n"); for (PlantumlComponent component : components) { @@ -134,10 +135,17 @@ public class PlantumlComponent { content.append("endswitch\n"); - } else if (getType() == ComponentType.PIPELINE) { + } else if (type == ComponentType.PIPELINE) { content.append("partition 子流程:").append(pipeline.getName()).append("{ \n"); pipeline.generate(content); content.append(" } \n"); + } else if (type == ComponentType.ADAPTER) { + PlantumlComponent pipeline = components.get(0); + content.append("partition 适配器:").append(nodeName) + .append(" 子流程:") + .append(pipeline.pipeline.getName()).append("{ \n"); + pipeline.pipeline.generate(content); + content.append(" } \n"); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java index fcc795b..802ddbb 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core.view.plantuml; import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.component.AdapterComponent; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; @@ -39,6 +40,7 @@ public class PlantumlComponentVisitor extends ComponentVisitor { @Override public ComponentVisitor visitComponent(Component comp) { PlantumlComponent component = new PlantumlComponent(comp.getName(), comp.describe()); + component.setType(comp instanceof AdapterComponent ? ComponentType.ADAPTER : null); this.plantumlComponent.addComponent(component); return new PlantumlComponentVisitor(component); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java index 5919ddc..a9df19a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java @@ -1,5 +1,7 @@ package org.smartboot.flow.core.view.plantuml; +import org.smartboot.flow.core.common.ComponentType; +import org.smartboot.flow.core.component.AdapterComponent; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; @@ -20,6 +22,7 @@ public class PlantumlPipelineVisitor extends PipelineVisitor { @Override public ComponentVisitor visitComponent(Component comp) { PlantumlComponent component = new PlantumlComponent(comp.getName(), comp.describe()); + component.setType(comp instanceof AdapterComponent ? ComponentType.ADAPTER : null); this.pipeline.addComponent(component); return new PlantumlComponentVisitor(component); } -- Gitee From 549fe7b00acb70d0c171d9ce3e49513f52b1372d Mon Sep 17 00:00:00 2001 From: huqiang Date: Thu, 8 Dec 2022 14:35:02 +0800 Subject: [PATCH 25/54] support adapter xml parser --- smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd | 4 ++-- smart-flow-example/src/main/resources/bean.xml | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 918682c..5e3c67e 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -191,8 +191,8 @@ - - + + diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml index 8e82f14..aeb26f1 100644 --- a/smart-flow-example/src/main/resources/bean.xml +++ b/smart-flow-example/src/main/resources/bean.xml @@ -42,6 +42,11 @@ + + + + + -- Gitee From f8af1e5d4d134e02d60379a56535ceb5692d69d9 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 8 Dec 2022 14:41:36 +0800 Subject: [PATCH 26/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20spring=20ada?= =?UTF-8?q?pter=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/spring/extension/BeanDefinitionVisitor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index 2e51ec3..7de8af4 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -302,10 +302,11 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } ed.getPipelineElement().visit(this); - BeanDefinition beanDefinition = registry.getBeanDefinition(ed.getPipelineElement().getIdentifier()); - definition.getPropertyValues().add("component", beanDefinition); + BeanDefinition beanDefinition = register.getBeanDefinition(ed.getPipelineElement().getIdentifier()); + definition.getPropertyValues().add("component", beanDefinition); + register.registerBeanDefinition(ed.getIdentifier(), definition); } } -- Gitee From caaa422912770807fa152745c9b7276d8e985d97 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 8 Dec 2022 16:32:44 +0800 Subject: [PATCH 27/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/AsyncCallResult.java | 23 +++- .../smartboot/flow/core/EngineContext.java | 25 ++++- .../org/smartboot/flow/core/FlowEngine.java | 2 + .../org/smartboot/flow/core/Pipeline.java | 63 +++++++---- .../flow/core/component/AdapterComponent.java | 8 +- .../flow/core/component/ChooseComponent.java | 3 +- .../flow/core/component/IfComponent.java | 3 +- .../flow/core/invoker/AsyncRunner.java | 29 +++++ .../flow/core/invoker/InvokeListener.java | 14 +++ .../flow/core/invoker/InvokeListeners.java | 44 ++++++++ .../smartboot/flow/core/invoker/Invoker.java | 105 ++++++++++++++++++ .../flow/core/invoker/TransparentContext.java | 73 ++++++++++++ .../core/parser/BuilderDefinitionVisitor.java | 2 +- .../smartboot/flow/example/AsyncStep4.java | 25 +++++ ...flow-example-subprocess-non-degradable.xsd | 40 +++++++ .../example/parser/DefaultParserTest.java | 18 +++ 16 files changed, 442 insertions(+), 35 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListener.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListeners.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java create mode 100644 smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index 3082775..d521289 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -1,6 +1,8 @@ package org.smartboot.flow.core; import org.smartboot.flow.core.component.Component; +import org.smartboot.flow.core.invoker.InvokeListener; +import org.smartboot.flow.core.invoker.TransparentContext; import java.util.ArrayList; import java.util.List; @@ -18,7 +20,12 @@ public class AsyncCallResult { private long timeout; private Future future; private Component source; - private final List> belongs = new ArrayList<>(0); + private final List belongs = new ArrayList<>(0); + private final List listeners = new ArrayList<>(); + + public List getListeners() { + return listeners; + } public String getName() { return name; @@ -52,7 +59,7 @@ public class AsyncCallResult { this.source = source; } - public void setBelongs(List> belongs) { + public void setBelongs(List belongs) { this.belongs.addAll(belongs); } @@ -60,7 +67,7 @@ public class AsyncCallResult { try { this.future.get(this.timeout, TimeUnit.MILLISECONDS); } catch (Throwable e) { - if (source.isDegradable()) { + if (source.isDegradable() || ctx.getDegradable()) { EngineContext.LOGGER.warn("degrade component {}", source.getName(), e); } else { EngineContext.LOGGER.error("wait component async-execute failed {}", source.describe(), e); @@ -69,10 +76,14 @@ public class AsyncCallResult { context.broken(true); } } finally { - if (source.isRollbackable(context) && !belongs.contains(source)) { - belongs.add(source); - } + listeners.forEach(listener -> listener.onCompleted(source, context)); } } + + private TransparentContext ctx; + + public void setTransparentContext(TransparentContext ctx) { + this.ctx = ctx; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 69e1e92..687392a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.exception.ExceptionHandler; +import org.smartboot.flow.core.invoker.Invoker; import org.smartboot.flow.core.trace.Tracer; import java.io.Serializable; @@ -37,6 +38,7 @@ public class EngineContext implements Cloneable{ private final Map asyncInvokes = new ConcurrentHashMap<>(); private String engineName; ExecutionListener listener; + private Invoker invoker; /** * 执行状态 */ @@ -65,6 +67,14 @@ public class EngineContext implements Cloneable{ return tracer.getTrace(); } + public Invoker getInvoker() { + return invoker; + } + + public void setInvoker(Invoker invoker) { + this.invoker = invoker; + } + public boolean getRollback() { return rollback; } @@ -137,7 +147,15 @@ public class EngineContext implements Cloneable{ this.engineName = engineName; } - public void addAsyncInvoke(Component component, Future future, List> belongs) { + public ExecutorService getExecutor() { + return executor; + } + + public void setExecutor(ExecutorService executor) { + this.executor = executor; + } + + public void addAsyncInvoke(Component component, Future future, List belongs) { AsyncCallResult result = new AsyncCallResult<>(); result.setFuture(future); result.setName(component.getName()); @@ -147,6 +165,10 @@ public class EngineContext implements Cloneable{ this.asyncInvokes.put(component.getName(), result); } + public void addAsyncInvoke(AsyncCallResult result) { + this.asyncInvokes.put(result.getName(), result); + } + public AsyncCallResult getAsyncCall(String name) { return this.asyncInvokes.get(name); } @@ -212,6 +234,7 @@ public class EngineContext implements Cloneable{ this.listener = null; this.engineName = null; this.executing = DISABLED; + this.executor = null; } private static class Value implements Serializable { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java index 3c6a802..88f794f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core; import org.smartboot.flow.core.exception.DefaultExceptionHandler; import org.smartboot.flow.core.exception.ExceptionHandler; +import org.smartboot.flow.core.invoker.Invoker; import org.smartboot.flow.core.manager.DefaultEngineManager; import org.smartboot.flow.core.metrics.MetricExecutionListener; import org.smartboot.flow.core.util.AssertUtil; @@ -95,6 +96,7 @@ public class FlowEngine implements Describable, Validator, Measurable { context.executor = executor; context.setEngineName(this.name); context.setExecuting(EngineContext.EXECUTING); + context.setInvoker(new Invoker()); // Execution Listener. ExecutionListeners listeners = new ExecutionListeners(ExecutionListenerRegistry.getRegistered()); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index 607b0dc..ac03836 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -1,7 +1,10 @@ package org.smartboot.flow.core; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.component.Component; +import org.smartboot.flow.core.invoker.InvokeListener; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; @@ -17,6 +20,8 @@ import java.util.concurrent.Future; */ public class Pipeline implements Rollback, Describable, Validator, Measurable { + private static final Logger LOGGER = LoggerFactory.getLogger(Pipeline.class); + private final List> components = new ArrayList<>(); private String name; @@ -31,7 +36,7 @@ public class Pipeline implements Rollback, Describable, Validator, M public void execute(EngineContext context) throws Exception { // Executed sequences. - List> executed = new ArrayList<>(); + List executed = new ArrayList<>(); context.putExt(Key.of(this), executed); // Enter record track @@ -42,28 +47,38 @@ public class Pipeline implements Rollback, Describable, Validator, M break; } - // component is disabled. - if (!component.isEnabled()) { - continue; - } - - // Ensure async dependencies are called and finished. - ensureAllDependsExecuted(component, context); - - // Compatible-check after ensureAllDependsExecuted called. - if (context.isBroken()) { - break; - } - - if (component.isAsync()) { - AssertUtil.notNull(context.executor, "executor must not be null"); - - Future submitted = context.executor.submit(() -> executeComponent(component, context, executed)); - context.addAsyncInvoke(component, submitted, executed); - continue; - } - - executeComponent(component, context, executed); + context.getInvoker().invoke(context, component, new InvokeListener() { + @Override + public void onCompleted(Component component, EngineContext context) { + // rollback + if (component.isRollbackable(context) && !executed.contains(component)) { + executed.add(component); + } + } + }); + +// // component is disabled. +// if (!component.isEnabled()) { +// continue; +// } +// +// // Ensure async dependencies are called and finished. +// ensureAllDependsExecuted(component, context); +// +// // Compatible-check after ensureAllDependsExecuted called. +// if (context.isBroken()) { +// break; +// } +// +// if (component.isAsync()) { +// AssertUtil.notNull(context.executor, "executor must not be null"); +// +// Future submitted = context.executor.submit(() -> executeComponent(component, context, executed)); +// context.addAsyncInvoke(component, submitted, executed); +// continue; +// } +// +// executeComponent(component, context, executed); } // Exit record track @@ -89,7 +104,7 @@ public class Pipeline implements Rollback, Describable, Validator, M private int executeComponent(Component component, EngineContext context, - List> executed) { + List executed) { try { component.invoke(context); } catch (Throwable e) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 3692e6c..43f9104 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -45,6 +45,11 @@ public class AdapterComponent extends Component { component.rollback(newContext); } + @Override + public boolean isRollbackable(EngineContext context) { + return true; + } + @Override public void validate() { AssertUtil.notNull(adapter, "adapter[" + getName() + "] adapter must not be null"); @@ -59,7 +64,8 @@ public class AdapterComponent extends Component { EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); int invoke = 1; try { - invoke = component.invoke(newContext); +// invoke = component.invoke(newContext); + invoke = context.getInvoker().invoke(newContext, component); } finally { context.setFatal(newContext.getFatal()); context.setRollback(newContext.getRollback()); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java index 4e4563e..3fc5aca 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java @@ -71,7 +71,8 @@ public class ChooseComponent extends Component { context.putExt(Key.of(this), execute); context.enter("branch##" + branch); try { - return execute.invoke(context); +// return execute.invoke(context); + return context.getInvoker().invoke(context, execute); } finally { context.exit("branch##" + branch); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java index e04fa63..751de54 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java @@ -53,7 +53,8 @@ public class IfComponent extends Component{ if (execute != null) { context.putExt(Key.of(this), execute); - return execute.invoke(context); +// return execute.invoke(context); + return context.getInvoker().invoke(context, execute); } } finally { context.exit(this); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java new file mode 100644 index 0000000..ac4b2ae --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java @@ -0,0 +1,29 @@ +package org.smartboot.flow.core.invoker; + +import java.util.concurrent.Callable; + +/** + * @author qinluo + * @date 2022-12-07 21:57:39 + * @since 1.0.0 + */ +public class AsyncRunner implements Callable { + + private final boolean degradable; + private final Callable task; + + public AsyncRunner(boolean degradable, Callable task) { + this.degradable = degradable; + this.task = task; + } + + @Override + public Integer call() throws Exception { + TransparentContext.enter(degradable); + try { + return task.call(); + } finally { + TransparentContext.exit(); + } + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListener.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListener.java new file mode 100644 index 0000000..545f461 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListener.java @@ -0,0 +1,14 @@ +package org.smartboot.flow.core.invoker; + +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.component.Component; + +/** + * @author qinluo + * @date 2022-12-07 21:28:41 + * @since 1.0.0 + */ +public interface InvokeListener { + + void onCompleted(Component component, EngineContext context); +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListeners.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListeners.java new file mode 100644 index 0000000..f4e9f26 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/InvokeListeners.java @@ -0,0 +1,44 @@ +package org.smartboot.flow.core.invoker; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.component.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author qinluo + * @date 2022-12-07 21:37:59 + * @since 1.0.0 + */ +public class InvokeListeners implements InvokeListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(InvokeListeners.class); + + private final List invokeListeners; + + public InvokeListeners(InvokeListener ...invokeListeners) { + if (invokeListeners == null || invokeListeners.length == 0) { + this.invokeListeners = new ArrayList<>(0); + } else { + this.invokeListeners = Stream.of(invokeListeners).filter(Objects::nonNull).collect(Collectors.toList()); + } + } + + @Override + public void onCompleted(Component component, EngineContext context) { + for (InvokeListener listener : invokeListeners) { + + try { + listener.onCompleted(component, context); + } catch (Exception e) { + LOGGER.warn("invoke listener failed, listener = {}", listener.getClass().getName(), e); + } + } + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java new file mode 100644 index 0000000..7db63ef --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java @@ -0,0 +1,105 @@ +package org.smartboot.flow.core.invoker; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.AsyncCallResult; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.component.Component; +import org.smartboot.flow.core.util.AssertUtil; + +import java.util.concurrent.Future; + +/** + * @author qinluo + * @date 2022-12-07 20:37:25 + * @since 1.0.0 + */ +public class Invoker { + + private static final Logger LOGGER = LoggerFactory.getLogger(Invoker.class); + + public int invoke(EngineContext context, Component component, InvokeListener ...listeners) { + if (context.isBroken()) { + return -1; + } + + // component is disabled. + if (!component.isEnabled()) { + LOGGER.warn("component {} disabled in engine {}", component.describe(), context.getEngineName()); + return 1; + } + + // Ensure async dependencies are called and finished. + ensureAllDependsExecuted(component, context); + + // Compatible-check after ensureAllDependsExecuted called. + if (context.isBroken()) { + return -1; + } + + TransparentContext.enter(component.isDegradable()); + + try { + InvokeListener listener = new InvokeListeners(listeners); + if (component.isAsync()) { + AssertUtil.notNull(context.getExecutor(), "executor must not be null"); + TransparentContext ctx = TransparentContext.current(); + + AsyncRunner runner = new AsyncRunner(ctx.getDegradable(), () -> execute(component, context, listener)); + Future submitted = context.getExecutor().submit(runner); + AsyncCallResult result = new AsyncCallResult<>(); + result.setFuture(submitted); + result.setName(component.getName()); + result.setTimeout(component.getTimeout()); + result.setSource(component); + result.getListeners().add(listener); + result.setTransparentContext(ctx); + context.addAsyncInvoke(result); + return 1; + } + + return execute(component, context, listener); + } finally { + TransparentContext.exit(); + } + } + + private int execute(Component component, + EngineContext context, + InvokeListener listeners) { + try { + component.invoke(context); + } catch (Throwable e) { + if (component.isDegradable() || TransparentContext.current().getDegradable()) { + LOGGER.warn("degrade component {}", component.getName(), e); + } else { + LOGGER.error("execute component failed {}", component.describe(), e); + context.setFatal(e); + context.setRollback(true); + context.broken(true); + } + } finally { + // rollback + listeners.onCompleted(component, context); + } + + return 1; + } + + private void ensureAllDependsExecuted(Component component, EngineContext context) { + for (String depends : component.getDependsOn()) { + AsyncCallResult asyncCall = context.getAsyncCall(depends); + if (asyncCall == null) { + EngineContext.LOGGER.warn("could not find dependsOn call on component {} with dependency {}", component.getName(), depends); + continue; + } + + // Await current future finished. + asyncCall.checkAndWait(context); + if (context.isBroken()) { + break; + } + } + + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java new file mode 100644 index 0000000..b979326 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java @@ -0,0 +1,73 @@ +package org.smartboot.flow.core.invoker; + +import org.smartboot.flow.core.util.AuxiliaryUtils; + +import java.io.Serializable; + +/** + * 用于透传组件上下文传值 + * + * @author qinluo + * @date 2022-12-07 21:47:26 + * @since 1.0.0 + */ +public class TransparentContext implements Serializable { + private static final long serialVersionUID = -3033584753584750611L; + + private static final ThreadLocal CURRENT = new InheritableThreadLocal<>(); + + public static TransparentContext current() { + TransparentContext ctx = CURRENT.get(); + return AuxiliaryUtils.or(ctx, new TransparentContext()); + } + + public static void enter(boolean degradable) { + TransparentContext ctx = CURRENT.get(); + if (ctx == null) { + ctx = new TransparentContext(); + CURRENT.set(ctx); + return; + } + + TransparentContext child = new TransparentContext(); + child.setParent(ctx); + child.setDegradable(degradable || ctx.degradable); + CURRENT.set(child); + } + + public static void exit() { + TransparentContext ctx = CURRENT.get(); + if (ctx == null) { + return; + } + + TransparentContext parent = ctx.getParent(); + if (parent == null) { + return; + } + + CURRENT.set(parent); + } + + /** + * Parent context. + */ + private TransparentContext parent; + private boolean degradable; + + public boolean getDegradable() { + return degradable; + } + + public void setDegradable(boolean degradable) { + this.degradable = degradable; + } + + public TransparentContext getParent() { + return parent; + } + + public void setParent(TransparentContext parent) { + this.parent = parent; + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index a46856e..54802b1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -141,7 +141,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { // resolve value type. builder.apply(p.getAttribute(), p.getValue()); }); - Component component = builder.asComponent((Executable) newInstance(ed.getExecute())); + Component component = builder.newAdapter((Executable) newInstance(ed.getExecute())); namedComponents.put(ed.getIdentifier(), component); } diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java new file mode 100644 index 0000000..ca36ea9 --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java @@ -0,0 +1,25 @@ +package org.smartboot.flow.example; + + +import org.smartboot.flow.core.exception.FlowException; +import org.smartboot.flow.core.executable.AbstractExecutable; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-11 21:44:21 + * @since 1.0.0 + */ +@Service +public class AsyncStep4 extends AbstractExecutable { + + @Override + public void execute(Integer integer, String s) { + try { + Thread.sleep(500); + } catch (Exception e) { + + } + throw new FlowException("async4 failed."); + } +} diff --git a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd new file mode 100644 index 0000000..06b8319 --- /dev/null +++ b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 14ca9ae..4af3207 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -13,6 +13,7 @@ import org.smartboot.flow.core.manager.DefaultEngineManager; import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; import java.io.InputStream; +import java.util.concurrent.Executors; /** * @author qinluo @@ -102,4 +103,21 @@ public class DefaultParserTest { PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); visitor.visit(testEngine); } + + @Test + public void testParseNestedElementsInPipeline4() { + + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/flow-example-subprocess-non-degradable.xsd")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + testEngine.setExecutor(Executors.newSingleThreadExecutor()); + + EngineContext execute = testEngine.execute(1); + LOGGER.info("trace \n{}", execute.getTrace()); + + PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); + visitor.visit(testEngine); + } } -- Gitee From 33b83dcdbcde710368f50af0cbe3c365a78af31a Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 8 Dec 2022 19:21:34 +0800 Subject: [PATCH 28/54] qinluo: - optimized --- .../smartboot/flow/core/AsyncCallResult.java | 15 ++--- .../smartboot/flow/core/EngineContext.java | 18 +----- .../org/smartboot/flow/core/Pipeline.java | 64 ------------------- .../flow/core/builder/AdapterBuilder.java | 8 +++ .../flow/core/component/AdapterComponent.java | 25 +++++--- .../flow/core/component/ChooseComponent.java | 1 - .../flow/core/component/IfComponent.java | 1 - .../smartboot/flow/core/invoker/Invoker.java | 2 +- .../example/builder/AdapterBuilderTest.java | 39 +++++++++++ 9 files changed, 70 insertions(+), 103 deletions(-) create mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index d521289..3b34e2a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -4,8 +4,6 @@ import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.invoker.InvokeListener; import org.smartboot.flow.core.invoker.TransparentContext; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -20,11 +18,10 @@ public class AsyncCallResult { private long timeout; private Future future; private Component source; - private final List belongs = new ArrayList<>(0); - private final List listeners = new ArrayList<>(); + private InvokeListener listeners; - public List getListeners() { - return listeners; + public void setListeners(InvokeListener listeners) { + this.listeners = listeners; } public String getName() { @@ -59,10 +56,6 @@ public class AsyncCallResult { this.source = source; } - public void setBelongs(List belongs) { - this.belongs.addAll(belongs); - } - public void checkAndWait(EngineContext context) { try { this.future.get(this.timeout, TimeUnit.MILLISECONDS); @@ -76,7 +69,7 @@ public class AsyncCallResult { context.broken(true); } } finally { - listeners.forEach(listener -> listener.onCompleted(source, context)); + listeners.onCompleted(source, context); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 687392a..3cb68c8 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -44,12 +44,10 @@ public class EngineContext implements Cloneable{ */ private int executing; - public EngineContext newContext(Object req, Object result) { - EngineContext newContext = new EngineContext<>(); + public EngineContext newContext(P req, Q result) { + EngineContext newContext = new EngineContext<>(); try { - newContext = (EngineContext)this.clone(); - newContext.extensions.putAll(this.extensions); - newContext.asyncInvokes.putAll(this.asyncInvokes); + newContext = (EngineContext)this.clone(); newContext.setReq(req); newContext.setResult(result); } catch (CloneNotSupportedException e) { @@ -155,16 +153,6 @@ public class EngineContext implements Cloneable{ this.executor = executor; } - public void addAsyncInvoke(Component component, Future future, List belongs) { - AsyncCallResult result = new AsyncCallResult<>(); - result.setFuture(future); - result.setName(component.getName()); - result.setTimeout(component.getTimeout()); - result.setSource(component); - result.setBelongs(belongs); - this.asyncInvokes.put(component.getName(), result); - } - public void addAsyncInvoke(AsyncCallResult result) { this.asyncInvokes.put(result.getName(), result); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index ac03836..db69d5f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -56,76 +56,12 @@ public class Pipeline implements Rollback, Describable, Validator, M } } }); - -// // component is disabled. -// if (!component.isEnabled()) { -// continue; -// } -// -// // Ensure async dependencies are called and finished. -// ensureAllDependsExecuted(component, context); -// -// // Compatible-check after ensureAllDependsExecuted called. -// if (context.isBroken()) { -// break; -// } -// -// if (component.isAsync()) { -// AssertUtil.notNull(context.executor, "executor must not be null"); -// -// Future submitted = context.executor.submit(() -> executeComponent(component, context, executed)); -// context.addAsyncInvoke(component, submitted, executed); -// continue; -// } -// -// executeComponent(component, context, executed); } // Exit record track context.exit(this); } - private void ensureAllDependsExecuted(Component component, EngineContext context) { - for (String depends : component.getDependsOn()) { - AsyncCallResult asyncCall = context.getAsyncCall(depends); - if (asyncCall == null) { - EngineContext.LOGGER.warn("could not find dependsOn call on component {} with dependency {}", component.getName(), depends); - continue; - } - - // Await current future finished. - asyncCall.checkAndWait(context); - if (context.isBroken()) { - break; - } - } - - } - - private int executeComponent(Component component, - EngineContext context, - List executed) { - try { - component.invoke(context); - } catch (Throwable e) { - if (component.isDegradable()) { - EngineContext.LOGGER.warn("degrade component {}", component.getName(), e); - } else { - EngineContext.LOGGER.error("execute component failed {}", component.describe(), e); - context.setFatal(e); - context.setRollback(true); - context.broken(true); - } - } finally { - // rollback - if (component.isRollbackable(context)) { - executed.add(component); - } - } - - return 1; - } - @Override public void rollback(EngineContext context) { List> executed = context.getExt(Key.of(this)); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java index 74fa9ff..af38027 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core.builder; import org.smartboot.flow.core.Adapter; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.AdapterComponent; import org.smartboot.flow.core.component.Component; @@ -27,5 +28,12 @@ public class AdapterBuilder extends ExecutableBuilder { return adapterComponent; } + /** + * Resolve return type. + */ + public AdapterBuilder apply(Attributes attributes, Object value) { + super.apply(attributes, value); + return this; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 43f9104..9efc8a7 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -2,6 +2,7 @@ package org.smartboot.flow.core.component; import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.Key; import org.smartboot.flow.core.common.Pair; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -39,17 +40,14 @@ public class AdapterComponent extends Component { @Override public void rollback(EngineContext context) { - Pair pair = adapter.before(context); - AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); + Pair pair = context.getExt(Key.of(this)); + if (pair == null) { + return; + } EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); component.rollback(newContext); } - @Override - public boolean isRollbackable(EngineContext context) { - return true; - } - @Override public void validate() { AssertUtil.notNull(adapter, "adapter[" + getName() + "] adapter must not be null"); @@ -59,19 +57,26 @@ public class AdapterComponent extends Component { @Override public int invoke(EngineContext context) throws Exception { context.enter(this); + + // Convert. Pair pair = adapter.before(context); AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); + + // Store converted objects. + context.putExt(Key.of(this), pair); + EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); - int invoke = 1; + int invoke; try { -// invoke = component.invoke(newContext); invoke = context.getInvoker().invoke(newContext, component); } finally { context.setFatal(newContext.getFatal()); context.setRollback(newContext.getRollback()); context.broken(newContext.isBroken()); + context.exit(this); } - context.exit(this); + + // Apply result to parent context. adapter.after(context, newContext); return invoke; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java index 3fc5aca..14fe2eb 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java @@ -71,7 +71,6 @@ public class ChooseComponent extends Component { context.putExt(Key.of(this), execute); context.enter("branch##" + branch); try { -// return execute.invoke(context); return context.getInvoker().invoke(context, execute); } finally { context.exit("branch##" + branch); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java index 751de54..3f07e89 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java @@ -53,7 +53,6 @@ public class IfComponent extends Component{ if (execute != null) { context.putExt(Key.of(this), execute); -// return execute.invoke(context); return context.getInvoker().invoke(context, execute); } } finally { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java index 7db63ef..6f334c5 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java @@ -52,7 +52,7 @@ public class Invoker { result.setName(component.getName()); result.setTimeout(component.getTimeout()); result.setSource(component); - result.getListeners().add(listener); + result.setListeners(listener); result.setTransparentContext(ctx); context.addAsyncInvoke(result); return 1; diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java new file mode 100644 index 0000000..a22c1c1 --- /dev/null +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java @@ -0,0 +1,39 @@ +package org.smartboot.flow.example.builder; + +import org.junit.jupiter.api.Test; +import org.smartboot.flow.core.Adapter; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.attribute.Attributes; +import org.smartboot.flow.core.builder.AdapterBuilder; +import org.smartboot.flow.core.common.Pair; + +/** + * @author qinluo + * @date 2022-12-08 19:06:06 + * @since 1.0.0 + */ +public class AdapterBuilderTest { + + @Test + public void testAdapterBuilder() { + AdapterBuilder builder + = new AdapterBuilder<>(new Adapter() { + @Override + public Pair before(EngineContext context) { + return null; + } + + @Override + public void after(EngineContext origin, EngineContext newContext) { + + } + + @Override + public String describe() { + return null; + } + }, null); + + builder.apply(Attributes.ASYNC, true); + } +} -- Gitee From d783c7df31194f49a43ffca85a1a12764aadd652 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 9 Dec 2022 09:42:47 +0800 Subject: [PATCH 29/54] qinluo: - optimize xsd --- smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 5e3c67e..b524c73 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -189,6 +189,9 @@ + + + @@ -227,6 +230,7 @@ + @@ -252,6 +256,7 @@ + @@ -298,6 +303,7 @@ + @@ -327,6 +333,7 @@ + -- Gitee From b13930b02a752961d2689559232781e84f22a749 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 9 Dec 2022 11:44:19 +0800 Subject: [PATCH 30/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20bean=20regis?= =?UTF-8?q?ter=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/smartboot/flow/example/ParseTest.java | 2 +- .../extension/BeanDefinitionRegister.java | 25 ++++++++++++++-- .../extension/BeanDefinitionVisitor.java | 30 ++++--------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java index 1185d0d..d88bcf2 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java @@ -34,7 +34,7 @@ public class ParseTest { LOGGER.info("trace\n {}", executeContext.getTrace()); LOGGER.info("========================================================================="); - executeContext = testEngine.execute((Integer) null); + executeContext = testEngine.execute((Integer) 3); LOGGER.info("trace\n {}", executeContext.getTrace()); diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java index 075e45a..ae84494 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java @@ -1,6 +1,7 @@ package org.smartboot.flow.spring.extension; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import java.util.HashMap; import java.util.Map; @@ -14,15 +15,33 @@ public class BeanDefinitionRegister { private final Map registered = new HashMap<>(32); + /** + * Spring registry + */ + private final BeanDefinitionRegistry registry; + + public BeanDefinitionRegister(BeanDefinitionRegistry registry) { + this.registry = registry; + } + public BeanDefinition getBeanDefinition(String identifier) { - return registered.get(identifier); + BeanDefinition beanDefinition = registered.get(identifier); + return beanDefinition != null ? beanDefinition : registry.getBeanDefinition(identifier); } public void registerBeanDefinition(String identifier, BeanDefinition def) { - registered.put(identifier, def); + registerBeanDefinition(identifier, def, false); + } + + public void registerBeanDefinition(String identifier, BeanDefinition def, boolean registerToSpring) { + if (registerToSpring) { + registry.registerBeanDefinition(identifier, def); + } else { + registered.put(identifier, def); + } } public boolean containsBeanDefinition(String identifier) { - return registered.containsKey(identifier); + return registered.containsKey(identifier) || registry.containsBeanDefinition(identifier); } } diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index 7de8af4..205dbd1 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -32,17 +32,16 @@ import java.util.List; */ public class BeanDefinitionVisitor implements DefinitionVisitor { - private final BeanDefinitionRegistry registry; private final ParserContext context; /** * Temporary def register. */ - private final BeanDefinitionRegister register = new BeanDefinitionRegister(); + private final BeanDefinitionRegister register; public BeanDefinitionVisitor(BeanDefinitionRegistry registry, ParserContext context) { - this.registry = registry; this.context = context; + this.register = new BeanDefinitionRegister(registry); } @Override @@ -52,7 +51,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { Class javaType = sed.getJavaType(); // Maybe a ref. if (javaType == null) { - BeanDefinition beanDefinition = registry.getBeanDefinition(sed.getName()); + BeanDefinition beanDefinition = register.getBeanDefinition(sed.getName()); String beanClassName = beanDefinition.getBeanClassName(); Class defJavaType = AuxiliaryUtils.asClass(beanClassName); AssertUtil.notNull(defJavaType, "bean " + sed.getName() + " javaType must be subclass of ScriptCondition"); @@ -67,7 +66,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { PropertyValue name = new PropertyValue("name", sed.getName()); definition.getPropertyValues().addPropertyValue(name); definition.getPropertyValues().addPropertyValue(script); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + register.registerBeanDefinition(ed.getIdentifier(), definition, true); } } else { @@ -84,8 +83,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); definition.getPropertyValues().addPropertyValue(pipeline); - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); + register.registerBeanDefinition(ed.getIdentifier(), definition, true); } @Override @@ -106,17 +104,10 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { BeanDefinition beanDefinition = register.getBeanDefinition(elementDef.getIdentifier()); AssertUtil.notNull(beanDefinition, elementDef.getIdentifier() + " not exist"); - //components.add(new RuntimeBeanReference(elementDef.getIdentifier())); components.add(beanDefinition); } - if (isAnonymous(ed.getIdentifier())) { - AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - register.registerBeanDefinition(ed.getIdentifier(), definition); - } else { - AssertUtil.isFalse(registry.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); - registry.registerBeanDefinition(ed.getIdentifier(), definition); - } + register.registerBeanDefinition(ed.getIdentifier(), definition, !isAnonymous(ed.getIdentifier())); } @Override @@ -128,7 +119,6 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); - // definition.getPropertyValues().addPropertyValue(pipeline); if (isAnonymous(ed.getPipeline())) { context.getRegistered(ed.getPipeline()).visit(this); definition.getPropertyValues().add("pipeline", register.getBeanDefinition(ed.getPipeline())); @@ -137,7 +127,6 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } appendAttributes(ed, definition); - AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); register.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -193,7 +182,6 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { } appendAttributes(ed, definition); - AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); register.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -226,19 +214,16 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { ed.getIfThenRef().visit(this); BeanDefinition beanDefinition = register.getBeanDefinition(ed.getIfThenRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getIfThenRef().getIdentifier() + " not exist"); - //definition.getPropertyValues().add("thenComponent", new RuntimeBeanReference(ed.getIfThenRef().getIdentifier())); definition.getPropertyValues().add("thenComponent", beanDefinition); if (ed.getIfElseRef() != null) { ed.getIfElseRef().visit(this); beanDefinition = register.getBeanDefinition(ed.getIfElseRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getIfElseRef().getIdentifier() + " not exist"); - //definition.getPropertyValues().add("elseComponent", new RuntimeBeanReference(ed.getIfElseRef().getIdentifier())); definition.getPropertyValues().add("elseComponent", beanDefinition); } appendAttributes(ed, definition); - AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); register.registerBeanDefinition(ed.getIdentifier(), definition); } @@ -265,7 +250,6 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { caseDef.visit(this); BeanDefinition beanDefinition = register.getBeanDefinition(caseDef.getIdentifier()); AssertUtil.notNull(beanDefinition, "case " + caseDef.getWhen() + " " + ed.getChooseDefaultRef().getIdentifier() + " not exist"); - //managedMap.put(caseDef.getWhen(), new RuntimeBeanReference(caseDef.getIdentifier())); managedMap.put(caseDef.getWhen(), beanDefinition); } @@ -275,12 +259,10 @@ public class BeanDefinitionVisitor implements DefinitionVisitor { ed.getChooseDefaultRef().visit(this); BeanDefinition beanDefinition = register.getBeanDefinition(ed.getChooseDefaultRef().getIdentifier()); AssertUtil.notNull(beanDefinition, ed.getChooseDefaultRef().getIdentifier() + " not exist"); - //definition.getPropertyValues().add("defaultBranch", new RuntimeBeanReference(ed.getChooseDefaultRef().getIdentifier())); definition.getPropertyValues().add("defaultBranch", beanDefinition); } appendAttributes(ed, definition); - AssertUtil.isFalse(register.containsBeanDefinition(ed.getIdentifier()), "bean definition " + ed.getIdentifier() + " already registered"); register.registerBeanDefinition(ed.getIdentifier(), definition); } -- Gitee From f0aa84a474d8a995606b60877d1155ed8d7b9bdc Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 10 Dec 2022 22:13:28 +0800 Subject: [PATCH 31/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20pipeline?= =?UTF-8?q?=E6=96=B0=E5=BB=BAcontext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/AsyncCallResult.java | 11 +++- .../smartboot/flow/core/EngineContext.java | 52 ++++++++++++++++++- .../org/smartboot/flow/core/Pipeline.java | 12 ++++- .../core/component/PipelineComponent.java | 14 ++++- ...flow-example-subprocess-non-degradable.xsd | 24 ++++----- 5 files changed, 94 insertions(+), 19 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index 3b34e2a..64424bf 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -19,6 +19,7 @@ public class AsyncCallResult { private Future future; private Component source; private InvokeListener listeners; + private volatile boolean called; public void setListeners(InvokeListener listeners) { this.listeners = listeners; @@ -56,11 +57,17 @@ public class AsyncCallResult { this.source = source; } - public void checkAndWait(EngineContext context) { + public synchronized void checkAndWait(EngineContext context) { + if (called) { + return; + } + + called = true; + try { this.future.get(this.timeout, TimeUnit.MILLISECONDS); } catch (Throwable e) { - if (source.isDegradable() || ctx.getDegradable()) { + if (source.isDegradable()) { EngineContext.LOGGER.warn("degrade component {}", source.getName(), e); } else { EngineContext.LOGGER.error("wait component async-execute failed {}", source.describe(), e); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 3cb68c8..4b49b10 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -29,8 +29,8 @@ public class EngineContext implements Cloneable{ private T req; private S result; ExecutorService executor; - private final Map, Value> extensions = new ConcurrentHashMap<>(); - private final Tracer tracer = new Tracer(); + private Map, Value> extensions = new ConcurrentHashMap<>(); + private Tracer tracer = new Tracer(); private boolean broken; private Throwable fatal; private ExceptionHandler handler; @@ -43,6 +43,7 @@ public class EngineContext implements Cloneable{ * 执行状态 */ private int executing; + private EngineContext parent; public EngineContext newContext(P req, Q result) { EngineContext newContext = new EngineContext<>(); @@ -56,6 +57,27 @@ public class EngineContext implements Cloneable{ return newContext; } + /** + * New context for subprocess. + * + */ + public EngineContext newContext() { + EngineContext newContext = new EngineContext<>(); + newContext.setReq(req); + newContext.setResult(result); + // Reuse extensions. + newContext.extensions = this.extensions; + newContext.invoker = this.invoker; + newContext.tracer = this.tracer; + newContext.engineName = this.engineName; + newContext.executing = this.executing; + newContext.listener = this.listener; + newContext.handler = this.handler; + newContext.parent = this; + newContext.executor = this.executor; + return newContext; + } + /** * Returns current invoked trace. * @@ -93,10 +115,23 @@ public class EngineContext implements Cloneable{ return broken; } + /** + * Break current pipeline. + */ public void broken(boolean broken) { this.broken = broken; } + /** + * Broken full pipeline + */ + public void brokenAll(boolean broken) { + this.broken = broken; + if (this.parent != null) { + this.parent.brokenAll(broken); + } + } + public T getReq() { return req; } @@ -223,6 +258,19 @@ public class EngineContext implements Cloneable{ this.engineName = null; this.executing = DISABLED; this.executor = null; + this.parent = null; + } + + /** + * Apply subprocess fields to parent ctx. + */ + public void apply() { + if (this.parent == null) { + return; + } + + // Apply fields to parent; + this.parent.fatal = this.fatal; } private static class Value implements Serializable { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index db69d5f..42e207a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -10,6 +10,7 @@ import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.Future; @@ -58,12 +59,18 @@ public class Pipeline implements Rollback, Describable, Validator, M }); } + context.ensureFinished(); + + if (context.getRollback()) { + context.brokenAll(true); + } + // Exit record track context.exit(this); } @Override - public void rollback(EngineContext context) { + public synchronized void rollback(EngineContext context) { List> executed = context.getExt(Key.of(this)); if (executed == null || executed.size() == 0) { return; @@ -81,6 +88,9 @@ public class Pipeline implements Rollback, Describable, Validator, M } } + // Clean rollback list. + context.putExt(Key.of(this), Collections.emptyList()); + context.exit(this); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 8f8b01b..72b2770 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -29,7 +29,17 @@ public class PipelineComponent extends Component { @Override public int invoke(EngineContext context) throws Exception { - pipeline.execute(context); + + // Create ctx for subprocess; + EngineContext subprocess = context.newContext(); + + + try { + pipeline.execute(context); + } finally { + subprocess.apply(); + } + return 1; } @@ -39,7 +49,7 @@ public class PipelineComponent extends Component { } @Override - public void rollback(EngineContext context) { + public synchronized void rollback(EngineContext context) { if (!isRollbackable(context)) { return; } diff --git a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd index 06b8319..bc94ed0 100644 --- a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd +++ b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd @@ -8,31 +8,31 @@ - - + + - - - + + + - - + + - + - - + + - + - + -- Gitee From 8924acf1519e9ca2e782ad07429195b51a912381 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 11 Dec 2022 14:25:32 +0800 Subject: [PATCH 32/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20pipeline?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/AsyncCallResult.java | 2 +- .../smartboot/flow/core/EngineContext.java | 12 +++++++- .../org/smartboot/flow/core/FlowEngine.java | 2 -- .../org/smartboot/flow/core/Pipeline.java | 28 ++++++++----------- .../flow/core/builder/ChooseBuilder.java | 2 +- .../flow/core/component/AdapterComponent.java | 15 +++++----- .../flow/core/component/ChooseComponent.java | 10 +++---- .../flow/core/component/Component.java | 17 ++++++++++- .../flow/core/component/IfComponent.java | 9 +++--- .../core/component/PipelineComponent.java | 25 ++++++++++------- .../core/executable/ExecutableAdapter.java | 2 +- .../smartboot/flow/core/invoker/Invoker.java | 23 +++++++++------ .../core/parser/BuilderDefinitionVisitor.java | 4 ++- ...flow-example-subprocess-non-degradable.xsd | 3 +- .../smartboot/flow/example/EngineTest.java | 8 ++++-- .../example/parser/DefaultParserTest.java | 9 ++++++ 16 files changed, 108 insertions(+), 63 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index 64424bf..2364212 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -70,7 +70,7 @@ public class AsyncCallResult { if (source.isDegradable()) { EngineContext.LOGGER.warn("degrade component {}", source.getName(), e); } else { - EngineContext.LOGGER.error("wait component async-execute failed {}", source.describe(), e); + EngineContext.LOGGER.error("wait component async-execute timeout {}ms {}", timeout, source.describe(), e); context.setFatal(e); context.setRollback(true); context.broken(true); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 4b49b10..1fb97d4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -247,6 +247,16 @@ public class EngineContext implements Cloneable{ extensions.put(key, value); } + @SuppressWarnings("unchecked") + public

P remove(Key

key) { + Value removed = extensions.remove(key); + if (removed == null || removed == Value.NULL) { + return null; + } + + return (P) removed.get(); + } + public void clear() { this.tracer.reset(); this.asyncInvokes.clear(); @@ -270,7 +280,7 @@ public class EngineContext implements Cloneable{ } // Apply fields to parent; - this.parent.fatal = this.fatal; + // this.parent.fatal = this.fatal; } private static class Value implements Serializable { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java index 88f794f..aaf4758 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java @@ -59,8 +59,6 @@ public class FlowEngine implements Describable, Validator, Measurable { rollback = true; } - context.ensureFinished(); - if (rollback || context.getRollback()) { context.setExecuting(EngineContext.ROLLBACK); pipeline.rollback(context); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index 42e207a..7465312 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -25,6 +25,7 @@ public class Pipeline implements Rollback, Describable, Validator, M private final List> components = new ArrayList<>(); private String name; + private volatile boolean validateCalled = false; public void setName(String name) { this.name = name; @@ -35,7 +36,7 @@ public class Pipeline implements Rollback, Describable, Validator, M return name; } - public void execute(EngineContext context) throws Exception { + public void execute(EngineContext context) throws Throwable { // Executed sequences. List executed = new ArrayList<>(); context.putExt(Key.of(this), executed); @@ -59,19 +60,15 @@ public class Pipeline implements Rollback, Describable, Validator, M }); } - context.ensureFinished(); - - if (context.getRollback()) { - context.brokenAll(true); - } - // Exit record track context.exit(this); + + context.ensureFinished(); } @Override public synchronized void rollback(EngineContext context) { - List> executed = context.getExt(Key.of(this)); + List> executed = context.remove(Key.of(this)); if (executed == null || executed.size() == 0) { return; } @@ -84,13 +81,10 @@ public class Pipeline implements Rollback, Describable, Validator, M try { component.rollback(context); } catch (Exception e) { - EngineContext.LOGGER.error("rollback failed {}", component.describe()); + LOGGER.error("{} rollback failed {}", this.name, component.describe()); } } - // Clean rollback list. - context.putExt(Key.of(this), Collections.emptyList()); - context.exit(this); } @@ -103,10 +97,6 @@ public class Pipeline implements Rollback, Describable, Validator, M this.components.addAll(components); } - public void addComponent(Component component) { - this.components.add(component); - } - public void visit(PipelineVisitor pipelineVisitor) { for (Component component : components) { ComponentVisitor visitor = pipelineVisitor.visitComponent(component); @@ -116,8 +106,14 @@ public class Pipeline implements Rollback, Describable, Validator, M @Override public void validate() { + if (validateCalled) { + return; + } + AssertUtil.notNull(components, "pipeline [" + describe() + "] components must not be null"); AssertUtil.isTrue(components.size() != 0, "pipeline [" + describe() + "] components must not be null"); components.forEach(Validator::validate); + + validateCalled = true; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java index b2b3447..fab6a21 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/ChooseBuilder.java @@ -56,7 +56,7 @@ public class ChooseBuilder extends ExecutableBuilder { return end(asComponent(defaultBranch)); } - public Component build(Component defaultBranch) { + public ChooseComponent build(Component defaultBranch) { ChooseComponent chooseComponent = new ChooseComponent<>(condition, branches, defaultBranch); applyValues(chooseComponent); return chooseComponent; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 9efc8a7..478cefb 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -40,7 +40,7 @@ public class AdapterComponent extends Component { @Override public void rollback(EngineContext context) { - Pair pair = context.getExt(Key.of(this)); + Pair pair = context.remove(Key.of(this)); if (pair == null) { return; } @@ -49,13 +49,13 @@ public class AdapterComponent extends Component { } @Override - public void validate() { + public void doValidate() { AssertUtil.notNull(adapter, "adapter[" + getName() + "] adapter must not be null"); AssertUtil.notNull(component, "component[" + getName() + "] component must not be null"); } @Override - public int invoke(EngineContext context) throws Exception { + public int invoke(EngineContext context) throws Throwable { context.enter(this); // Convert. @@ -68,14 +68,15 @@ public class AdapterComponent extends Component { EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); int invoke; try { - invoke = context.getInvoker().invoke(newContext, component); + invoke = component.invoke(newContext); } finally { - context.setFatal(newContext.getFatal()); - context.setRollback(newContext.getRollback()); - context.broken(newContext.isBroken()); context.exit(this); } + if (newContext.getFatal() != null) { + throw newContext.getFatal(); + } + // Apply result to parent context. adapter.after(context, newContext); return invoke; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java index 14fe2eb..8f98b8e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java @@ -28,8 +28,6 @@ public class ChooseComponent extends Component { this.branches = branches; this.condition = condition; this.defaultBranch = defaultBranch; - // Compatible parse from xml. - this.allBranchWasString = branches.keySet().stream().allMatch(p -> p instanceof String); } public void setBranches(Map> branches) { @@ -49,7 +47,7 @@ public class ChooseComponent extends Component { } @Override - public int invoke(EngineContext context) throws Exception { + public int invoke(EngineContext context) throws Throwable { context.enter(this); try { Object branch = condition.test(context); @@ -71,7 +69,7 @@ public class ChooseComponent extends Component { context.putExt(Key.of(this), execute); context.enter("branch##" + branch); try { - return context.getInvoker().invoke(context, execute); + execute.invoke(context); } finally { context.exit("branch##" + branch); } @@ -91,7 +89,7 @@ public class ChooseComponent extends Component { @Override public void rollback(EngineContext context) { - Component executed = context.getExt(Key.of(this)); + Component executed = context.remove(Key.of(this)); if (executed == null || !executed.isRollbackable(context)) { return; } @@ -127,7 +125,7 @@ public class ChooseComponent extends Component { } @Override - public void validate() { + public void doValidate() { AssertUtil.notNull(condition, "choose[" + getName() + "] condition must not be null"); AssertUtil.notNull(branches, "choose[" + getName() + "] branch must not be null"); AssertUtil.isTrue(branches.size() != 0, "choose[" + getName() + "] branch must not be null"); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java index 4df34d2..2e92ba7 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java @@ -38,6 +38,7 @@ public abstract class Component implements Rollback, Describable, Va private DegradeCallback degradeCallback; protected final List attributes = new ArrayList<>(0); + private volatile boolean validateCalled = false; public DegradeCallback getDegradeCallback() { return degradeCallback; @@ -110,12 +111,26 @@ public abstract class Component implements Rollback, Describable, Va this.name = name; } - public abstract int invoke(EngineContext context) throws Exception; + public abstract int invoke(EngineContext context) throws Throwable; public boolean isRollbackable(EngineContext context) { return rollback; } + @Override + public void validate() { + if (validateCalled) { + return; + } + + this.doValidate(); + this.validateCalled = true; + } + + protected void doValidate() { + + } + /* Visit component's structure */ public abstract void visit(ComponentVisitor visitor); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java index 3f07e89..57f52e9 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java @@ -39,7 +39,7 @@ public class IfComponent extends Component{ } @Override - public int invoke(EngineContext context) throws Exception { + public int invoke(EngineContext context) throws Throwable { context.enter(this); try { Object test = condition.test(context); @@ -51,9 +51,10 @@ public class IfComponent extends Component{ execute = this.elseComponent; } + if (execute != null) { context.putExt(Key.of(this), execute); - return context.getInvoker().invoke(context, execute); + execute.invoke(context); } } finally { context.exit(this); @@ -70,7 +71,7 @@ public class IfComponent extends Component{ @Override public void rollback(EngineContext context) { - Component executed = context.getExt(Key.of(this)); + Component executed = context.remove(Key.of(this)); if (executed == null || !executed.isRollbackable(context)) { return; } @@ -102,7 +103,7 @@ public class IfComponent extends Component{ } @Override - public void validate() { + public void doValidate() { AssertUtil.notNull(condition, "IF[" + getName() + "]condition must not be null"); AssertUtil.notNull(thenComponent, "IF[" + getName() + "]branch must not be null"); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 72b2770..4c48056 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -28,18 +28,28 @@ public class PipelineComponent extends Component { } @Override - public int invoke(EngineContext context) throws Exception { + public int invoke(EngineContext context) throws Throwable { // Create ctx for subprocess; EngineContext subprocess = context.newContext(); try { - pipeline.execute(context); + pipeline.execute(subprocess); + subprocess.ensureFinished(); } finally { subprocess.apply(); } + if (subprocess.getRollback()) { + subprocess.setExecuting(EngineContext.ROLLBACK); + this.rollback(subprocess); + } + + if (subprocess.getFatal() != null) { + throw subprocess.getFatal(); + } + return 1; } @@ -49,16 +59,11 @@ public class PipelineComponent extends Component { } @Override - public synchronized void rollback(EngineContext context) { + public void rollback(EngineContext context) { if (!isRollbackable(context)) { return; } - context.enter(this); - try { - pipeline.rollback(context); - } finally { - context.exit(this); - } + pipeline.rollback(context); } @Override @@ -74,7 +79,7 @@ public class PipelineComponent extends Component { } @Override - public void validate() { + public void doValidate() { AssertUtil.notNull(pipeline, "subprocess[" + getName() + "]pipeline must not be null!"); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java index 000b24b..cc03aef 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java @@ -78,7 +78,7 @@ public class ExecutableAdapter extends Component implements Rollback< } @Override - public void validate() { + public void doValidate() { AssertUtil.notNull(executable, "Executable[" + getName() + "]executable must not be null"); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java index 6f334c5..ffdd617 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java @@ -67,20 +67,27 @@ public class Invoker { private int execute(Component component, EngineContext context, InvokeListener listeners) { + + Throwable fatal = null; + try { component.invoke(context); } catch (Throwable e) { - if (component.isDegradable() || TransparentContext.current().getDegradable()) { - LOGGER.warn("degrade component {}", component.getName(), e); - } else { - LOGGER.error("execute component failed {}", component.describe(), e); - context.setFatal(e); - context.setRollback(true); - context.broken(true); - } + fatal = e; } finally { // rollback listeners.onCompleted(component, context); + + if (fatal != null) { + if (component.isDegradable()) { + LOGGER.warn("degrade component {}", component.describe(), fatal); + } else { + LOGGER.error("execute component failed {}", component.describe(), fatal); + context.setFatal(fatal); + context.setRollback(true); + context.broken(true); + } + } } return 1; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index 54802b1..bb38b59 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -11,6 +11,7 @@ import org.smartboot.flow.core.builder.ExecutableBuilder; import org.smartboot.flow.core.builder.IfComponentBuilder; import org.smartboot.flow.core.builder.PipelineBuilder; import org.smartboot.flow.core.component.AdapterComponent; +import org.smartboot.flow.core.component.ChooseComponent; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.PipelineComponent; import org.smartboot.flow.core.executable.Executable; @@ -228,7 +229,8 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { defaultBranch = this.namedComponents.get(chooseDefaultRef.getIdentifier()); } - Component build = chooseBuilder.build(defaultBranch); + ChooseComponent build = chooseBuilder.build(defaultBranch); + build.setAllBranchWasString(true); this.namedComponents.put(ed.getIdentifier(), build); } diff --git a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd index bc94ed0..e58a7d7 100644 --- a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd +++ b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd @@ -27,13 +27,14 @@ - + + diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index c48874d..93404c6 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -18,6 +18,7 @@ import org.smartboot.flow.core.executable.AbstractExecutable; import org.smartboot.flow.core.executable.ExecutableAdapter; import java.util.ArrayList; +import java.util.List; /** * @author qinluo @@ -35,7 +36,8 @@ public class EngineTest { engine.setPipeline(pipeline); engine.setName("test"); - pipeline.setComponents(new ArrayList<>()); + List> components = new ArrayList<>(); + pipeline.setComponents(components); ExecutableAdapter component = new ExecutableAdapter<>(new AbstractExecutable() { @Override @@ -44,7 +46,7 @@ public class EngineTest { System.out.println(o2); } }); - pipeline.addComponent(component); + components.add(component); IfComponent ifComponent = new IfComponent<>(new Condition() { @Override @@ -58,7 +60,7 @@ public class EngineTest { } })); - pipeline.addComponent(ifComponent); + components.add(ifComponent); diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 4af3207..c80d120 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.exception.ExceptionHandler; import org.smartboot.flow.core.parser.DefaultParser; import org.smartboot.flow.example.EngineTest; import org.smartboot.flow.core.manager.DefaultEngineManager; @@ -113,10 +114,18 @@ public class DefaultParserTest { FlowEngine testEngine = parser.getEngine("testEngine"); testEngine.setExecutor(Executors.newSingleThreadExecutor()); +// testEngine.setExceptionHandler(new ExceptionHandler() { +// @Override +// public void handle(EngineContext context, Throwable e) { +// System.out.println("handle " + e.getMessage()); +// } +// }); EngineContext execute = testEngine.execute(1); LOGGER.info("trace \n{}", execute.getTrace()); + LOGGER.error("fatal ", execute.getFatal()); + PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); visitor.visit(testEngine); } -- Gitee From 952bdf162e34a9d6acb71a1b876b839742a26964 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 11 Dec 2022 17:06:18 +0800 Subject: [PATCH 33/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=BB=93=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/component/PipelineComponent.java | 1 - .../core/parser/AbstractElementParser.java | 67 +++++++++++-------- .../core/parser/PipelineElementParser.java | 29 +------- ...low-example-parse-multiple-as-pipeline.xml | 25 +++++++ ...flow-example-parse-single-as-component.xml | 24 +++++++ .../example/parser/DefaultParserTest.java | 62 +++++++++++++++-- 6 files changed, 146 insertions(+), 62 deletions(-) create mode 100644 smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml create mode 100644 smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 4c48056..95e7661 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -36,7 +36,6 @@ public class PipelineComponent extends Component { try { pipeline.execute(subprocess); - subprocess.ensureFinished(); } finally { subprocess.apply(); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java index cda8654..c54ed92 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java @@ -51,6 +51,15 @@ public abstract class AbstractElementParser implements ElementParser { public abstract void doParse(Element element, ParserContext context); protected ElementDefinition parseElementsAsPipeline(Element element, ParserContext context) { + List subs = ElementUtils.subElements(element); + AssertUtil.isTrue(subs.size() != 0, "[" + ElementUtils.getName(element) + "] childNodes can't be null"); + + // 只有一个标签时 优化解析,不使用pipeline进行包装 + if (subs.size() == 1) { + Element subElement = subs.get(0); + return parseSubElement(subElement, context); + } + // pipeline identifier. String pipelineIdentifier = context.allocateIdentifier("anonymous-pipeline"); @@ -68,36 +77,11 @@ public abstract class AbstractElementParser implements ElementParser { pipelineDef.setName(pipelineIdentifier); pipelineDef.setIdentifier(pipelineIdentifier); - List subs = ElementUtils.subElements(element); - AssertUtil.isTrue(subs.size() != 0, "[" + ElementUtils.getName(element) + "] childNodes can't be null"); + List subDefinitions = new ArrayList<>(); for (Element sub : subs) { - String subName = ElementUtils.getName(sub); - AssertUtil.isTrue(context.isAllowed(subName), "element " + subName + " not allowed in pipeline"); - ElementParser parser = context.getParser(subName); - AssertUtil.notNull(parser, "Could not find parser for element " + subName); - - String elementIdentifier = getIdentifier(sub, context); - - // nested subprocess - if (Objects.equals(subName, ParseConstants.PIPELINE)) { - PipelineComponentDefinition nestedWrap = new PipelineComponentDefinition(); - String nestedIdentifier = context.allocateIdentifier("anonymous-pipeline-wrapper"); - nestedWrap.setName("anonymous-pipeline-wrapper-" + sub.getAttribute(ParseConstants.NAME)); - nestedWrap.setIdentifier(nestedIdentifier); - nestedWrap.setPipeline(elementIdentifier); - context.register(nestedWrap); - - // Use nested wrap identifier. - elementIdentifier = nestedIdentifier; - } - - parser.parseElement(sub, context); - - // Append sub elements. - ElementDefinition registered = context.getRegistered(elementIdentifier); - AssertUtil.notNull(registered, elementIdentifier + " sub elements parse failed."); + ElementDefinition registered = parseSubElement(sub, context); subDefinitions.add(registered); } @@ -106,4 +90,33 @@ public abstract class AbstractElementParser implements ElementParser { return def; } + + protected ElementDefinition parseSubElement(Element sub, ParserContext context) { + String subName = ElementUtils.getName(sub); + AssertUtil.isTrue(context.isAllowed(subName), "element " + subName + " not allowed in pipeline"); + ElementParser parser = context.getParser(subName); + AssertUtil.notNull(parser, "Could not find parser for element " + subName); + + String elementIdentifier = getIdentifier(sub, context); + + // nested subprocess + if (Objects.equals(subName, ParseConstants.PIPELINE)) { + PipelineComponentDefinition nestedWrap = new PipelineComponentDefinition(); + String nestedIdentifier = context.allocateIdentifier("anonymous-pipeline-wrapper"); + nestedWrap.setName("anonymous-pipeline-wrapper-" + sub.getAttribute(ParseConstants.NAME)); + nestedWrap.setIdentifier(nestedIdentifier); + nestedWrap.setPipeline(elementIdentifier); + context.register(nestedWrap); + + // Use nested wrap identifier. + elementIdentifier = nestedIdentifier; + } + + parser.parseElement(sub, context); + + // Append sub elements. + ElementDefinition registered = context.getRegistered(elementIdentifier); + AssertUtil.notNull(registered, elementIdentifier + " sub elements parse failed."); + return registered; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/PipelineElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/PipelineElementParser.java index 64576f8..569c8c2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/PipelineElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/PipelineElementParser.java @@ -1,14 +1,12 @@ package org.smartboot.flow.core.parser; import org.smartboot.flow.core.parser.definition.ElementDefinition; -import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition; import org.smartboot.flow.core.parser.definition.PipelineDefinition; import org.smartboot.flow.core.util.AssertUtil; import org.w3c.dom.Element; import java.util.ArrayList; import java.util.List; -import java.util.Objects; /** * Parse pipeline tag. @@ -46,32 +44,7 @@ public class PipelineElementParser extends AbstractElementParser { List subDefinitions = new ArrayList<>(); for (Element sub : elements) { - String subName = ElementUtils.getName(sub); - AssertUtil.isTrue(context.isAllowed(subName), "element " + subName + " not allowed in pipeline"); - ElementParser parser = context.getParser(subName); - AssertUtil.notNull(parser, "Could not find parser for element " + subName); - - identifier = super.getIdentifier(sub, context); - - // nested subprocess - if (Objects.equals(subName, ParseConstants.PIPELINE)) { - PipelineComponentDefinition nestedWrap = new PipelineComponentDefinition(); - String nestedIdentifier = context.allocateIdentifier("anonymous-pipeline-wrapper"); - nestedWrap.setName("anonymous-pipeline-wrapper-" + sub.getAttribute(ParseConstants.NAME)); - nestedWrap.setIdentifier(nestedIdentifier); - nestedWrap.setPipeline(identifier); - context.register(nestedWrap); - - // Use nested wrap identifier. - identifier = nestedIdentifier; - } - - parser.parseElement(sub, context); - - // Append sub elements. - ElementDefinition registered = context.getRegistered(identifier); - AssertUtil.notNull(registered, identifier + " sub elements parse failed."); - subDefinitions.add(registered); + subDefinitions.add(parseSubElement(sub, context)); } definition.setChildren(subDefinitions); diff --git a/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml b/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml new file mode 100644 index 0000000..b62f8b1 --- /dev/null +++ b/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml b/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml new file mode 100644 index 0000000..59d4513 --- /dev/null +++ b/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index c80d120..4a10874 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -114,12 +114,62 @@ public class DefaultParserTest { FlowEngine testEngine = parser.getEngine("testEngine"); testEngine.setExecutor(Executors.newSingleThreadExecutor()); -// testEngine.setExceptionHandler(new ExceptionHandler() { -// @Override -// public void handle(EngineContext context, Throwable e) { -// System.out.println("handle " + e.getMessage()); -// } -// }); + testEngine.setExceptionHandler(new ExceptionHandler() { + @Override + public void handle(EngineContext context, Throwable e) { + System.out.println("handle " + e.getMessage()); + } + }); + + EngineContext execute = testEngine.execute(1); + LOGGER.info("trace \n{}", execute.getTrace()); + + LOGGER.error("fatal ", execute.getFatal()); + + PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); + visitor.visit(testEngine); + } + + @Test + public void testParseMultipleAsPipeline() { + + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/flow-example-parse-multiple-as-pipeline.xml")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + testEngine.setExecutor(Executors.newSingleThreadExecutor()); + testEngine.setExceptionHandler(new ExceptionHandler() { + @Override + public void handle(EngineContext context, Throwable e) { + System.out.println("handle " + e.getMessage()); + } + }); + + EngineContext execute = testEngine.execute(1); + LOGGER.info("trace \n{}", execute.getTrace()); + + LOGGER.error("fatal ", execute.getFatal()); + + PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); + visitor.visit(testEngine); + } + + @Test + public void testParseSingleAsComponent() { + + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/flow-example-parse-single-as-component.xml")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + testEngine.setExecutor(Executors.newSingleThreadExecutor()); + testEngine.setExceptionHandler(new ExceptionHandler() { + @Override + public void handle(EngineContext context, Throwable e) { + System.out.println("handle " + e.getMessage()); + } + }); EngineContext execute = testEngine.execute(1); LOGGER.info("trace \n{}", execute.getTrace()); -- Gitee From 895942162ff3a2865057dd58c8493875b78d08ed Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 11 Dec 2022 17:09:55 +0800 Subject: [PATCH 34/54] qinluo: - rename --- .../org/smartboot/flow/core/parser/AbstractElementParser.java | 2 +- .../org/smartboot/flow/core/parser/AdapterElementParser.java | 2 +- .../org/smartboot/flow/core/parser/ChooseElementParser.java | 2 +- .../java/org/smartboot/flow/core/parser/IfElementParser.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java index c54ed92..4bb00f6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AbstractElementParser.java @@ -50,7 +50,7 @@ public abstract class AbstractElementParser implements ElementParser { */ public abstract void doParse(Element element, ParserContext context); - protected ElementDefinition parseElementsAsPipeline(Element element, ParserContext context) { + protected ElementDefinition parseSubElements(Element element, ParserContext context) { List subs = ElementUtils.subElements(element); AssertUtil.isTrue(subs.size() != 0, "[" + ElementUtils.getName(element) + "] childNodes can't be null"); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java index 98b1418..9f385dd 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/AdapterElementParser.java @@ -31,7 +31,7 @@ public class AdapterElementParser extends AbstractElementParser{ definition.setIdentifier(identifier); definition.getAttributes().addAll(ElementUtils.extraAttributes(element)); - ElementDefinition def = parseElementsAsPipeline(element, context); + ElementDefinition def = parseSubElements(element, context); definition.setPipelineElement(def); context.register(definition); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java index edff646..6504932 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ChooseElementParser.java @@ -69,7 +69,7 @@ public class ChooseElementParser extends AbstractElementParser{ } // Wrap sub elements as pipeline. - ElementDefinition def = parseElementsAsPipeline(subElement, context); + ElementDefinition def = parseSubElements(subElement, context); if (elementName.equals(ParseConstants.CASE)) { caseList.remove(currentDef); def.setWhen(subElement.getAttribute(ParseConstants.WHEN)); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java index 6e5b216..02c2018 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/IfElementParser.java @@ -71,7 +71,7 @@ public class IfElementParser extends AbstractElementParser { } // Wrap sub elements as pipeline. - ElementDefinition def = parseElementsAsPipeline(subElement, context); + ElementDefinition def = parseSubElements(subElement, context); if (Objects.equals(elementName, ParseConstants.ELSE)) { elseDef = def; } else if (Objects.equals(elementName, ParseConstants.THEN)) { -- Gitee From 275c1cfe27e47793ba6921b33d241df1578b7901 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 11 Dec 2022 20:35:05 +0800 Subject: [PATCH 35/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20adapter=20ct?= =?UTF-8?q?x=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/EngineContext.java | 68 ++++++++++++------- .../flow/core/component/AdapterComponent.java | 26 ++++--- .../flow/core/component/AdapterContext.java | 47 +++++++++++++ 3 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterContext.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 1fb97d4..5bbb681 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -26,35 +26,51 @@ public class EngineContext implements Cloneable{ public static final int ROLLBACK = 2; public static final Logger LOGGER = LoggerFactory.getLogger(EngineContext.class); - private T req; - private S result; - ExecutorService executor; - private Map, Value> extensions = new ConcurrentHashMap<>(); - private Tracer tracer = new Tracer(); - private boolean broken; - private Throwable fatal; - private ExceptionHandler handler; - private boolean rollback; - private final Map asyncInvokes = new ConcurrentHashMap<>(); - private String engineName; - ExecutionListener listener; - private Invoker invoker; + protected T req; + protected S result; + protected ExecutorService executor; + protected Map, Value> extensions = new ConcurrentHashMap<>(); + protected Tracer tracer = new Tracer(); + protected boolean broken; + protected Throwable fatal; + protected ExceptionHandler handler; + protected boolean rollback; + protected Map asyncInvokes = new ConcurrentHashMap<>(); + protected String engineName; + protected ExecutionListener listener; + protected Invoker invoker; /** * 执行状态 */ - private int executing; - private EngineContext parent; - - public EngineContext newContext(P req, Q result) { - EngineContext newContext = new EngineContext<>(); - try { - newContext = (EngineContext)this.clone(); - newContext.setReq(req); - newContext.setResult(result); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - return newContext; + protected int executing; + protected EngineContext parent; + +// public EngineContext newContext(P req, Q result) { +// EngineContext newContext = new EngineContext<>(); +// try { +// newContext = (EngineContext)this.clone(); +// newContext.setReq(req); +// newContext.setResult(result); +// newContext.parent = this; +// } catch (CloneNotSupportedException e) { +// e.printStackTrace(); +// } +// return newContext; +// } + + public void copy(EngineContext dest) { + // Reuse extensions. + dest.extensions = this.extensions; + dest.invoker = this.invoker; + dest.tracer = this.tracer; + dest.engineName = this.engineName; + dest.executing = this.executing; + dest.listener = this.listener; + dest.handler = this.handler; + dest.executor = this.executor; + dest.fatal = this.fatal; + dest.broken = this.broken; + dest.asyncInvokes = this.asyncInvokes; } /** diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 478cefb..b89ab77 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -40,14 +40,19 @@ public class AdapterComponent extends Component { @Override public void rollback(EngineContext context) { - Pair pair = context.remove(Key.of(this)); - if (pair == null) { + AdapterContext newContext = context.remove(Key.of(this)); + if (newContext == null) { return; } - EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); component.rollback(newContext); } + @Override + public boolean isRollbackable(EngineContext context) { + AdapterContext newContext = context.getExt(Key.of(this)); + return newContext != null; + } + @Override public void doValidate() { AssertUtil.notNull(adapter, "adapter[" + getName() + "] adapter must not be null"); @@ -62,10 +67,17 @@ public class AdapterComponent extends Component { Pair pair = adapter.before(context); AssertUtil.notNull(pair, "adapter[" + getName() + "] result must not be null"); + // Adapter ctx 本质只是进行参数的转换,并不是像子流程那样新起一个ctx,所以对一些操作类的方法,相关属性需要回设到父流程去 + AdapterContext newContext = new AdapterContext<>(); + newContext.setReq(pair.getLeft()); + newContext.setResult(pair.getRight()); + // copy parent + context.copy(newContext); + newContext.setParent(context); + // Store converted objects. - context.putExt(Key.of(this), pair); + context.putExt(Key.of(this), newContext); - EngineContext newContext = context.newContext(pair.getLeft(), pair.getRight()); int invoke; try { invoke = component.invoke(newContext); @@ -73,10 +85,6 @@ public class AdapterComponent extends Component { context.exit(this); } - if (newContext.getFatal() != null) { - throw newContext.getFatal(); - } - // Apply result to parent context. adapter.after(context, newContext); return invoke; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterContext.java new file mode 100644 index 0000000..caf23c5 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterContext.java @@ -0,0 +1,47 @@ +package org.smartboot.flow.core.component; + +import org.smartboot.flow.core.EngineContext; + +/** + * @author qinluo + * @date 2022/12/11 20:09 + * @since 1.0.0 + */ +public class AdapterContext extends EngineContext { + + @Override + public String getTrace() { + return this.parent.getTrace(); + } + + @Override + public boolean getRollback() { + return super.getRollback(); + } + + @Override + public void setRollback(boolean rollback) { + this.parent.setRollback(rollback); + super.setRollback(rollback); + } + + @Override + public Throwable getFatal() { + return super.getFatal(); + } + + @Override + public void setFatal(Throwable fatal) { + this.parent.setFatal(fatal); + super.setFatal(fatal); + } + + @Override + public void broken(boolean broken) { + super.brokenAll(broken); + } + + public void setParent(EngineContext ctx) { + this.parent = ctx; + } +} -- Gitee From 35f65f721d3aa73de2f3930a13102f1ecc07d037 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sun, 11 Dec 2022 20:52:07 +0800 Subject: [PATCH 36/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E5=AD=90=E6=B5=81=E7=A8=8B=E4=B8=8E=E4=B8=BB=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=B8=80=E8=B5=B7=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/component/PipelineComponent.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 95e7661..351fc8a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -40,7 +40,7 @@ public class PipelineComponent extends Component { subprocess.apply(); } - if (subprocess.getRollback()) { + if (subprocess.getRollback() && !isAnonymous()) { subprocess.setExecuting(EngineContext.ROLLBACK); this.rollback(subprocess); } @@ -52,6 +52,10 @@ public class PipelineComponent extends Component { return 1; } + private boolean isAnonymous() { + return pipeline.describe().contains("anonymous-pipeline"); + } + @Override public boolean isRollbackable(EngineContext context) { return pipeline.isRollbackable(context); -- Gitee From 04b05e04e5b45ec84715afc3ff0be271fee70da8 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 13 Dec 2022 20:25:15 +0800 Subject: [PATCH 37/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20while?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=A8=A1=E6=8B=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/parser/BuilderDefinitionVisitor.java | 10 ++++- .../flow/example/ExecuteTimesCondition.java | 40 +++++++++++++++++++ .../src/main/resources/flow-example-while.xml | 27 +++++++++++++ .../example/parser/DefaultParserTest.java | 20 ++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java create mode 100644 smart-flow-example/src/main/resources/flow-example-while.xml diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java index bb38b59..527c684 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/BuilderDefinitionVisitor.java @@ -41,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap; public class BuilderDefinitionVisitor implements DefinitionVisitor { private final Map> namedComponents = new ConcurrentHashMap<>(); + private final Map assembledPipelines = new ConcurrentHashMap<>(); private final Map> namedPipelines = new ConcurrentHashMap<>(); private final Map> namedEngines = new ConcurrentHashMap<>(); private final Map> callbacks = new ConcurrentHashMap<>(); @@ -85,6 +86,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { Pipeline build = pipelineBuilder.build(); invoke(ed.getIdentifier(), build); + this.assembledPipelines.put(ed.getIdentifier(), build); } @Override @@ -97,8 +99,10 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { pipelineBuilder = new PipelineBuilder<>(ed.getPipeline()); this.namedPipelines.put(ed.getPipeline(), pipelineBuilder); this.collect(ed.getPipeline(), (engineBuilder::pipeline)); + } else if (assembledPipelines.get(ed.getPipeline()) != null) { + engineBuilder.pipeline(assembledPipelines.get(ed.getPipeline())); } else { - engineBuilder.pipeline(pipelineBuilder.build()); + this.collect(ed.getPipeline(), (engineBuilder::pipeline)); } this.namedEngines.put(engineName, engineBuilder); @@ -114,8 +118,10 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { pipelineBuilder = new PipelineBuilder<>(ed.getPipeline()); this.namedPipelines.put(ed.getPipeline(), pipelineBuilder); this.collect(ed.getPipeline(), pipelineComponent::setPipeline); + } else if (assembledPipelines.get(ed.getPipeline()) != null) { + pipelineComponent.setPipeline(assembledPipelines.get(ed.getPipeline())); } else { - pipelineComponent = new PipelineComponent<>(pipelineBuilder.build()); + this.collect(ed.getPipeline(), (pipelineComponent::setPipeline)); } this.namedComponents.put(engineName, pipelineComponent); diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java new file mode 100644 index 0000000..31e49b9 --- /dev/null +++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java @@ -0,0 +1,40 @@ +package org.smartboot.flow.example; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.Condition; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.Key; +import org.springframework.stereotype.Service; + +/** + * @author qinluo + * @date 2022-11-11 21:45:21 + * @since 1.0.0 + */ +@Service +public class ExecuteTimesCondition extends Condition { + + private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteTimesCondition.class); + + @Override + public Object test(Integer integer, String s) { + return integer != null && integer == 1; + } + + @Override + public Object test(EngineContext context) { + Integer cnt = context.getExt(Key.of(this)); + if (cnt == null) { + cnt = 3; + } + + cnt--; + context.putExt(Key.of(this), cnt); + + LOGGER.info("value {}", cnt); + + return cnt > 0; + } +} diff --git a/smart-flow-example/src/main/resources/flow-example-while.xml b/smart-flow-example/src/main/resources/flow-example-while.xml new file mode 100644 index 0000000..6c12bca --- /dev/null +++ b/smart-flow-example/src/main/resources/flow-example-while.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 4a10874..acf4d08 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -179,4 +179,24 @@ public class DefaultParserTest { PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); visitor.visit(testEngine); } + + @Test + public void testWhile() { + + DefaultParser parser = new DefaultParser(); + parser.parse(this.getClass().getResourceAsStream("/flow-example-while.xml")); + LOGGER.info("engines {}", parser.getEngineNames()); + + FlowEngine testEngine = parser.getEngine("testEngine"); + testEngine.setExecutor(Executors.newSingleThreadExecutor()); + testEngine.setExceptionHandler(new ExceptionHandler() { + @Override + public void handle(EngineContext context, Throwable e) { + e.printStackTrace(); + } + }); + + EngineContext execute = testEngine.execute(1); + LOGGER.info("trace \n{}", execute.getTrace()); + } } -- Gitee From e3d399255241cb56704cee22fb55103fcc6ffa69 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 13 Dec 2022 20:47:49 +0800 Subject: [PATCH 38/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84visitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/smartboot/flow/core/FlowEngine.java | 6 ++-- .../org/smartboot/flow/core/Pipeline.java | 8 +++-- .../flow/core/component/AdapterComponent.java | 6 ++++ .../flow/core/component/ChooseComponent.java | 19 +++++++++--- .../flow/core/component/Component.java | 4 +++ .../flow/core/component/IfComponent.java | 18 +++++++++--- .../core/component/PipelineComponent.java | 12 ++++++-- .../view/plantuml/PlantumlEngineVisitor.java | 16 +++++++--- .../flow/core/visitor/ComponentVisitor.java | 21 ++++++++++---- .../flow/core/visitor/EngineVisitor.java | 29 +++++++++++-------- .../flow/core/visitor/PipelineVisitor.java | 19 ++++++++++-- 11 files changed, 119 insertions(+), 39 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java index aaf4758..6b2e71b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/FlowEngine.java @@ -137,8 +137,10 @@ public class FlowEngine implements Describable, Validator, Measurable { public void visit(EngineVisitor engineVisitor) { AssertUtil.notNull(engineVisitor, "visitor must not be null!"); - engineVisitor.visit(this.name); - PipelineVisitor pipelineVisitor = engineVisitor.visitPipeline(pipeline); + engineVisitor.visit(this.name, this.executor); + engineVisitor.visitSource(this); + + PipelineVisitor pipelineVisitor = engineVisitor.visitPipeline(pipeline.describe()); pipeline.visit(pipelineVisitor); // Visit completed. diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index 7465312..9ca9da7 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -98,9 +98,13 @@ public class Pipeline implements Rollback, Describable, Validator, M } public void visit(PipelineVisitor pipelineVisitor) { + pipelineVisitor.visitSource(this); + for (Component component : components) { - ComponentVisitor visitor = pipelineVisitor.visitComponent(component); - component.visit(visitor); + ComponentVisitor visitor = pipelineVisitor.visitComponent(component.getType(), component.getName(), component.describe()); + if (visitor != null) { + component.visit(visitor); + } } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index b89ab77..1216627 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core.component; import org.smartboot.flow.core.Adapter; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Key; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.common.Pair; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -95,4 +96,9 @@ public class AdapterComponent extends Component { ComponentVisitor componentVisitor = visitor.visitComponent(component); component.visit(componentVisitor); } + + @Override + public ComponentType getType() { + return ComponentType.ADAPTER; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java index 8f98b8e..008ae1e 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java @@ -4,6 +4,7 @@ package org.smartboot.flow.core.component; import org.smartboot.flow.core.Condition; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Key; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -114,13 +115,18 @@ public class ChooseComponent extends Component { visitor.visitCondition(condition.describe()); branches.forEach((k, v) -> { - ComponentVisitor branchVisitor = visitor.visitBranch(k, v); - v.visit(branchVisitor); + ComponentVisitor branchVisitor = visitor.visitBranch(k, v.getType(), v.getName(), v.describe()); + if (branchVisitor != null) { + v.visit(branchVisitor); + } }); if (defaultBranch != null) { - ComponentVisitor defaultVisitor = visitor.visitComponent(defaultBranch); - defaultBranch.visit(defaultVisitor); + ComponentVisitor defaultVisitor = visitor.visitComponent(defaultBranch.getType(), defaultBranch.getName(), defaultBranch.describe()); + if (defaultVisitor != null) { + defaultBranch.visit(defaultVisitor); + } + } } @@ -135,4 +141,9 @@ public class ChooseComponent extends Component { defaultBranch.validate(); } } + + @Override + public ComponentType getType() { + return ComponentType.CHOOSE; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java index 2e92ba7..f874be3 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java @@ -8,6 +8,7 @@ import org.smartboot.flow.core.Measurable; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.Validator; import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.visitor.ComponentVisitor; import java.util.ArrayList; @@ -133,4 +134,7 @@ public abstract class Component implements Rollback, Describable, Va /* Visit component's structure */ public abstract void visit(ComponentVisitor visitor); + + /* Returns component's type */ + public abstract ComponentType getType(); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java index 57f52e9..8592cdf 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java @@ -4,6 +4,7 @@ package org.smartboot.flow.core.component; import org.smartboot.flow.core.Condition; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Key; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -93,12 +94,16 @@ public class IfComponent extends Component{ public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); visitor.visitCondition(condition.describe()); - ComponentVisitor thenVisitor = visitor.visitComponent(thenComponent); - thenComponent.visit(thenVisitor); + ComponentVisitor thenVisitor = visitor.visitComponent(thenComponent.getType(), thenComponent.getName(), thenComponent.describe()); + if (thenVisitor != null) { + thenComponent.visit(thenVisitor); + } if (elseComponent != null) { - ComponentVisitor elseVisitor = visitor.visitComponent(elseComponent); - elseComponent.visit(elseVisitor); + ComponentVisitor elseVisitor = visitor.visitComponent(elseComponent.getType(), elseComponent.getName(), elseComponent.describe()); + if (elseVisitor != null) { + elseComponent.visit(elseVisitor); + } } } @@ -112,4 +117,9 @@ public class IfComponent extends Component{ elseComponent.validate(); } } + + @Override + public ComponentType getType() { + return ComponentType.IF; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 351fc8a..8877ab9 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core.component; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; @@ -77,12 +78,19 @@ public class PipelineComponent extends Component { @Override public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); - PipelineVisitor pipelineVisitor = visitor.visitPipeline(pipeline); - pipeline.visit(pipelineVisitor); + PipelineVisitor pipelineVisitor = visitor.visitPipeline(pipeline.describe()); + if (pipelineVisitor != null) { + pipeline.visit(pipelineVisitor); + } } @Override public void doValidate() { AssertUtil.notNull(pipeline, "subprocess[" + getName() + "]pipeline must not be null!"); } + + @Override + public ComponentType getType() { + return ComponentType.PIPELINE; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java index 40c013f..fe2d52f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java @@ -10,6 +10,7 @@ import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.OutputStreamWriter; +import java.util.concurrent.Executor; /** * @author qinluo @@ -27,6 +28,12 @@ public class PlantumlEngineVisitor extends EngineVisitor { private final PlantumlEngine plantumlEngine = new PlantumlEngine(); // plantuml file dest. private final String dest; + /** + * engine name. + */ + private String name; + private PlantumlPipeline pipeline; + private Executor executor; public PlantumlEngineVisitor(String dest) { this.dest = dest + SUFFIX; @@ -79,14 +86,15 @@ public class PlantumlEngineVisitor extends EngineVisitor { } @Override - public void visit(String engine) { - plantumlEngine.setName(engine); + public void visit(String engine, Executor executor) { + this.name = engine; + this.executor = executor; } @Override - public PipelineVisitor visitPipeline(Pipeline pipeline) { + public PipelineVisitor visitPipeline(String pipeline) { PlantumlPipeline plantumlPipeline = new PlantumlPipeline(); - plantumlPipeline.setName(pipeline.describe()); + plantumlPipeline.setName(pipeline); plantumlEngine.setPipeline(plantumlPipeline); return new PlantumlPipelineVisitor(plantumlPipeline); } 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 24b5ed8..77ff493 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 @@ -1,7 +1,7 @@ package org.smartboot.flow.core.visitor; -import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.component.Component; import java.util.List; @@ -23,7 +23,7 @@ public class ComponentVisitor { this.delegate = visitor; } - public PipelineVisitor visitPipeline(Pipeline pipeline) { + public PipelineVisitor visitPipeline(String pipeline) { if (delegate != null) { return delegate.visitPipeline(pipeline); } @@ -31,15 +31,24 @@ public class ComponentVisitor { return null; } + public void visitSource(Component component) { + if (delegate != null) { + delegate.visitSource(component); + } + } + public void visitCondition(String condition) { if (delegate != null) { delegate.visitCondition(condition); } } - public ComponentVisitor visitComponent(Component component) { + /** + * Visit component with type, name, describe. + */ + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { if (delegate != null) { - return delegate.visitComponent(component); + return delegate.visitComponent(type, name, describe); } return null; @@ -51,9 +60,9 @@ public class ComponentVisitor { } } - public ComponentVisitor visitBranch(Object branch, Component component) { + public ComponentVisitor visitBranch(Object branch, ComponentType type, String name, String describe) { if (delegate != null) { - return delegate.visitBranch(branch, component); + return delegate.visitBranch(branch, type, name, describe); } return null; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/EngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/EngineVisitor.java index 777ad3f..5b80098 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/EngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/EngineVisitor.java @@ -1,7 +1,8 @@ package org.smartboot.flow.core.visitor; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; + +import java.util.concurrent.Executor; /** * @author qinluo @@ -23,28 +24,32 @@ public class EngineVisitor { this.delegate = delegate; } + public void visitEnd() { + if (delegate != null) { + delegate.visitEnd(); + } + } + /** - * Visit engine. + * Visit name and executor. + * + * @param name engine's name. + * @param executor async executor, maybe null. * - * @param flowEngine root. */ - public void visit(FlowEngine flowEngine) { - flowEngine.visit(this); - } - - public void visitEnd() { + public void visit(String name, Executor executor) { if (delegate != null) { - delegate.visitEnd(); + delegate.visit(name, executor); } } - public void visit(String engine) { + public void visitSource(FlowEngine flowEngine) { if (delegate != null) { - delegate.visit(engine); + delegate.visitSource(flowEngine); } } - public PipelineVisitor visitPipeline(Pipeline pipeline) { + public PipelineVisitor visitPipeline(String pipeline) { if (delegate != null) { return delegate.visitPipeline(pipeline); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/PipelineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/PipelineVisitor.java index 25c402b..c639b25 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/PipelineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/visitor/PipelineVisitor.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core.visitor; -import org.smartboot.flow.core.component.Component; +import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.common.ComponentType; /** * @author qinluo @@ -19,9 +20,21 @@ public class PipelineVisitor { this.delegate = delegate; } - public ComponentVisitor visitComponent(Component component) { + /** + * Visit pipeline source. + */ + public void visitSource(Pipeline pipeline) { if (delegate != null) { - return delegate.visitComponent(component); + delegate.visitSource(pipeline); + } + } + + /** + * Visit component with type, name, describe. + */ + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { + if (delegate != null) { + return delegate.visitComponent(type, name, describe); } return null; -- Gitee From 6054dda750ba3d2aeee2464cff5560435e27d6bd Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 13 Dec 2022 22:05:18 +0800 Subject: [PATCH 39/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20Visitor?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/core/component/AdapterComponent.java | 6 +- .../flow/core/component/ChooseComponent.java | 1 + .../flow/core/component/IfComponent.java | 1 + .../core/component/PipelineComponent.java | 1 + .../core/executable/ExecutableAdapter.java | 7 ++ .../flow/core/manager/ComponentModel.java | 23 +++- .../core/manager/DefaultEngineManager.java | 2 +- .../core/manager/RegisterEngineVisitor.java | 23 ++-- .../manager/RegisteredComponentVisitor.java | 29 ++--- .../manager/RegisteredPipelineVisitor.java | 13 +- .../core/view/plantuml/PlantumlComponent.java | 117 ++++++++---------- .../plantuml/PlantumlComponentVisitor.java | 67 ---------- .../core/view/plantuml/PlantumlEngine.java | 30 ----- .../view/plantuml/PlantumlEngineVisitor.java | 24 ++-- .../core/view/plantuml/PlantumlPipeline.java | 34 +++-- .../plantuml/PlantumlPipelineVisitor.java | 29 ----- 16 files changed, 166 insertions(+), 241 deletions(-) delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngine.java delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java index 1216627..c2258a1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AdapterComponent.java @@ -93,8 +93,10 @@ public class AdapterComponent extends Component { @Override public void visit(ComponentVisitor visitor) { - ComponentVisitor componentVisitor = visitor.visitComponent(component); - component.visit(componentVisitor); + ComponentVisitor componentVisitor = visitor.visitComponent(component.getType(), component.getName(), component.describe()); + if (componentVisitor != null) { + component.visit(componentVisitor); + } } @Override diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java index 008ae1e..f11520b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/ChooseComponent.java @@ -113,6 +113,7 @@ public class ChooseComponent extends Component { public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); visitor.visitCondition(condition.describe()); + visitor.visitSource(this); branches.forEach((k, v) -> { ComponentVisitor branchVisitor = visitor.visitBranch(k, v.getType(), v.getName(), v.describe()); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java index 8592cdf..a06ed12 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/IfComponent.java @@ -94,6 +94,7 @@ public class IfComponent extends Component{ public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); visitor.visitCondition(condition.describe()); + visitor.visitSource(this); ComponentVisitor thenVisitor = visitor.visitComponent(thenComponent.getType(), thenComponent.getName(), thenComponent.describe()); if (thenVisitor != null) { thenComponent.visit(thenVisitor); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java index 8877ab9..990db74 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/PipelineComponent.java @@ -78,6 +78,7 @@ public class PipelineComponent extends Component { @Override public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); + visitor.visitSource(this); PipelineVisitor pipelineVisitor = visitor.visitPipeline(pipeline.describe()); if (pipelineVisitor != null) { pipeline.visit(pipelineVisitor); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java index cc03aef..b22dc9c 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java @@ -4,6 +4,7 @@ package org.smartboot.flow.core.executable; import org.smartboot.flow.core.DegradeCallback; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.Rollback; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -75,10 +76,16 @@ public class ExecutableAdapter extends Component implements Rollback< public void visit(ComponentVisitor visitor) { visitor.visitAttributes(attributes); visitor.visitExecutable(executable.describe()); + visitor.visitSource(this); } @Override public void doValidate() { AssertUtil.notNull(executable, "Executable[" + getName() + "]executable must not be null"); } + + @Override + public ComponentType getType() { + return ComponentType.BASIC; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java index 697b540..3e071db 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java @@ -21,9 +21,9 @@ import java.util.concurrent.ConcurrentHashMap; public class ComponentModel extends Uniqueness { private final Map holders = new ConcurrentHashMap<>(); - private final Component component; - private final String name; - private final String describe; + private Component component; + private String name; + private String describe; private final Map components = new ConcurrentHashMap<>(); String executable; @@ -33,7 +33,7 @@ public class ComponentModel extends Uniqueness { PipelineModel pipeline; String condition; private String branch; - private final Metrics metrics; + private Metrics metrics; ComponentModel(String identifier, Component component) { this.identifier = identifier; @@ -43,6 +43,10 @@ public class ComponentModel extends Uniqueness { this.metrics = component.getMetrics(); } + ComponentModel(String identifier) { + this.identifier = identifier; + } + public Map getHolders() { return holders; } @@ -143,4 +147,15 @@ public class ComponentModel extends Uniqueness { this.metrics.reset(); components.forEach((k, v) -> v.reset()); } + + public void setComponent(Component component) { + this.component = component; + this.name = component.getName(); + this.describe = component.describe(); + this.metrics = component.getMetrics(); + } + + public void setType(ComponentType type) { + this.type = type; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java index 68d1f51..3b060d6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/DefaultEngineManager.java @@ -41,7 +41,7 @@ public class DefaultEngineManager implements EngineManager { engine.validate(); RegisterEngineVisitor visitor = new RegisterEngineVisitor(); - visitor.visit(engine); + engine.visit(visitor); EngineModel model = visitor.getEngine(); registeredEngines.put(model.getIdentifier(), model); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java index 6b66aa4..33c36bc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java @@ -1,11 +1,12 @@ package org.smartboot.flow.core.manager; import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.util.ContactUtils; import org.smartboot.flow.core.visitor.EngineVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; +import java.util.concurrent.Executor; + /** * @author qinluo * @date 2022/11/18 23:02 @@ -16,25 +17,27 @@ public class RegisterEngineVisitor extends EngineVisitor { private EngineModel model; @Override - public void visit(FlowEngine flowEngine) { - this.model = new EngineModel(flowEngine.getName()); - this.model.setMetrics(flowEngine.getMetrics()); - super.visit(flowEngine); + public void visit(String name, Executor executor) { + this.model = new EngineModel(name); } @Override - public void visitEnd() { - this.model.collect(); + public void visitSource(FlowEngine flowEngine) { + this.model.setMetrics(flowEngine.getMetrics()); } @Override - public PipelineVisitor visitPipeline(Pipeline pipeline) { - PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(this.model.getIdentifier(), pipeline.describe())); + public PipelineVisitor visitPipeline(String pipeline) { + PipelineModel pipelineModel = new PipelineModel(pipeline, ContactUtils.contact(this.model.getIdentifier(), pipeline)); this.model.setPipeline(pipelineModel); - pipelineModel.setMetrics(pipeline.getMetrics()); return new RegisteredPipelineVisitor(pipelineModel); } + @Override + public void visitEnd() { + this.model.collect(); + } + public EngineModel getEngine() { return model; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java index 9b415ce..3d35e38 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java @@ -1,6 +1,5 @@ package org.smartboot.flow.core.manager; -import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.component.Component; @@ -25,31 +24,34 @@ public class RegisteredComponentVisitor extends ComponentVisitor { } @Override - public PipelineVisitor visitPipeline(Pipeline pipeline) { - PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(model.getIdentifier(), pipeline.describe())); + public PipelineVisitor visitPipeline(String pipeline) { + PipelineModel pipelineModel = new PipelineModel(pipeline, ContactUtils.contact(model.getIdentifier(), pipeline)); this.model.pipeline = pipelineModel; - this.model.type = (ComponentType.PIPELINE); - pipelineModel.setMetrics(pipeline.getMetrics()); return new RegisteredPipelineVisitor(pipelineModel); } + @Override + public void visitSource(Component component) { + this.model.setComponent(component); + } + @Override public void visitCondition(String condition) { - this.model.type = (ComponentType.IF); this.model.condition = (condition); } @Override - public ComponentVisitor visitComponent(Component component) { - String identifier = ContactUtils.contact(model.getIdentifier(), AuxiliaryUtils.or(component.getName(), component.describe())); + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { + String identifier = ContactUtils.contact(model.getIdentifier(), AuxiliaryUtils.or(name, describe)); String branch = null; - if (this.model.type == ComponentType.CHOOSE) { + if (type == ComponentType.CHOOSE) { identifier = ContactUtils.contact(model.getIdentifier(), "default"); branch = "default"; } - ComponentModel comp = new ComponentModel(identifier, component); + ComponentModel comp = new ComponentModel(identifier); comp.setBranch(branch); + comp.setType(type); this.model.addComponent(comp); return new RegisteredComponentVisitor(comp); } @@ -60,10 +62,10 @@ public class RegisteredComponentVisitor extends ComponentVisitor { } @Override - public ComponentVisitor visitBranch(Object branch, Component component) { - ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), "branch", String.valueOf(branch)), component); + public ComponentVisitor visitBranch(Object branch, ComponentType type, String name, String describe) { + ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), "branch", String.valueOf(branch))); model.setBranch((String.valueOf(branch))); - this.model.type = (ComponentType.CHOOSE); + this.model.type = type; this.model.addComponent(model); return new RegisteredComponentVisitor(model); } @@ -71,6 +73,5 @@ public class RegisteredComponentVisitor extends ComponentVisitor { @Override public void visitExecutable(String executable) { this.model.executable = (executable); - this.model.type = (ComponentType.BASIC); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java index 9c62bad..c35f0f1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java @@ -1,6 +1,7 @@ package org.smartboot.flow.core.manager; -import org.smartboot.flow.core.component.Component; +import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.smartboot.flow.core.util.ContactUtils; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -20,8 +21,14 @@ public class RegisteredPipelineVisitor extends PipelineVisitor { } @Override - public ComponentVisitor visitComponent(Component component) { - ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), AuxiliaryUtils.or(component.getName(), component.describe())), component); + public void visitSource(Pipeline pipeline) { + pipelineModel.setMetrics(pipeline.getMetrics()); + } + + @Override + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { + ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), AuxiliaryUtils.or(name, describe))); + comp.setType(type); this.pipelineModel.addComponent(comp); return new RegisteredComponentVisitor(comp); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index bba5d5e..a7bf12a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -4,6 +4,8 @@ import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.util.AuxiliaryUtils; +import org.smartboot.flow.core.visitor.ComponentVisitor; +import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.ArrayList; import java.util.List; @@ -12,96 +14,60 @@ import java.util.List; * @author yamikaze * @date 2022/11/14 */ -public class PlantumlComponent { +public class PlantumlComponent extends ComponentVisitor { private final List attributes = new ArrayList<>(); - private String name; - private String describe; + private final String name; + private final String describe; // basic, if, choose, pipeline; - private ComponentType type; + private final ComponentType type; // Used with type pipeline. private PlantumlPipeline pipeline; private String condition; private String branch; private final List components = new ArrayList<>(); - private String executable; + private volatile boolean eraserCalled; - public PlantumlComponent(String name, String describe) { + public PlantumlComponent(ComponentType type, String name, String describe) { this.name = name; this.describe = describe; - } - - public List getAttributes() { - return attributes; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescribe() { - return describe; - } - - public void setDescribe(String describe) { - this.describe = describe; - } - - public ComponentType getType() { - if (type == null && condition != null) { - type = ComponentType.IF; - } - - return type; - } - - public void setType(ComponentType type) { this.type = type; } - public PlantumlPipeline getPipeline() { - return pipeline; + @Override + public PipelineVisitor visitPipeline(String pipeline) { + this.pipeline = new PlantumlPipeline(pipeline); + return this.pipeline; } - public void setPipeline(PlantumlPipeline pipeline) { - this.pipeline = pipeline; - } - - public String getCondition() { - return condition; - } - - public void setCondition(String condition) { + @Override + public void visitCondition(String condition) { this.condition = condition; } - public String getBranch() { - return branch; - } - - public void setBranch(String branch) { - this.branch = branch; - } - - public void addComponent(PlantumlComponent component) { + @Override + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { + PlantumlComponent component = new PlantumlComponent(type, name, describe); this.components.add(component); + return component; } - public String getExecutable() { - return executable; + @Override + public void visitAttributes(List attributes) { + this.attributes.addAll(attributes); } - public void setExecutable(String executable) { - this.executable = executable; + @Override + public ComponentVisitor visitBranch(Object branch, ComponentType type, String name, String describe) { + PlantumlComponent component = new PlantumlComponent(type, name, describe); + component.branch = (String.valueOf(branch)); + this.components.add(component); + return component; } public void generate(StringBuilder content) { String nodeName = AuxiliaryUtils.isBlank(name) ? describe : name; - ComponentType type = getType(); + ComponentType type = this.type; if (type == ComponentType.BASIC) { String serialAttributes = serialAttributes(); @@ -125,7 +91,7 @@ public class PlantumlComponent { content.append("switch (").append(condition).append(")\n"); for (PlantumlComponent component : components) { - if (component.getBranch() != null) { + if (component.branch != null) { content.append("case (branch ").append(component.branch).append(")\n"); } else { content.append("case (default) \n"); @@ -185,4 +151,29 @@ public class PlantumlComponent { return base; } + + public void eraser(boolean directPipeline) { + if (eraserCalled) { + return; + } + + eraserCalled = true; + + // 未直接在流水线中,需要擦除所有属性,除了name, 如果是基本组件,可以保留degradable和callback + if (!directPipeline) { + this.attributes.removeIf(p -> { + if (type != ComponentType.BASIC) { + return p.getAttribute() != Attributes.NAME; + } + + return p.getAttribute() != Attributes.DEGRADABLE && p.getAttribute() != Attributes.DEGRADE_CALLBACK; + }); + } + + if (this.type == ComponentType.PIPELINE) { + this.pipeline.eraser(); + } else if (this.type != ComponentType.BASIC) { + this.components.forEach(p -> p.eraser(false)); + } + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java deleted file mode 100644 index 802ddbb..0000000 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponentVisitor.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.smartboot.flow.core.view.plantuml; - -import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.common.ComponentType; -import org.smartboot.flow.core.attribute.AttributeHolder; -import org.smartboot.flow.core.component.AdapterComponent; -import org.smartboot.flow.core.component.Component; -import org.smartboot.flow.core.visitor.ComponentVisitor; -import org.smartboot.flow.core.visitor.PipelineVisitor; - -import java.util.List; - -/** - * @author qinluo - * @date 2022-11-14 19:48:45 - * @since 1.0.0 - */ -public class PlantumlComponentVisitor extends ComponentVisitor { - - private final PlantumlComponent plantumlComponent; - - public PlantumlComponentVisitor(PlantumlComponent plantumlComponent) { - this.plantumlComponent = plantumlComponent; - } - - @Override - public PipelineVisitor visitPipeline(Pipeline pipeline) { - PlantumlPipeline plantumlPipeline = new PlantumlPipeline(); - plantumlPipeline.setName(pipeline.describe()); - plantumlComponent.setPipeline(plantumlPipeline); - plantumlComponent.setType(ComponentType.PIPELINE); - return new PlantumlPipelineVisitor(plantumlPipeline); - } - - @Override - public void visitCondition(String condition) { - plantumlComponent.setCondition(condition); - } - - @Override - public ComponentVisitor visitComponent(Component comp) { - PlantumlComponent component = new PlantumlComponent(comp.getName(), comp.describe()); - component.setType(comp instanceof AdapterComponent ? ComponentType.ADAPTER : null); - this.plantumlComponent.addComponent(component); - return new PlantumlComponentVisitor(component); - } - - @Override - public void visitAttributes(List attributes) { - this.plantumlComponent.getAttributes().addAll(attributes); - } - - @Override - public ComponentVisitor visitBranch(Object branch, Component comp) { - PlantumlComponent component = new PlantumlComponent(comp.getName(), comp.describe()); - component.setBranch(String.valueOf(branch)); - this.plantumlComponent.addComponent(component); - this.plantumlComponent.setType(ComponentType.CHOOSE); - return new PlantumlComponentVisitor(component); - } - - @Override - public void visitExecutable(String executable) { - this.plantumlComponent.setType(ComponentType.BASIC); - this.plantumlComponent.setExecutable(executable); - } -} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngine.java deleted file mode 100644 index d03f189..0000000 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngine.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.smartboot.flow.core.view.plantuml; - -/** - * @author yamikaze - * @date 2022/11/14 - */ -public class PlantumlEngine { - - /** - * engine name. - */ - private String name; - private PlantumlPipeline pipeline; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public PlantumlPipeline getPipeline() { - return pipeline; - } - - public void setPipeline(PlantumlPipeline pipeline) { - this.pipeline = pipeline; - } -} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java index fe2d52f..6d47dc6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java @@ -2,7 +2,7 @@ package org.smartboot.flow.core.view.plantuml; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.Pipeline; +import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.visitor.EngineVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; @@ -25,7 +25,6 @@ public class PlantumlEngineVisitor extends EngineVisitor { private static final String END = "@enduml"; private static final String SUFFIX = ".puml"; - private final PlantumlEngine plantumlEngine = new PlantumlEngine(); // plantuml file dest. private final String dest; /** @@ -33,19 +32,25 @@ public class PlantumlEngineVisitor extends EngineVisitor { */ private String name; private PlantumlPipeline pipeline; - private Executor executor; public PlantumlEngineVisitor(String dest) { this.dest = dest + SUFFIX; } + public void visit(FlowEngine engine) { + engine.visit(this); + } + @Override public void visitEnd() { + // eraser不需要的属性 + this.pipeline.eraser(); + StringBuilder content = new StringBuilder(); content.append(START).append("\n"); content.append("skinparam ConditionEndStyle hline\n"); - content.append("note right\n Engine:").append(plantumlEngine.getName()) - .append(",MainProcess:").append(plantumlEngine.getPipeline().getName()) + content.append("note right\n Engine:").append(this.name) + .append(",MainProcess:").append(pipeline.getName()) .append("\nend note \n").append("-[hidden]->\n"); content.append("split\n"); @@ -69,7 +74,7 @@ public class PlantumlEngineVisitor extends EngineVisitor { content.append("\n : start ;\n"); - plantumlEngine.getPipeline().generate(content); + this.pipeline.generate(content); content.append("\n : end ;\n"); @@ -88,14 +93,11 @@ public class PlantumlEngineVisitor extends EngineVisitor { @Override public void visit(String engine, Executor executor) { this.name = engine; - this.executor = executor; } @Override public PipelineVisitor visitPipeline(String pipeline) { - PlantumlPipeline plantumlPipeline = new PlantumlPipeline(); - plantumlPipeline.setName(pipeline); - plantumlEngine.setPipeline(plantumlPipeline); - return new PlantumlPipelineVisitor(plantumlPipeline); + this.pipeline = new PlantumlPipeline(pipeline); + return this.pipeline; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java index 2efe09f..cf3a9a0 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java @@ -1,5 +1,9 @@ package org.smartboot.flow.core.view.plantuml; +import org.smartboot.flow.core.common.ComponentType; +import org.smartboot.flow.core.visitor.ComponentVisitor; +import org.smartboot.flow.core.visitor.PipelineVisitor; + import java.util.ArrayList; import java.util.List; @@ -7,27 +11,31 @@ import java.util.List; * @author yamikaze * @date 2022/11/14 */ -public class PlantumlPipeline { +public class PlantumlPipeline extends PipelineVisitor { - private String name; + private volatile boolean eraserCalled; + private final String name; private final List components = new ArrayList<>(); public String getName() { return name; } - public void setName(String name) { + public PlantumlPipeline(String name) { this.name = name; } - public void addComponent(PlantumlComponent component) { - this.components.add(component); - } - public List getComponents() { return components; } + @Override + public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { + PlantumlComponent component = new PlantumlComponent(type, name, describe); + this.components.add(component); + return component; + } + public void generate(StringBuilder content) { for (PlantumlComponent component : components) { @@ -35,4 +43,16 @@ public class PlantumlPipeline { } } + + public void eraser() { + if (eraserCalled) { + return; + } + + eraserCalled = true; + + for (PlantumlComponent component : components) { + component.eraser(true); + } + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java deleted file mode 100644 index a9df19a..0000000 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipelineVisitor.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.smartboot.flow.core.view.plantuml; - -import org.smartboot.flow.core.common.ComponentType; -import org.smartboot.flow.core.component.AdapterComponent; -import org.smartboot.flow.core.component.Component; -import org.smartboot.flow.core.visitor.ComponentVisitor; -import org.smartboot.flow.core.visitor.PipelineVisitor; - -/** - * @author qinluo - * @date 2022-11-14 19:48:21 - * @since 1.0.0 - */ -public class PlantumlPipelineVisitor extends PipelineVisitor { - - private final PlantumlPipeline pipeline; - - public PlantumlPipelineVisitor(PlantumlPipeline pipeline) { - this.pipeline = pipeline; - } - - @Override - public ComponentVisitor visitComponent(Component comp) { - PlantumlComponent component = new PlantumlComponent(comp.getName(), comp.describe()); - component.setType(comp instanceof AdapterComponent ? ComponentType.ADAPTER : null); - this.pipeline.addComponent(component); - return new PlantumlComponentVisitor(component); - } -} -- Gitee From c5dcbb5849a28190b6b6df9852782a488afe89ea Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 13 Dec 2022 22:08:02 +0800 Subject: [PATCH 40/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20Visitor?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/core/view/plantuml/PlantumlComponent.java | 2 +- .../flow/core/view/plantuml/PlantumlEngineVisitor.java | 10 +++++++++- .../flow/core/view/plantuml/PlantumlPipeline.java | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index a7bf12a..a922c22 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -36,7 +36,7 @@ public class PlantumlComponent extends ComponentVisitor { @Override public PipelineVisitor visitPipeline(String pipeline) { - this.pipeline = new PlantumlPipeline(pipeline); + this.pipeline = new PlantumlPipeline(pipeline, null); return this.pipeline; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java index 6d47dc6..8da8ab1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java @@ -10,6 +10,8 @@ import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.OutputStreamWriter; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.Executor; /** @@ -33,6 +35,11 @@ public class PlantumlEngineVisitor extends EngineVisitor { private String name; private PlantumlPipeline pipeline; + /** + * 记录访问过的对象 + */ + private final Set visitedSources = new HashSet<>(); + public PlantumlEngineVisitor(String dest) { this.dest = dest + SUFFIX; } @@ -97,7 +104,8 @@ public class PlantumlEngineVisitor extends EngineVisitor { @Override public PipelineVisitor visitPipeline(String pipeline) { - this.pipeline = new PlantumlPipeline(pipeline); + this.visitedSources.add(pipeline); + this.pipeline = new PlantumlPipeline(pipeline, visitedSources); return this.pipeline; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java index cf3a9a0..bcc2f61 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java @@ -5,7 +5,9 @@ import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author yamikaze @@ -16,13 +18,18 @@ public class PlantumlPipeline extends PipelineVisitor { private volatile boolean eraserCalled; private final String name; private final List components = new ArrayList<>(); + /** + * 记录访问过的对象 + */ + private final Set visitedSources; public String getName() { return name; } - public PlantumlPipeline(String name) { + public PlantumlPipeline(String name, Set visitedSources) { this.name = name; + this.visitedSources = visitedSources; } public List getComponents() { -- Gitee From c4de3b8386c3117f4a112eb5b219cfdbe8f5241d Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 14 Dec 2022 10:37:39 +0800 Subject: [PATCH 41/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E7=94=9F?= =?UTF-8?q?=E6=88=90uml=E4=BC=98=E5=8C=96=E5=BE=AA=E7=8E=AF=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/view/plantuml/PlantumlComponent.java | 21 +++++++++++++++---- .../view/plantuml/PlantumlEngineVisitor.java | 5 ++--- .../core/view/plantuml/PlantumlPipeline.java | 18 ++++++++++++++-- .../src/main/resources/flow-example-while.xml | 5 ++++- .../example/parser/DefaultParserTest.java | 9 ++++---- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index a922c22..02f071d 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -9,6 +9,7 @@ import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.ArrayList; import java.util.List; +import java.util.Set; /** * @author yamikaze @@ -27,16 +28,21 @@ public class PlantumlComponent extends ComponentVisitor { private String branch; private final List components = new ArrayList<>(); private volatile boolean eraserCalled; + /** + * 记录访问过的对象 + */ + private final Set visited; - public PlantumlComponent(ComponentType type, String name, String describe) { + public PlantumlComponent(ComponentType type, String name, String describe, Set visited) { this.name = name; this.describe = describe; this.type = type; + this.visited = visited; } @Override public PipelineVisitor visitPipeline(String pipeline) { - this.pipeline = new PlantumlPipeline(pipeline, null); + this.pipeline = new PlantumlPipeline(pipeline, visited); return this.pipeline; } @@ -47,7 +53,7 @@ public class PlantumlComponent extends ComponentVisitor { @Override public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { - PlantumlComponent component = new PlantumlComponent(type, name, describe); + PlantumlComponent component = new PlantumlComponent(type, name, describe, visited); this.components.add(component); return component; } @@ -59,7 +65,7 @@ public class PlantumlComponent extends ComponentVisitor { @Override public ComponentVisitor visitBranch(Object branch, ComponentType type, String name, String describe) { - PlantumlComponent component = new PlantumlComponent(type, name, describe); + PlantumlComponent component = new PlantumlComponent(type, name, describe, visited); component.branch = (String.valueOf(branch)); this.components.add(component); return component; @@ -102,6 +108,13 @@ public class PlantumlComponent extends ComponentVisitor { content.append("endswitch\n"); } else if (type == ComponentType.PIPELINE) { + if (pipeline.isCycle()) { + content.append(": goto ").append(pipeline.getName()).append(";\n"); + // kill this branch. + content.append("kill\n "); + return; + } + content.append("partition 子流程:").append(pipeline.getName()).append("{ \n"); pipeline.generate(content); content.append(" } \n"); diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java index 8da8ab1..5e0dfba 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java @@ -56,9 +56,8 @@ public class PlantumlEngineVisitor extends EngineVisitor { StringBuilder content = new StringBuilder(); content.append(START).append("\n"); content.append("skinparam ConditionEndStyle hline\n"); - content.append("note right\n Engine:").append(this.name) - .append(",MainProcess:").append(pipeline.getName()) - .append("\nend note \n").append("-[hidden]->\n"); + content.append("title Engine:").append(this.name) + .append(",MainProcess:").append(pipeline.getName()).append("\n"); content.append("split\n"); for (Color color : Color.values()) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java index bcc2f61..2f8701f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java @@ -1,11 +1,11 @@ package org.smartboot.flow.core.view.plantuml; +import org.smartboot.flow.core.Pipeline; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -22,11 +22,16 @@ public class PlantumlPipeline extends PipelineVisitor { * 记录访问过的对象 */ private final Set visitedSources; + private boolean cycle; public String getName() { return name; } + public boolean isCycle() { + return cycle; + } + public PlantumlPipeline(String name, Set visitedSources) { this.name = name; this.visitedSources = visitedSources; @@ -36,9 +41,18 @@ public class PlantumlPipeline extends PipelineVisitor { return components; } + @Override + public void visitSource(Pipeline pipeline) { + this.cycle = !visitedSources.add(pipeline); + } + @Override public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { - PlantumlComponent component = new PlantumlComponent(type, name, describe); + if (this.isCycle()) { + return null; + } + + PlantumlComponent component = new PlantumlComponent(type, name, describe, visitedSources); this.components.add(component); return component; } diff --git a/smart-flow-example/src/main/resources/flow-example-while.xml b/smart-flow-example/src/main/resources/flow-example-while.xml index 6c12bca..2468c46 100644 --- a/smart-flow-example/src/main/resources/flow-example-while.xml +++ b/smart-flow-example/src/main/resources/flow-example-while.xml @@ -9,7 +9,7 @@ - + @@ -17,6 +17,9 @@ + + + diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index acf4d08..5a618b2 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -174,8 +174,6 @@ public class DefaultParserTest { EngineContext execute = testEngine.execute(1); LOGGER.info("trace \n{}", execute.getTrace()); - LOGGER.error("fatal ", execute.getFatal()); - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); visitor.visit(testEngine); } @@ -196,7 +194,10 @@ public class DefaultParserTest { } }); - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); +// EngineContext execute = testEngine.execute(1); +// LOGGER.info("trace \n{}", execute.getTrace()); + + PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); + visitor.visit(testEngine); } } -- Gitee From 66c159cb5dc977d84d269846a22db9c5ea3a1b9c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 14 Dec 2022 10:44:18 +0800 Subject: [PATCH 42/54] qinluo: - rename --- .../flow/core/view/plantuml/PlantumlEngineVisitor.java | 5 ++--- .../flow/core/view/plantuml/PlantumlPipeline.java | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java index 5e0dfba..5413c8a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlEngineVisitor.java @@ -38,7 +38,7 @@ public class PlantumlEngineVisitor extends EngineVisitor { /** * 记录访问过的对象 */ - private final Set visitedSources = new HashSet<>(); + private final Set visited = new HashSet<>(); public PlantumlEngineVisitor(String dest) { this.dest = dest + SUFFIX; @@ -103,8 +103,7 @@ public class PlantumlEngineVisitor extends EngineVisitor { @Override public PipelineVisitor visitPipeline(String pipeline) { - this.visitedSources.add(pipeline); - this.pipeline = new PlantumlPipeline(pipeline, visitedSources); + this.pipeline = new PlantumlPipeline(pipeline, visited); return this.pipeline; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java index 2f8701f..76dced6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlPipeline.java @@ -21,7 +21,7 @@ public class PlantumlPipeline extends PipelineVisitor { /** * 记录访问过的对象 */ - private final Set visitedSources; + private final Set visited; private boolean cycle; public String getName() { @@ -32,9 +32,9 @@ public class PlantumlPipeline extends PipelineVisitor { return cycle; } - public PlantumlPipeline(String name, Set visitedSources) { + public PlantumlPipeline(String name, Set visited) { this.name = name; - this.visitedSources = visitedSources; + this.visited = visited; } public List getComponents() { @@ -43,7 +43,7 @@ public class PlantumlPipeline extends PipelineVisitor { @Override public void visitSource(Pipeline pipeline) { - this.cycle = !visitedSources.add(pipeline); + this.cycle = !visited.add(pipeline); } @Override @@ -52,7 +52,7 @@ public class PlantumlPipeline extends PipelineVisitor { return null; } - PlantumlComponent component = new PlantumlComponent(type, name, describe, visitedSources); + PlantumlComponent component = new PlantumlComponent(type, name, describe, visited); this.components.add(component); return component; } -- Gitee From fae5d00df11ebef9ea0d229c183d8992ef7a7fa8 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 14 Dec 2022 20:42:43 +0800 Subject: [PATCH 43/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E8=B7=AF=E5=BE=84=E4=BC=98=E5=8C=96=20=20=20=20=20=20?= =?UTF-8?q?-=20=E7=AE=A1=E7=90=86=E8=AE=BF=E9=97=AE=E5=99=A8fix=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=B5=81=E7=A8=8B=20=20=20=20=20=20-=20=E5=85=B6?= =?UTF-8?q?=E4=BB=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartboot/flow/core/AsyncCallResult.java | 7 -- .../org/smartboot/flow/core/Condition.java | 4 +- .../flow/core/invoker/AsyncRunner.java | 17 ++--- .../smartboot/flow/core/invoker/Invoker.java | 40 ++++------ .../flow/core/invoker/TransparentContext.java | 73 ------------------- .../flow/core/manager/ComponentModel.java | 15 +--- .../core/manager/RegisterEngineVisitor.java | 6 +- .../manager/RegisteredComponentVisitor.java | 19 ++--- .../manager/RegisteredPipelineVisitor.java | 18 ++++- .../org/smartboot/flow/core/trace/Node.java | 42 +++++------ .../org/smartboot/flow/core/trace/Tracer.java | 8 ++ .../core/view/plantuml/PlantumlComponent.java | 25 +++++++ ...flow-example-parse-single-as-component.xml | 4 +- .../src/main/resources/flow-example-while.xml | 6 +- .../src/main/resources/flow-example7.xsd | 1 + .../example/parser/DefaultParserTest.java | 4 +- .../flow/manager/change/ChangeModel.java | 2 +- .../flow/manager/change/HttpManager.java | 1 - .../flow/manager/change}/ManagerAction.java | 2 +- 19 files changed, 121 insertions(+), 173 deletions(-) delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java rename {smart-flow-core/src/main/java/org/smartboot/flow/core/manager => smart-flow-manager/src/main/java/org/smartboot/flow/manager/change}/ManagerAction.java (92%) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java index 2364212..7d3ea68 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/AsyncCallResult.java @@ -2,7 +2,6 @@ package org.smartboot.flow.core; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.invoker.InvokeListener; -import org.smartboot.flow.core.invoker.TransparentContext; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -80,10 +79,4 @@ public class AsyncCallResult { } } - - private TransparentContext ctx; - - public void setTransparentContext(TransparentContext ctx) { - this.ctx = ctx; - } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Condition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Condition.java index 83555a1..24c956b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Condition.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Condition.java @@ -11,7 +11,9 @@ public abstract class Condition implements Describable { return this.test(context.getReq(), context.getResult()); } - public abstract Object test(T t, S s); + public Object test(T t, S s) { + return null; + } @Override public String describe() { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java index ac4b2ae..80137d7 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java @@ -1,5 +1,8 @@ package org.smartboot.flow.core.invoker; +import org.smartboot.flow.core.trace.Node; +import org.smartboot.flow.core.trace.Tracer; + import java.util.concurrent.Callable; /** @@ -9,21 +12,17 @@ import java.util.concurrent.Callable; */ public class AsyncRunner implements Callable { - private final boolean degradable; private final Callable task; + private final Node root; - public AsyncRunner(boolean degradable, Callable task) { - this.degradable = degradable; + public AsyncRunner(Callable task) { this.task = task; + this.root = Tracer.get(); } @Override public Integer call() throws Exception { - TransparentContext.enter(degradable); - try { - return task.call(); - } finally { - TransparentContext.exit(); - } + Tracer.setNode(root); + return task.call(); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java index ffdd617..51ac717 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/Invoker.java @@ -37,31 +37,23 @@ public class Invoker { return -1; } - TransparentContext.enter(component.isDegradable()); - - try { - InvokeListener listener = new InvokeListeners(listeners); - if (component.isAsync()) { - AssertUtil.notNull(context.getExecutor(), "executor must not be null"); - TransparentContext ctx = TransparentContext.current(); - - AsyncRunner runner = new AsyncRunner(ctx.getDegradable(), () -> execute(component, context, listener)); - Future submitted = context.getExecutor().submit(runner); - AsyncCallResult result = new AsyncCallResult<>(); - result.setFuture(submitted); - result.setName(component.getName()); - result.setTimeout(component.getTimeout()); - result.setSource(component); - result.setListeners(listener); - result.setTransparentContext(ctx); - context.addAsyncInvoke(result); - return 1; - } - - return execute(component, context, listener); - } finally { - TransparentContext.exit(); + InvokeListener listener = new InvokeListeners(listeners); + if (component.isAsync()) { + AssertUtil.notNull(context.getExecutor(), "executor must not be null"); + + AsyncRunner runner = new AsyncRunner(() -> execute(component, context, listener)); + Future submitted = context.getExecutor().submit(runner); + AsyncCallResult result = new AsyncCallResult<>(); + result.setFuture(submitted); + result.setName(component.getName()); + result.setTimeout(component.getTimeout()); + result.setSource(component); + result.setListeners(listener); + context.addAsyncInvoke(result); + return 1; } + + return execute(component, context, listener); } private int execute(Component component, diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java deleted file mode 100644 index b979326..0000000 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/TransparentContext.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.smartboot.flow.core.invoker; - -import org.smartboot.flow.core.util.AuxiliaryUtils; - -import java.io.Serializable; - -/** - * 用于透传组件上下文传值 - * - * @author qinluo - * @date 2022-12-07 21:47:26 - * @since 1.0.0 - */ -public class TransparentContext implements Serializable { - private static final long serialVersionUID = -3033584753584750611L; - - private static final ThreadLocal CURRENT = new InheritableThreadLocal<>(); - - public static TransparentContext current() { - TransparentContext ctx = CURRENT.get(); - return AuxiliaryUtils.or(ctx, new TransparentContext()); - } - - public static void enter(boolean degradable) { - TransparentContext ctx = CURRENT.get(); - if (ctx == null) { - ctx = new TransparentContext(); - CURRENT.set(ctx); - return; - } - - TransparentContext child = new TransparentContext(); - child.setParent(ctx); - child.setDegradable(degradable || ctx.degradable); - CURRENT.set(child); - } - - public static void exit() { - TransparentContext ctx = CURRENT.get(); - if (ctx == null) { - return; - } - - TransparentContext parent = ctx.getParent(); - if (parent == null) { - return; - } - - CURRENT.set(parent); - } - - /** - * Parent context. - */ - private TransparentContext parent; - private boolean degradable; - - public boolean getDegradable() { - return degradable; - } - - public void setDegradable(boolean degradable) { - this.degradable = degradable; - } - - public TransparentContext getParent() { - return parent; - } - - public void setParent(TransparentContext parent) { - this.parent = parent; - } -} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java index 3e071db..53115a5 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java @@ -35,16 +35,9 @@ public class ComponentModel extends Uniqueness { private String branch; private Metrics metrics; - ComponentModel(String identifier, Component component) { - this.identifier = identifier; - this.component = component; - this.name = component.getName(); - this.describe = component.describe(); - this.metrics = component.getMetrics(); - } - - ComponentModel(String identifier) { + ComponentModel(ComponentType type, String identifier) { this.identifier = identifier; + this.type = type; } public Map getHolders() { @@ -154,8 +147,4 @@ public class ComponentModel extends Uniqueness { this.describe = component.describe(); this.metrics = component.getMetrics(); } - - public void setType(ComponentType type) { - this.type = type; - } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java index 33c36bc..2743345 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisterEngineVisitor.java @@ -5,6 +5,8 @@ import org.smartboot.flow.core.util.ContactUtils; import org.smartboot.flow.core.visitor.EngineVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.Executor; /** @@ -15,6 +17,7 @@ import java.util.concurrent.Executor; public class RegisterEngineVisitor extends EngineVisitor { private EngineModel model; + private final Set visited = new HashSet<>(32); @Override public void visit(String name, Executor executor) { @@ -23,6 +26,7 @@ public class RegisterEngineVisitor extends EngineVisitor { @Override public void visitSource(FlowEngine flowEngine) { + visited.add(flowEngine); this.model.setMetrics(flowEngine.getMetrics()); } @@ -30,7 +34,7 @@ public class RegisterEngineVisitor extends EngineVisitor { public PipelineVisitor visitPipeline(String pipeline) { PipelineModel pipelineModel = new PipelineModel(pipeline, ContactUtils.contact(this.model.getIdentifier(), pipeline)); this.model.setPipeline(pipelineModel); - return new RegisteredPipelineVisitor(pipelineModel); + return new RegisteredPipelineVisitor(pipelineModel, visited); } @Override diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java index 3d35e38..68f4376 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredComponentVisitor.java @@ -9,6 +9,7 @@ import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; import java.util.List; +import java.util.Set; /** * @author qinluo @@ -18,16 +19,18 @@ import java.util.List; public class RegisteredComponentVisitor extends ComponentVisitor { private final ComponentModel model; + private final Set visited; - public RegisteredComponentVisitor(ComponentModel comp) { + public RegisteredComponentVisitor(ComponentModel comp, Set visited) { this.model = comp; + this.visited = visited; } @Override public PipelineVisitor visitPipeline(String pipeline) { PipelineModel pipelineModel = new PipelineModel(pipeline, ContactUtils.contact(model.getIdentifier(), pipeline)); this.model.pipeline = pipelineModel; - return new RegisteredPipelineVisitor(pipelineModel); + return new RegisteredPipelineVisitor(pipelineModel, visited); } @Override @@ -44,16 +47,15 @@ public class RegisteredComponentVisitor extends ComponentVisitor { public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { String identifier = ContactUtils.contact(model.getIdentifier(), AuxiliaryUtils.or(name, describe)); String branch = null; - if (type == ComponentType.CHOOSE) { + if (this.model.type == ComponentType.CHOOSE) { identifier = ContactUtils.contact(model.getIdentifier(), "default"); branch = "default"; } - ComponentModel comp = new ComponentModel(identifier); + ComponentModel comp = new ComponentModel(type, identifier); comp.setBranch(branch); - comp.setType(type); this.model.addComponent(comp); - return new RegisteredComponentVisitor(comp); + return new RegisteredComponentVisitor(comp, visited); } @Override @@ -63,11 +65,10 @@ public class RegisteredComponentVisitor extends ComponentVisitor { @Override public ComponentVisitor visitBranch(Object branch, ComponentType type, String name, String describe) { - ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), "branch", String.valueOf(branch))); + ComponentModel model = new ComponentModel(type, ContactUtils.contact(this.model.getIdentifier(), "branch", String.valueOf(branch))); model.setBranch((String.valueOf(branch))); - this.model.type = type; this.model.addComponent(model); - return new RegisteredComponentVisitor(model); + return new RegisteredComponentVisitor(model, visited); } @Override diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java index c35f0f1..d2e25ee 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/RegisteredPipelineVisitor.java @@ -7,6 +7,8 @@ import org.smartboot.flow.core.util.ContactUtils; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; +import java.util.Set; + /** * @author qinluo * @date 2022/11/19 12:26 @@ -15,21 +17,29 @@ import org.smartboot.flow.core.visitor.PipelineVisitor; public class RegisteredPipelineVisitor extends PipelineVisitor { private final PipelineModel pipelineModel; + private final Set visited; + private boolean isCycle; - public RegisteredPipelineVisitor(PipelineModel pipelineModel) { + public RegisteredPipelineVisitor(PipelineModel pipelineModel, Set visited) { this.pipelineModel = pipelineModel; + this.visited = visited; } @Override public void visitSource(Pipeline pipeline) { + this.isCycle = !this.visited.add(pipeline); pipelineModel.setMetrics(pipeline.getMetrics()); } @Override public ComponentVisitor visitComponent(ComponentType type, String name, String describe) { - ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), AuxiliaryUtils.or(name, describe))); - comp.setType(type); + // Avoid stackOverflow + if (isCycle) { + return null; + } + + ComponentModel comp = new ComponentModel(type, ContactUtils.contact(this.pipelineModel.getIdentifier(), AuxiliaryUtils.or(name, describe))); this.pipelineModel.addComponent(comp); - return new RegisteredComponentVisitor(comp); + return new RegisteredComponentVisitor(comp, visited); } } 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 12b214c..243deb2 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,6 +1,7 @@ package org.smartboot.flow.core.trace; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; /** @@ -19,22 +20,19 @@ public class Node { * Node escaped time in mills. */ private long escaped; + private final long timestamp; /** * Parent Node. */ private Node parent; + private boolean async; /** * Children nodes. */ private final List children = new ArrayList<>(16); - /** - * Children nodes in another threads. - */ - private final List threadChildren = new ArrayList<>(16); - /** * Create this node object's thread. */ @@ -56,10 +54,6 @@ public class Node { return children; } - public List getThreadChildren() { - return threadChildren; - } - public long getThreadId() { return threadId; } @@ -74,14 +68,14 @@ public class Node { public Node(String message) { this.message = message; this.escaped = System.currentTimeMillis(); + this.timestamp = escaped; } public void addChild(Node node) { - if (node.threadId == threadId) { - children.add(node); - } else { - threadChildren.add(node); + if (node.threadId != threadId) { + node.async = true; } + children.add(node); } public Node getParent() { @@ -99,21 +93,25 @@ public class Node { public void dump(String prefix, StringBuilder sb) { sb.append(prefix).append(wrap(message)).append(" escaped ").append(escaped).append("ms"); sb.append("\n"); - if (children.isEmpty() && threadChildren.isEmpty()) { + if (children.isEmpty()) { return; } - int i = 0; - for (Node child : children) { - String nextPrefix = generatePrefix(prefix, false,i++ >= children.size()); - child.dump(nextPrefix, sb); + children.sort((Comparator.comparingLong(o -> o.timestamp))); + boolean hasNextBrother = hasNextBrother(); + + for (Node node : children) { + String nextPrefix = generatePrefix(prefix, node.async, hasNextBrother); + node.dump(nextPrefix, sb); } + } - i = 0; - for (Node child : threadChildren) { - String nextPrefix = generatePrefix(prefix, true, i++ >= threadChildren.size()); - child.dump(nextPrefix, sb); + private boolean hasNextBrother() { + if (parent == null || parent.children.isEmpty()) { + return false; } + + return parent.children.indexOf(this) < parent.children.size() - 1; } private String generatePrefix(String prefix, boolean async, boolean hasNext) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java index 1548213..b94ea3a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/trace/Tracer.java @@ -73,4 +73,12 @@ public class Tracer { this.trace = null; TOP.remove(); } + + public static Node get() { + return TOP.get(); + } + + public static void setNode(Node n) { + TOP.set(n); + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java index 02f071d..cc81ab4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java @@ -77,6 +77,9 @@ public class PlantumlComponent extends ComponentVisitor { if (type == ComponentType.BASIC) { String serialAttributes = serialAttributes(); + if (isAsync()) { + content.append("-[dashed]->异步;\n"); + } content.append(getColor()).append(":").append(nodeName).append(";\n"); if (serialAttributes.trim().length() > 0) { @@ -85,6 +88,9 @@ public class PlantumlComponent extends ComponentVisitor { } } else if (type == ComponentType.IF) { + if (isAsync()) { + content.append("-[dashed]->异步;\n"); + } content.append("if (").append(condition).append(") then (true)\n"); components.get(0).generate(content); if (components.size() >= 2) { @@ -94,6 +100,9 @@ public class PlantumlComponent extends ComponentVisitor { content.append("endif\n"); } else if (type == ComponentType.CHOOSE) { + if (isAsync()) { + content.append("-[dashed]->异步;\n"); + } content.append("switch (").append(condition).append(")\n"); for (PlantumlComponent component : components) { @@ -108,6 +117,9 @@ public class PlantumlComponent extends ComponentVisitor { content.append("endswitch\n"); } else if (type == ComponentType.PIPELINE) { + if (isAsync()) { + content.append("-[dashed]->异步;\n"); + } if (pipeline.isCycle()) { content.append(": goto ").append(pipeline.getName()).append(";\n"); // kill this branch. @@ -119,6 +131,9 @@ public class PlantumlComponent extends ComponentVisitor { pipeline.generate(content); content.append(" } \n"); } else if (type == ComponentType.ADAPTER) { + if (isAsync()) { + content.append("-[dashed]->异步;\n"); + } PlantumlComponent pipeline = components.get(0); content.append("partition 适配器:").append(nodeName) .append(" 子流程:") @@ -138,6 +153,16 @@ public class PlantumlComponent extends ComponentVisitor { return sb.toString(); } + private boolean isAsync() { + for (AttributeHolder holder : attributes) { + if (holder.getAttribute() == Attributes.ASYNC) { + return true; + } + } + + return false; + } + private String getColor() { List colors = new ArrayList<>(); for (AttributeHolder holder : attributes) { diff --git a/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml b/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml index 59d4513..3c933c2 100644 --- a/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml +++ b/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml @@ -11,13 +11,13 @@ - + - + diff --git a/smart-flow-example/src/main/resources/flow-example-while.xml b/smart-flow-example/src/main/resources/flow-example-while.xml index 2468c46..8a99e71 100644 --- a/smart-flow-example/src/main/resources/flow-example-while.xml +++ b/smart-flow-example/src/main/resources/flow-example-while.xml @@ -10,10 +10,10 @@ - - + + - + diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xsd index dd76941..978e1c3 100644 --- a/smart-flow-example/src/main/resources/flow-example7.xsd +++ b/smart-flow-example/src/main/resources/flow-example7.xsd @@ -41,6 +41,7 @@ + \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 5a618b2..14ce9ee 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -194,8 +194,8 @@ public class DefaultParserTest { } }); -// EngineContext execute = testEngine.execute(1); -// LOGGER.info("trace \n{}", execute.getTrace()); + EngineContext execute = testEngine.execute(1); + LOGGER.info("trace \n{}", execute.getTrace()); PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); visitor.visit(testEngine); diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java index d199183..71419cd 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java @@ -13,7 +13,7 @@ public class ChangeModel implements Serializable { /** * Change action * - * @see org.smartboot.flow.core.manager.ManagerAction + * @see ManagerAction */ private String action; diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java index 861e09f..830117b 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java @@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory; import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.manager.DefaultEngineManager; -import org.smartboot.flow.core.manager.ManagerAction; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.manager.NamedThreadFactory; import org.smartboot.flow.manager.report.HostUtils; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ManagerAction.java similarity index 92% rename from smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java rename to smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ManagerAction.java index b0d536f..1aace0a 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ManagerAction.java @@ -1,4 +1,4 @@ -package org.smartboot.flow.core.manager; +package org.smartboot.flow.manager.change; import java.util.Objects; -- Gitee From 8fbd5bc1874ef257cd33b80676e8dc3a2e8c97a5 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 14 Dec 2022 21:42:09 +0800 Subject: [PATCH 44/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20readme?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 623ce27..458f52d 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,14 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [X] 支持Spring环境XML配置集成 - [X] 支持实时生成流程引擎结构图 - [X] 支持多种条件表达式(Groovy、OGNL、JavaScript等) - +- [ ] springboot集成 ## 管理功能 - [X] 支持自定义执行数据采集 - [X] 支持HTTP方式引擎数据上报(包含执行数据) - [X] 支持组件动态管理(动态降级、启用组件等功能) -- [ ] 自带简易管理后台 +- [ ] 简易管理后台 - [ ] 支持从数据库等存储介质重新加载 -- Gitee From 0adcda4553691bef757f06cb6d0f6e749c2d24f1 Mon Sep 17 00:00:00 2001 From: huqiang Date: Thu, 15 Dec 2022 16:38:20 +0800 Subject: [PATCH 45/54] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20springboot=20starter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + smart-flow-springboot-extension/pom.xml | 37 ++++++++++++++ .../FlowHttpManageConfiguration.java | 51 +++++++++++++++++++ .../FlowHttpReportConfiguration.java | 45 ++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + 5 files changed, 135 insertions(+) create mode 100644 smart-flow-springboot-extension/pom.xml create mode 100644 smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java create mode 100644 smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java create mode 100644 smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories diff --git a/pom.xml b/pom.xml index 5d99066..ae416ab 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ smart-flow-manager smart-flow-example smart-flow-script-condition + smart-flow-springboot-extension diff --git a/smart-flow-springboot-extension/pom.xml b/smart-flow-springboot-extension/pom.xml new file mode 100644 index 0000000..86ec4a7 --- /dev/null +++ b/smart-flow-springboot-extension/pom.xml @@ -0,0 +1,37 @@ + + + + flow-engine + org.smartboot + 1.0.2 + + 4.0.0 + + smart-flow-springboot-extension + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter + 2.7.5 + + + org.smartboot + smart-flow-spring-extension + 1.0.2 + + + org.smartboot + smart-flow-manager + 1.0.2 + + + + \ No newline at end of file diff --git a/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java new file mode 100644 index 0000000..07ad34c --- /dev/null +++ b/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java @@ -0,0 +1,51 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.manager.change.HttpManager; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author huqiang + * @since 2022/12/14 19:15 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.httpmanage") +public class FlowHttpManageConfiguration { + + private long timeout; + + private String url; + + private long idle; + + private long delayAtFirst; + + @Bean + public HttpManager getHttpManager(){ + HttpManager httpManager = new HttpManager(); + httpManager.setTimeout(timeout); + httpManager.setUrl(url); + httpManager.setIdle(idle); + httpManager.setDelayAtFirst(delayAtFirst); + httpManager.start(); + return httpManager; + } + + + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public void setUrl(String url) { + this.url = url; + } + + public void setIdle(long idle) { + this.idle = idle; + } + + public void setDelayAtFirst(long delayAtFirst) { + this.delayAtFirst = delayAtFirst; + } +} diff --git a/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java b/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java new file mode 100644 index 0000000..bfe24c2 --- /dev/null +++ b/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java @@ -0,0 +1,45 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.manager.report.HttpReporter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * smart flow httReport auto config + * + * @author huqiang + * @since 2022/12/15 16:32 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.httpreport") +public class FlowHttpReportConfiguration { + + + private long timeout; + + private String url; + + private long idle; + + @Bean + public HttpReporter getHttpReporter() { + HttpReporter reporter = new HttpReporter(); + reporter.setTimeout(this.timeout); + reporter.setUrl(this.url); + reporter.setIdle(this.idle); + return reporter; + } + + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public void setUrl(String url) { + this.url = url; + } + + public void setIdle(long idle) { + this.idle = idle; + } +} diff --git a/smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories b/smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..eec163c --- /dev/null +++ b/smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration \ No newline at end of file -- Gitee From 5be2cf834a233f9c9b7e72e79682f1cd408aef4c Mon Sep 17 00:00:00 2001 From: huqiang Date: Thu, 15 Dec 2022 17:20:03 +0800 Subject: [PATCH 46/54] springboot starter --- pom.xml | 2 +- .../pom.xml | 2 +- .../FlowHttpManageConfiguration.java | 0 .../FlowHttpReportConfiguration.java | 0 .../extension/FlowParseConfiguration.java | 34 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 +- 6 files changed, 37 insertions(+), 3 deletions(-) rename {smart-flow-springboot-extension => smart-flow-springboot-starter}/pom.xml (95%) rename {smart-flow-springboot-extension => smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java (100%) rename {smart-flow-springboot-extension => smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java (100%) create mode 100644 smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java rename {smart-flow-springboot-extension => smart-flow-springboot-starter}/src/main/resources/META-INF/spring.factories (73%) diff --git a/pom.xml b/pom.xml index ae416ab..adbc25d 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ smart-flow-manager smart-flow-example smart-flow-script-condition - smart-flow-springboot-extension + smart-flow-springboot-starter diff --git a/smart-flow-springboot-extension/pom.xml b/smart-flow-springboot-starter/pom.xml similarity index 95% rename from smart-flow-springboot-extension/pom.xml rename to smart-flow-springboot-starter/pom.xml index 86ec4a7..8d0f033 100644 --- a/smart-flow-springboot-extension/pom.xml +++ b/smart-flow-springboot-starter/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - smart-flow-springboot-extension + smart-flow-springboot-starter 8 diff --git a/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java similarity index 100% rename from smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java rename to smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java diff --git a/smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java similarity index 100% rename from smart-flow-springboot-extension/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java rename to smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java new file mode 100644 index 0000000..217811c --- /dev/null +++ b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java @@ -0,0 +1,34 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.core.parser.DefaultParser; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author huqiang + * @since 2022/12/15 16:44 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.engine") +public class FlowParseConfiguration { + + private String file; + + private String[] files; + + @Bean + public DefaultParser getParse() { + DefaultParser defaultParser = new DefaultParser(); + defaultParser.parse(file, files); + return defaultParser; + } + + public void setFile(String file) { + this.file = file; + } + + public void setFiles(String[] files) { + this.files = files; + } +} diff --git a/smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories b/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories similarity index 73% rename from smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories rename to smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories index eec163c..4f1f073 100644 --- a/smart-flow-springboot-extension/src/main/resources/META-INF/spring.factories +++ b/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration,org.smartboot.flow.springboot.extension.FlowParseConfiguration \ No newline at end of file -- Gitee From 50e22ccef9f349e5e61d6fc187ecf283d396fe4d Mon Sep 17 00:00:00 2001 From: yisshengyouni Date: Fri, 16 Dec 2022 10:45:25 +0800 Subject: [PATCH 47/54] =?UTF-8?q?=E5=88=A0=E9=99=A4spring=20starter?= =?UTF-8?q?=E7=9A=84=20xml=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extension/FlowParseConfiguration.java | 34 ------------------- .../main/resources/META-INF/spring.factories | 4 ++- 2 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java deleted file mode 100644 index 217811c..0000000 --- a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowParseConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.smartboot.flow.springboot.extension; - -import org.smartboot.flow.core.parser.DefaultParser; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author huqiang - * @since 2022/12/15 16:44 - */ -@Configuration -@ConfigurationProperties(prefix = "smart.flow.engine") -public class FlowParseConfiguration { - - private String file; - - private String[] files; - - @Bean - public DefaultParser getParse() { - DefaultParser defaultParser = new DefaultParser(); - defaultParser.parse(file, files); - return defaultParser; - } - - public void setFile(String file) { - this.file = file; - } - - public void setFiles(String[] files) { - this.files = files; - } -} diff --git a/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories b/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories index 4f1f073..cd6d66e 100644 --- a/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories +++ b/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories @@ -1 +1,3 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration,org.smartboot.flow.springboot.extension.FlowParseConfiguration \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,\ + org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration \ No newline at end of file -- Gitee From fe17354077bff18dda9d22395992f3ea5fe1f529 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 16 Dec 2022 14:43:19 +0800 Subject: [PATCH 48/54] qinluo: - rename prefix --- .../flow/springboot/extension/FlowHttpManageConfiguration.java | 2 +- .../flow/springboot/extension/FlowHttpReportConfiguration.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java index 07ad34c..e092c46 100644 --- a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java +++ b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java @@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration; * @since 2022/12/14 19:15 */ @Configuration -@ConfigurationProperties(prefix = "smart.flow.httpmanage") +@ConfigurationProperties(prefix = "smart.flow.manage.http") public class FlowHttpManageConfiguration { private long timeout; diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java index bfe24c2..5e25516 100644 --- a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java +++ b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration; * @since 2022/12/15 16:32 */ @Configuration -@ConfigurationProperties(prefix = "smart.flow.httpreport") +@ConfigurationProperties(prefix = "smart.flow.report.http") public class FlowHttpReportConfiguration { -- Gitee From d6bb0e5bba700f4390d1f1e6bdbfd2d529c82db6 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 16 Dec 2022 18:44:17 +0800 Subject: [PATCH 49/54] qinluo: - remove unused code. --- .../smartboot/flow/core/EngineContext.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java index 5bbb681..33ee074 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContext.java @@ -2,24 +2,21 @@ package org.smartboot.flow.core; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.exception.ExceptionHandler; import org.smartboot.flow.core.invoker.Invoker; import org.smartboot.flow.core.trace.Tracer; import java.io.Serializable; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; /** * @author qinluo * @date 2022-11-12 21:00:58 * @since 1.0.0 */ -public class EngineContext implements Cloneable{ +public class EngineContext{ public static final int DISABLED = -1; public static final int EXECUTING = 1; @@ -45,19 +42,6 @@ public class EngineContext implements Cloneable{ protected int executing; protected EngineContext parent; -// public EngineContext newContext(P req, Q result) { -// EngineContext newContext = new EngineContext<>(); -// try { -// newContext = (EngineContext)this.clone(); -// newContext.setReq(req); -// newContext.setResult(result); -// newContext.parent = this; -// } catch (CloneNotSupportedException e) { -// e.printStackTrace(); -// } -// return newContext; -// } - public void copy(EngineContext dest) { // Reuse extensions. dest.extensions = this.extensions; @@ -291,12 +275,7 @@ public class EngineContext implements Cloneable{ * Apply subprocess fields to parent ctx. */ public void apply() { - if (this.parent == null) { - return; - } - // Apply fields to parent; - // this.parent.fatal = this.fatal; } private static class Value implements Serializable { -- Gitee From 97679d55a25ae555787011f61aa620877831391a Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 17 Dec 2022 01:17:25 +0800 Subject: [PATCH 50/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20rename=20=20?= =?UTF-8?q?=20=20=20=20-=20=E5=8D=95=E6=B5=8B=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rade-callback.xsd => degrade-callback.xml} | 0 ...low-example-subprocess-non-degradable.xml} | 0 .../{flow-example.xsd => flow-example.xml} | 0 .../{flow-example3.xsd => flow-example3.xml} | 4 ---- .../{flow-example4.xsd => flow-example4.xml} | 0 .../{flow-example5.xsd => flow-example5.xml} | 0 .../{flow-example6.xsd => flow-example6.xml} | 0 .../{flow-example7.xsd => flow-example7.xml} | 0 .../smartboot/flow/example/EngineTest.java | 5 ++--- .../org/smartboot/flow/example/ParseTest.java | 2 -- .../flow/example/async/AsyncTest.java | 11 +++++++---- .../example/degrade/DegradeCallbackTest.java | 2 +- .../flow/example/manager/ManagerTest.java | 1 + .../example/parser/DefaultParserTest.java | 19 ++++++++++--------- 14 files changed, 21 insertions(+), 23 deletions(-) rename smart-flow-example/src/main/resources/{degrade-callback.xsd => degrade-callback.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example-subprocess-non-degradable.xsd => flow-example-subprocess-non-degradable.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example.xsd => flow-example.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example3.xsd => flow-example3.xml} (86%) rename smart-flow-example/src/main/resources/{flow-example4.xsd => flow-example4.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example5.xsd => flow-example5.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example6.xsd => flow-example6.xml} (100%) rename smart-flow-example/src/main/resources/{flow-example7.xsd => flow-example7.xml} (100%) diff --git a/smart-flow-example/src/main/resources/degrade-callback.xsd b/smart-flow-example/src/main/resources/degrade-callback.xml similarity index 100% rename from smart-flow-example/src/main/resources/degrade-callback.xsd rename to smart-flow-example/src/main/resources/degrade-callback.xml diff --git a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xsd rename to smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml diff --git a/smart-flow-example/src/main/resources/flow-example.xsd b/smart-flow-example/src/main/resources/flow-example.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example.xsd rename to smart-flow-example/src/main/resources/flow-example.xml diff --git a/smart-flow-example/src/main/resources/flow-example3.xsd b/smart-flow-example/src/main/resources/flow-example3.xml similarity index 86% rename from smart-flow-example/src/main/resources/flow-example3.xsd rename to smart-flow-example/src/main/resources/flow-example3.xml index 2d4bea8..d6b0332 100644 --- a/smart-flow-example/src/main/resources/flow-example3.xsd +++ b/smart-flow-example/src/main/resources/flow-example3.xml @@ -11,8 +11,4 @@ - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example4.xsd b/smart-flow-example/src/main/resources/flow-example4.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example4.xsd rename to smart-flow-example/src/main/resources/flow-example4.xml diff --git a/smart-flow-example/src/main/resources/flow-example5.xsd b/smart-flow-example/src/main/resources/flow-example5.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example5.xsd rename to smart-flow-example/src/main/resources/flow-example5.xml diff --git a/smart-flow-example/src/main/resources/flow-example6.xsd b/smart-flow-example/src/main/resources/flow-example6.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example6.xsd rename to smart-flow-example/src/main/resources/flow-example6.xml diff --git a/smart-flow-example/src/main/resources/flow-example7.xsd b/smart-flow-example/src/main/resources/flow-example7.xml similarity index 100% rename from smart-flow-example/src/main/resources/flow-example7.xsd rename to smart-flow-example/src/main/resources/flow-example7.xml diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java index 93404c6..56fc43d 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java @@ -37,7 +37,7 @@ public class EngineTest { engine.setName("test"); List> components = new ArrayList<>(); - pipeline.setComponents(components); + ExecutableAdapter component = new ExecutableAdapter<>(new AbstractExecutable() { @Override @@ -62,7 +62,7 @@ public class EngineTest { components.add(ifComponent); - + pipeline.setComponents(components); EngineContext context = new EngineContext<>(); context.setReq(1); @@ -223,7 +223,6 @@ public class EngineTest { .newBranch(1, new IntegerStep()).end(new DefaultStep()) .pipeline("subprocess") .next(new Step4()) - .next(new ErrorStep()) .end(); diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java index d88bcf2..bcee483 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java @@ -41,8 +41,6 @@ public class ParseTest { LOGGER.info("========================================================================="); EngineContext context1 = testEngine.execute(2); LOGGER.info("trace\n {}", context1.getTrace()); - - Thread.sleep(60000); } @Test diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java index 8afab3a..ec92296 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.exception.ExceptionHandler; import org.smartboot.flow.example.*; import org.smartboot.flow.core.builder.EngineBuilder; import org.smartboot.flow.core.builder.ExecutableBuilder; @@ -54,11 +55,13 @@ public class AsyncTest { context.setResult("hello"); FlowEngine engine = builder.pipeline(pipelineBuilder.build()).executor(Executors.newFixedThreadPool(10)).build(); + engine.setExceptionHandler(new ExceptionHandler() { + @Override + public void handle(EngineContext context, Throwable e) { + // do nothing + } + }); engine.execute(context); LOGGER.info("trace {}", context.getTrace()); - - // Generate plantuml file named engine-flow - PlantumlEngineVisitor plantumlEngineVisitor = new PlantumlEngineVisitor("engine-flow"); - plantumlEngineVisitor.visit(engine); } } diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java index aa2515f..cf554a3 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java @@ -28,7 +28,7 @@ public class DegradeCallbackTest { @Test public void testDegradeCallback() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/degrade-callback.xsd")); + parser.parse(this.getClass().getResourceAsStream("/degrade-callback.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java index 95ecaaf..e14e1b3 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java @@ -37,6 +37,7 @@ public class ManagerTest { @Test public void testModifyAttributes() { + DefaultEngineManager.getDefaultManager().detachAll(); PipelineBuilder builder = new PipelineBuilder<>("DefaultPipeline"); Pipeline build = builder.next(new IfCondition()).apply(Attributes.DEGRADABLE, true).then(new DefaultStep()) diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java index 14ce9ee..d97fdcd 100644 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.smartboot.flow.core.EngineContext; import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.exception.ExceptionHandler; +import org.smartboot.flow.core.exception.FlowException; import org.smartboot.flow.core.parser.DefaultParser; import org.smartboot.flow.example.EngineTest; import org.smartboot.flow.core.manager.DefaultEngineManager; @@ -34,22 +35,22 @@ public class DefaultParserTest { @Test public void testParseNull() { DefaultParser parser = new DefaultParser(); - Exception e = Assertions.assertThrows(IllegalArgumentException.class, () -> parser.parse((InputStream) null)); + Exception e = Assertions.assertThrows(FlowException.class, () -> parser.parse((InputStream) null)); LOGGER.error("", e); } @Test public void testParseWithUncorrectedRootElement() { DefaultParser parser = new DefaultParser(); - Exception e = Assertions.assertThrows(IllegalArgumentException.class, () -> - parser.parse(this.getClass().getResourceAsStream("/flow-example.xsd"))); + Exception e = Assertions.assertThrows(FlowException.class, () -> + parser.parse(this.getClass().getResourceAsStream("/flow-example.xml"))); LOGGER.error("", e); } @Test public void testParseSimple() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example3.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example3.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -59,7 +60,7 @@ public class DefaultParserTest { @Test public void testParseNestedPipelineInPipeline() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example4.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example4.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -70,7 +71,7 @@ public class DefaultParserTest { @Test public void testParseNestedElementsInPipeline() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example5.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example5.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -82,7 +83,7 @@ public class DefaultParserTest { public void testParseNestedElementsInPipeline2() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example6.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example6.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -94,7 +95,7 @@ public class DefaultParserTest { public void testParseNestedElementsInPipeline3() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example7.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example7.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -109,7 +110,7 @@ public class DefaultParserTest { public void testParseNestedElementsInPipeline4() { DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example-subprocess-non-degradable.xsd")); + parser.parse(this.getClass().getResourceAsStream("/flow-example-subprocess-non-degradable.xml")); LOGGER.info("engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); -- Gitee From f09eace79e95f0233b84b3da5c72a2e9a59ef9d6 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 17 Dec 2022 01:19:43 +0800 Subject: [PATCH 51/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20readme?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 458f52d..9295c8f 100644 --- a/README.md +++ b/README.md @@ -399,7 +399,7 @@ smart-flow提供默认的Parser解析`DefaultParser`,`DefaultParser`接受一 以下为使用示例: ```java DefaultParser parser = new DefaultParser(); -parser.parse(this.getClass().getResourceAsStream("/flow-example7.xsd")); +parser.parse(this.getClass().getResourceAsStream("/flow-example7.xml")); LOGGER.info("parsed engines {}", parser.getEngineNames()); FlowEngine testEngine = parser.getEngine("testEngine"); @@ -410,7 +410,7 @@ LOGGER.info("trace \n{}", execute.getTrace()); ### 完整xml示例 -参考文件 [flow-example7.xsd](https://gitee.com/smartboot/smart-flow/blob/master/smart-flow-example/src/main/resources/flow-example7.xsd) +参考文件 [flow-example7.xml](https://gitee.com/smartboot/smart-flow/blob/master/smart-flow-example/src/main/resources/flow-example7.xml) -- Gitee From 0ed19af8214c3c2c8418f592c639ad25c8c168f7 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 17 Dec 2022 01:25:51 +0800 Subject: [PATCH 52/54] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20readme?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9295c8f..ce42a35 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,12 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 ## 核心功能 - [X] 支持基于Java代码或者XML配置的线性流程编排 - [X] 支持IF、CHOOSE条件分支 -- [X] 支持组件异步执行以及组件执行依赖 +- [X] 支持组件异步 - [X] 支持组件降级以及降级回调 - [X] 支持IF、CHOOSE、PIPELINE嵌套子流程 -- [X] 支持组件失败回滚 -- [X] 支持查看调用路径 +- [X] 支持组件回滚 +- [X] 支持组件适配,以复用子流程 +- [X] 生成执行路径树 @@ -35,7 +36,7 @@ smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流 - [X] 支持Spring环境XML配置集成 - [X] 支持实时生成流程引擎结构图 - [X] 支持多种条件表达式(Groovy、OGNL、JavaScript等) -- [ ] springboot集成 +- [X] springboot集成 ## 管理功能 -- Gitee From ee53da67f4c0cebe2044012c4d1e6c4214ef75ca Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 17 Dec 2022 13:50:06 +0800 Subject: [PATCH 53/54] qinluo: - remove demo --- pom.xml | 40 ++- smart-flow-example/pom.xml | 66 ----- .../smartboot/flow/example/AdapterTest.java | 28 --- .../flow/example/AlwaysFalseCondition.java | 25 -- .../flow/example/AlwaysTrueCondition.java | 26 -- .../smartboot/flow/example/AsyncStep1.java | 19 -- .../smartboot/flow/example/AsyncStep2.java | 23 -- .../smartboot/flow/example/AsyncStep3.java | 23 -- .../smartboot/flow/example/AsyncStep4.java | 25 -- .../flow/example/ChooseCondition.java | 26 -- .../smartboot/flow/example/DefaultStep.java | 19 -- .../org/smartboot/flow/example/ElseStep.java | 19 -- .../org/smartboot/flow/example/ErrorStep.java | 19 -- .../flow/example/ExampleCallback.java | 24 -- .../flow/example/ExecuteTimesCondition.java | 40 --- .../smartboot/flow/example/IfCondition.java | 19 -- .../smartboot/flow/example/IfCondition2.java | 19 -- .../smartboot/flow/example/IfCondition3.java | 19 -- .../smartboot/flow/example/IntegerStep.java | 19 -- .../org/smartboot/flow/example/NewStep1.java | 16 -- .../org/smartboot/flow/example/NullStep.java | 23 -- .../flow/example/SelfCallbackComponent.java | 33 --- .../org/smartboot/flow/example/Step1.java | 17 -- .../org/smartboot/flow/example/Step2.java | 17 -- .../org/smartboot/flow/example/Step3.java | 19 -- .../org/smartboot/flow/example/Step4.java | 19 -- .../org/smartboot/flow/example/Step5.java | 19 -- .../org/smartboot/flow/example/Step6.java | 19 -- .../main/resources/META-INF/smart-flow-script | 1 - .../src/main/resources/bean.xml | 85 ------- .../src/main/resources/degrade-callback.xml | 40 --- ...low-example-parse-multiple-as-pipeline.xml | 25 -- ...flow-example-parse-single-as-component.xml | 24 -- ...flow-example-subprocess-non-degradable.xml | 41 --- .../src/main/resources/flow-example-while.xml | 30 --- .../src/main/resources/flow-example.xml | 8 - .../src/main/resources/flow-example3.xml | 14 -- .../src/main/resources/flow-example4.xml | 19 -- .../src/main/resources/flow-example5.xml | 28 --- .../src/main/resources/flow-example6.xml | 37 --- .../src/main/resources/flow-example7.xml | 47 ---- .../src/main/resources/log4j.properties | 59 ----- .../src/main/resources/log4j2.properties | 6 - .../main/resources/log4jdbc.log4j2.properties | 2 - .../src/main/resources/script-use.xsd | 51 ---- .../smartboot/flow/example/EngineTest.java | 238 ------------------ .../org/smartboot/flow/example/ParseTest.java | 55 ---- .../flow/example/async/AsyncTest.java | 67 ----- .../example/attributes/AttributeTest.java | 46 ---- .../example/builder/AdapterBuilderTest.java | 39 --- .../builder/IfComponentBuilderTest.java | 38 --- .../example/degrade/DegradeCallbackTest.java | 38 --- .../flow/example/manager/ManagerTest.java | 78 ------ .../example/parser/DefaultParserTest.java | 204 --------------- .../flow/example/script/ScriptTest.java | 38 --- 55 files changed, 39 insertions(+), 1999 deletions(-) delete mode 100644 smart-flow-example/pom.xml delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java delete mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java delete mode 100644 smart-flow-example/src/main/resources/META-INF/smart-flow-script delete mode 100644 smart-flow-example/src/main/resources/bean.xml delete mode 100644 smart-flow-example/src/main/resources/degrade-callback.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example-while.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example3.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example4.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example5.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example6.xml delete mode 100644 smart-flow-example/src/main/resources/flow-example7.xml delete mode 100644 smart-flow-example/src/main/resources/log4j.properties delete mode 100644 smart-flow-example/src/main/resources/log4j2.properties delete mode 100644 smart-flow-example/src/main/resources/log4jdbc.log4j2.properties delete mode 100644 smart-flow-example/src/main/resources/script-use.xsd delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java delete mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java diff --git a/pom.xml b/pom.xml index adbc25d..aa2b9b2 100644 --- a/pom.xml +++ b/pom.xml @@ -13,11 +13,49 @@ smart-flow-core smart-flow-spring-extension smart-flow-manager - smart-flow-example smart-flow-script-condition smart-flow-springboot-starter + + + yamikaze + qinluo + 1558642210@qq.com + + smart-flow作者 + + https://gitee.com/yamikaze + GMT+8 + smartboot + https://gitee.com/smartboot + + + yisshengyouni + yisshengyouni + yifengyoujian163@163.com + + smart-flow作者 + + https://gitee.com/yisshengyouni + GMT+8 + smartboot + https://gitee.com/smartboot + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml deleted file mode 100644 index e66efe2..0000000 --- a/smart-flow-example/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - flow-engine - org.smartboot - 1.0.2 - - 4.0.0 - - smart-flow-example - - - 8 - 8 - - - - - org.smartboot - smart-flow-manager - 1.0.2 - - - - org.smartboot - smart-flow-spring-extension - 1.0.2 - - - - org.junit.jupiter - junit-jupiter-api - 5.9.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.9.1 - test - - - - org.slf4j - slf4j-log4j12 - 2.0.3 - - - - - org.smartboot - smart-flow-script-ognl - 1.0.2 - - - - org.smartboot - smart-flow-script-groovy - 1.0.2 - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java deleted file mode 100644 index 8286a5a..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AdapterTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.smartboot.flow.example; - -import org.smartboot.flow.core.Adapter; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.common.Pair; - -/** - * @author huqiang - * @since 2022/12/7 19:54 - */ -public class AdapterTest implements Adapter { - - @Override - public Pair before(EngineContext context) { - return Pair.of("req", "response"); - } - - @Override - public void after(EngineContext origin, EngineContext newContext) { - System.out.println("origin req = " + origin.getReq() + ", origin response = " + origin.getResult()); - System.out.println("req=" + newContext.getReq() + ", response=" + newContext.getResult()); - } - - @Override - public String describe() { - return this.getClass().getName(); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java deleted file mode 100644 index 627116e..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysFalseCondition.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.script.ScriptCondition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -public class AlwaysFalseCondition extends ScriptCondition { - - @Override - public Object test(EngineContext context) { - System.out.println("always false invoked " + script); - return true; - } - - @Override - public String getType() { - return "alwaysfalse"; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java deleted file mode 100644 index 29b5449..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AlwaysTrueCondition.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.script.ScriptCondition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -@Service -public class AlwaysTrueCondition extends ScriptCondition { - - @Override - public Object test(EngineContext context) { - System.out.println("invoked " + script); - return true; - } - - @Override - public String getType() { - return "always"; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java deleted file mode 100644 index 0347c92..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep1.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class AsyncStep1 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java deleted file mode 100644 index 8a94014..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep2.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class AsyncStep2 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - try { - Thread.sleep(100); - } catch (Exception e) { - - } - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java deleted file mode 100644 index 2c20351..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep3.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class AsyncStep3 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - try { - Thread.sleep(200); - } catch (Exception e) { - - } - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java deleted file mode 100644 index ca36ea9..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/AsyncStep4.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.exception.FlowException; -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class AsyncStep4 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - try { - Thread.sleep(500); - } catch (Exception e) { - - } - throw new FlowException("async4 failed."); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java deleted file mode 100644 index 9bab376..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/ChooseCondition.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.Condition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 16:45:21 - * @since 1.0.0 - */ -@Service -public class ChooseCondition extends Condition { - - @Override - public Object test(Integer integer, String s) { - if (integer == null) { - return "null"; - } else if (integer == 1) { - return 1; - } else if (integer == 2) { - return 2; - } - return null; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java deleted file mode 100644 index d021efc..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/DefaultStep.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 16:44:21 - * @since 1.0.0 - */ -@Service -public class DefaultStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java deleted file mode 100644 index b334791..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/ElseStep.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 16:44:21 - * @since 1.0.0 - */ -@Service -public class ElseStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java deleted file mode 100644 index 79d0e29..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/ErrorStep.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class ErrorStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("error executed ======="); - throw new IllegalArgumentException("Error"); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java deleted file mode 100644 index fa35d91..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExampleCallback.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.smartboot.flow.example; - -import org.smartboot.flow.core.DegradeCallback; -import org.smartboot.flow.core.EngineContext; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-28 21:20:11 - * @since 1.0.0 - */ -@Service -public class ExampleCallback implements DegradeCallback { - - @Override - public void doWithDegrade(EngineContext context, Throwable e) { - System.out.println("degrade callback called."); - } - - @Override - public String describe() { - return "example-callback"; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java deleted file mode 100644 index 31e49b9..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/ExecuteTimesCondition.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.smartboot.flow.example; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.Condition; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.Key; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -@Service -public class ExecuteTimesCondition extends Condition { - - private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteTimesCondition.class); - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } - - @Override - public Object test(EngineContext context) { - Integer cnt = context.getExt(Key.of(this)); - if (cnt == null) { - cnt = 3; - } - - cnt--; - context.putExt(Key.of(this), cnt); - - LOGGER.info("value {}", cnt); - - return cnt > 0; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java deleted file mode 100644 index b1f1e44..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.Condition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -@Service -public class IfCondition extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java deleted file mode 100644 index 8e1c17c..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition2.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.Condition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -@Service -public class IfCondition2 extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java deleted file mode 100644 index eb9ac14..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/IfCondition3.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.Condition; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:45:21 - * @since 1.0.0 - */ -@Service -public class IfCondition3 extends Condition { - - @Override - public Object test(Integer integer, String s) { - return integer != null && integer == 1; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java deleted file mode 100644 index ec2be0d..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/IntegerStep.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class IntegerStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println(getClass()); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java deleted file mode 100644 index a62f1fe..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/NewStep1.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.smartboot.flow.example; - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author huqiang - * @since 2022/12/7 19:57 - */ -public class NewStep1 extends AbstractExecutable { - - @Override - public void execute(String s, String s2) { - System.out.println("new step" + " req=" + s + ", response=" + s2); - - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java deleted file mode 100644 index c1e43b3..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/NullStep.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class NullStep extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - if (integer == null) { - throw new RuntimeException("null value"); - } - - System.out.println(getClass()); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java deleted file mode 100644 index 0ccea2f..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/SelfCallbackComponent.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.smartboot.flow.example; - -import org.smartboot.flow.core.DegradeCallback; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.exception.FlowException; -import org.smartboot.flow.spring.extension.NamedAbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-29 21:20:11 - * @since 1.0.0 - */ -@Service -public class SelfCallbackComponent extends NamedAbstractExecutable implements DegradeCallback { - - @Override - public void execute(Integer integer, String s) { - System.out.println("SelfCallbackComponent executed"); - throw new FlowException("aaaa"); - } - - @Override - public void doWithDegrade(EngineContext context, Throwable e) { - System.out.println("SelfCallbackComponent-degrade callback called."); - System.out.println("SelfCallbackComponent-degrade e = " + e.getMessage()); - } - - @Override - public String describe() { - return "example-callback"; - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java deleted file mode 100644 index 92b06f9..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step1.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step1 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step1 == " + integer); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java deleted file mode 100644 index 3538277..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step2.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -public class Step2 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step2 == " + integer); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java deleted file mode 100644 index 107320d..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step3.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class Step3 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step3 == " + integer); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java deleted file mode 100644 index 20e90a6..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step4.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class Step4 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step4 == " + integer); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java deleted file mode 100644 index fd4b890..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step5.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class Step5 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step5 == " + integer); - } -} diff --git a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java deleted file mode 100644 index 9a4c7fa..0000000 --- a/smart-flow-example/src/main/java/org/smartboot/flow/example/Step6.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.smartboot.flow.example; - - -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.springframework.stereotype.Service; - -/** - * @author qinluo - * @date 2022-11-11 21:44:21 - * @since 1.0.0 - */ -@Service -public class Step6 extends AbstractExecutable { - - @Override - public void execute(Integer integer, String s) { - System.out.println("step5 == " + integer); - } -} diff --git a/smart-flow-example/src/main/resources/META-INF/smart-flow-script b/smart-flow-example/src/main/resources/META-INF/smart-flow-script deleted file mode 100644 index c11e6bc..0000000 --- a/smart-flow-example/src/main/resources/META-INF/smart-flow-script +++ /dev/null @@ -1 +0,0 @@ -alwaysfalse=org.smartboot.flow.example.AlwaysFalseCondition \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/bean.xml b/smart-flow-example/src/main/resources/bean.xml deleted file mode 100644 index aeb26f1..0000000 --- a/smart-flow-example/src/main/resources/bean.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var local = 2; - local == request; - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/degrade-callback.xml b/smart-flow-example/src/main/resources/degrade-callback.xml deleted file mode 100644 index afbdb5a..0000000 --- a/smart-flow-example/src/main/resources/degrade-callback.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml b/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml deleted file mode 100644 index b62f8b1..0000000 --- a/smart-flow-example/src/main/resources/flow-example-parse-multiple-as-pipeline.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml b/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml deleted file mode 100644 index 3c933c2..0000000 --- a/smart-flow-example/src/main/resources/flow-example-parse-single-as-component.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml b/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml deleted file mode 100644 index e58a7d7..0000000 --- a/smart-flow-example/src/main/resources/flow-example-subprocess-non-degradable.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example-while.xml b/smart-flow-example/src/main/resources/flow-example-while.xml deleted file mode 100644 index 8a99e71..0000000 --- a/smart-flow-example/src/main/resources/flow-example-while.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example.xml b/smart-flow-example/src/main/resources/flow-example.xml deleted file mode 100644 index 7231d98..0000000 --- a/smart-flow-example/src/main/resources/flow-example.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example3.xml b/smart-flow-example/src/main/resources/flow-example3.xml deleted file mode 100644 index d6b0332..0000000 --- a/smart-flow-example/src/main/resources/flow-example3.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example4.xml b/smart-flow-example/src/main/resources/flow-example4.xml deleted file mode 100644 index 5501fb7..0000000 --- a/smart-flow-example/src/main/resources/flow-example4.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example5.xml b/smart-flow-example/src/main/resources/flow-example5.xml deleted file mode 100644 index ae35fcd..0000000 --- a/smart-flow-example/src/main/resources/flow-example5.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example6.xml b/smart-flow-example/src/main/resources/flow-example6.xml deleted file mode 100644 index b647239..0000000 --- a/smart-flow-example/src/main/resources/flow-example6.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/flow-example7.xml b/smart-flow-example/src/main/resources/flow-example7.xml deleted file mode 100644 index 978e1c3..0000000 --- a/smart-flow-example/src/main/resources/flow-example7.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/log4j.properties b/smart-flow-example/src/main/resources/log4j.properties deleted file mode 100644 index b9a23dd..0000000 --- a/smart-flow-example/src/main/resources/log4j.properties +++ /dev/null @@ -1,59 +0,0 @@ -### direct log messages to stdout ### -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.debug=org.apache.log4j.ConsoleAppender -log4j.appender.debug.layout=org.apache.log4j.PatternLayout -log4j.appender.debug.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.warn=org.apache.log4j.ConsoleAppender -log4j.appender.warn.layout=org.apache.log4j.PatternLayout -log4j.appender.warn.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.error=org.apache.log4j.ConsoleAppender -log4j.appender.error.layout=org.apache.log4j.PatternLayout -log4j.appender.error.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -### direct messages to file hibernate.log ### -#log4j.appender.file=org.apache.log4j.FileAppender -#log4j.appender.file.File=hibernate.log -#log4j.appender.file.layout=org.apache.log4j.PatternLayout -#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### set log levels - for more verbose logging change 'info' to 'debug' ### - -log4j.rootLogger=debug,stdout - -#log4j.logger.org.hibernate=info -#log4j.logger.org.hibernate=debug - -### log HQL query parser activity -#log4j.logger.org.hibernate.hql.ast.AST=debug - -### log just the SQL -#log4j.logger.org.hibernate.SQL=debug - -### log JDBC bind parameters ### -#log4j.logger.org.hibernate.type=info -#log4j.logger.org.hibernate.type=debug - -### log schema export/update ### -log4j.logger.org.hibernate.tool.hbm2ddl=debug - -### log HQL parse trees -#log4j.logger.org.hibernate.hql=debug - -### log cache activity ### -#log4j.logger.org.hibernate.cache=debug - -### log transaction activity -#log4j.logger.org.hibernate.transaction=debug - -### log JDBC resource acquisition -#log4j.logger.org.hibernate.jdbc=debug - -### enable the following line if you want to track down connection ### -### leakages when using DriverManagerConnectionProvider ### -#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace diff --git a/smart-flow-example/src/main/resources/log4j2.properties b/smart-flow-example/src/main/resources/log4j2.properties deleted file mode 100644 index e05109d..0000000 --- a/smart-flow-example/src/main/resources/log4j2.properties +++ /dev/null @@ -1,6 +0,0 @@ -appender.console.type = Console -appender.console.name = console -appender.console.layout.type = PatternLayout - -rootLogger.level = debug -rootLogger.appenderRef.console.ref = console \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/log4jdbc.log4j2.properties b/smart-flow-example/src/main/resources/log4jdbc.log4j2.properties deleted file mode 100644 index 76f2440..0000000 --- a/smart-flow-example/src/main/resources/log4jdbc.log4j2.properties +++ /dev/null @@ -1,2 +0,0 @@ -#log4jdbc-log4j2默认只支持log4j2,如果想要支持slf4j,则需要增加如下配置: -log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator \ No newline at end of file diff --git a/smart-flow-example/src/main/resources/script-use.xsd b/smart-flow-example/src/main/resources/script-use.xsd deleted file mode 100644 index a690404..0000000 --- a/smart-flow-example/src/main/resources/script-use.xsd +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java deleted file mode 100644 index 56fc43d..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/EngineTest.java +++ /dev/null @@ -1,238 +0,0 @@ -package org.smartboot.flow.example; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.Condition; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.builder.EngineBuilder; -import org.smartboot.flow.core.builder.ExecutableBuilder; -import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.attribute.Attributes; -import org.smartboot.flow.core.component.Component; -import org.smartboot.flow.core.component.IfComponent; -import org.smartboot.flow.core.component.PipelineComponent; -import org.smartboot.flow.core.executable.AbstractExecutable; -import org.smartboot.flow.core.executable.ExecutableAdapter; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author qinluo - * @date 2022-11-12 18:40:45 - * @since 1.0.0 - */ -public class EngineTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); - - @Test - public void testSimple() { - FlowEngine engine = new FlowEngine<>(); - Pipeline pipeline = new Pipeline<>(); - engine.setPipeline(pipeline); - engine.setName("test"); - - List> components = new ArrayList<>(); - - - ExecutableAdapter component = new ExecutableAdapter<>(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println(o); - System.out.println(o2); - } - }); - components.add(component); - - IfComponent ifComponent = new IfComponent<>(new Condition() { - @Override - public Object test(Integer integer, String s) { - return true; - } - }, new ExecutableAdapter<>(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println("if cocndition"); - } - })); - - components.add(ifComponent); - - pipeline.setComponents(components); - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - engine.execute(context); - } - - @Test - public void testSimpleBuilder() { - EngineBuilder builder = new EngineBuilder<>("defaultEngine"); - FlowEngine engine = builder.pipeline(new PipelineBuilder("DefaultPipeline").next(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println(o); - System.out.println(o2); - } - }).next(new Condition() { - @Override - public Object test(Integer integer, String s) { - return false; - } - }).then(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println("if cocndition"); - } - }, new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println("otherwise cocndition"); - } - }).build()).build(); - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - engine.execute(context); - } - - @Test - public void testSimpleBuilder02() { - EngineBuilder builder = new EngineBuilder<>("defaultEngine"); - FlowEngine engine = builder.pipeline(new PipelineBuilder("DefaultPipeline").next(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println(o); - System.out.println(o2); - } - }).next(new Condition() { - @Override - public Object test(Integer integer, String s) { - return false; - } - }).then(new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println("if cocndition"); - } - }, new AbstractExecutable() { - @Override - public void execute(Integer o, String o2) { - System.out.println("otherwise cocndition"); - } - }).choose(new Condition() { - @Override - public Object test(Integer integer, String s) { - if (integer == null) { - return "null"; - } else if (integer == 1) { - return 1; - } else if (integer == 2) { - return 2; - } - return null; - } - }).newBranch("null", new AbstractExecutable() { - @Override - public void execute(Integer integer, String s) { - System.out.println("enter branch null"); - } - }).newBranch(1, new AbstractExecutable() { - @Override - public void execute(Integer integer, String s) { - System.out.println("enter branch 1"); - } - }).newBranch(2, new AbstractExecutable() { - @Override - public void execute(Integer integer, String s) { - System.out.println("enter branch 2"); - } - }).end(new AbstractExecutable() { - @Override - public void execute(Integer integer, String s) { - System.out.println("enter default branch"); - } - }) - - .build()).build(); - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - engine.execute(context); - } - - - @Test - public void testAdapterPipeline(){ - EngineBuilder builder = new EngineBuilder<>("defaultEngine"); - - - - - PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); - - PipelineBuilder adapterPipelineBuilder = new PipelineBuilder<>("adapter process"); - adapterPipelineBuilder.next(new NewStep1()).next(new NewStep1()); - - ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); - execBuilder.apply(Attributes.ROLLBACK, true); - Component nested = execBuilder.newAdapter(new Step5()); - - - pipelineBuilder.next(new Step1()).next(new Step2()) - .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) - .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - .adapter(new AdapterTest(), new PipelineComponent<>(adapterPipelineBuilder.build())) - .next(new Step3()); - - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - builder.pipeline(pipelineBuilder.build()).build().execute(context); - - LOGGER.info("trace {}", context.getTrace()); - } - - @Test - public void testBuildPipeline() { - EngineBuilder builder = new EngineBuilder<>("defaultEngine"); - - PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); - - ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); - execBuilder.apply(Attributes.ROLLBACK, true); - Component nested = execBuilder.newAdapter(new Step5()); - - pipelineBuilder.next(new Step1()).next(new Step2()) - .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) - .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - .choose(new ChooseCondition()) - .newBranch("null", new NullStep()) - .newBranch(1, new IntegerStep()).end(new DefaultStep()) - .pipeline("subprocess") - .next(new Step4()) - .end(); - - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - builder.pipeline(pipelineBuilder.build()).build().execute(context); - - LOGGER.info("trace {}", context.getTrace()); - - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java deleted file mode 100644 index bcee483..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.smartboot.flow.example; - - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.script.ScriptDetector; -import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.net.URL; -import java.util.Enumeration; - -/** - * @author yamikaze - * @version 1.0.0 - * @date 2018/3/20 12:52 - */ -public class ParseTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(ParseTest.class); - - @Test - public void testXml() throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:bean.xml"); - Object step = context.getBean("step3"); - LOGGER.info("step is " + step.getClass().getName()); - - FlowEngine testEngine = (FlowEngine)context.getBean("testEngine", FlowEngine.class); - - EngineContext executeContext = testEngine.execute(1); - LOGGER.info("trace\n {}", executeContext.getTrace()); - - LOGGER.info("========================================================================="); - executeContext = testEngine.execute((Integer) 3); - LOGGER.info("trace\n {}", executeContext.getTrace()); - - - LOGGER.info("========================================================================="); - EngineContext context1 = testEngine.execute(2); - LOGGER.info("trace\n {}", context1.getTrace()); - } - - @Test - public void testGetExtension() throws Exception { - LOGGER.warn("{}", ScriptDetector.get().getJavaType("javaScript")); - - Enumeration resources = this.getClass().getClassLoader().getResources("META-INF/smart-flow-script"); - LOGGER.info("size {}", resources); - - LOGGER.info("class [}", Class.forName("org.smartboot.flow.condition.extension.groovy.GroovyScriptCondition")); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java deleted file mode 100644 index ec92296..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/async/AsyncTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.smartboot.flow.example.async; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.exception.ExceptionHandler; -import org.smartboot.flow.example.*; -import org.smartboot.flow.core.builder.EngineBuilder; -import org.smartboot.flow.core.builder.ExecutableBuilder; -import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.attribute.Attributes; -import org.smartboot.flow.core.component.Component; -import org.smartboot.flow.core.component.IfComponent; -import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; - -import java.util.concurrent.Executors; - -/** - * @author qinluo - * @date 2022-11-14 22:34:14 - * @since 1.0.0 - */ -public class AsyncTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(AsyncTest.class); - - @Test - public void testAsync() { - EngineBuilder builder = new EngineBuilder<>("defaultEngine"); - - PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process"); - - ExecutableBuilder execBuilder = ExecutableBuilder.newBuilder(); - execBuilder.apply(Attributes.ROLLBACK, true); - Component nested = execBuilder.newAdapter(new Step5()); - - pipelineBuilder.next(new Step1()).next(new Step2()) - .next(new IfCondition()).apply(Attributes.ROLLBACK, true).then(new Step3(), new ElseStep()) - .next(new IfCondition2()).then(new IfComponent<>(new IfCondition3(), nested)) - - .next(execBuilder.apply(Attributes.ASYNC, true).apply(Attributes.NAME, "asyncStep1").apply(Attributes.TIMEOUT, 1000).newAdapter(new AsyncStep1())) - .next(execBuilder.apply(Attributes.ASYNC, true).apply(Attributes.NAME, "asyncStep2").apply(Attributes.TIMEOUT, 1000).newAdapter(new AsyncStep2())) - .next(execBuilder.apply(Attributes.ASYNC, false).apply(Attributes.DEPENDS_ON, "asyncStep1,asyncStep2").newAdapter(new AsyncStep3())) - - .choose(new ChooseCondition()) - .newBranch("null", new NullStep()) - .newBranch(1, new IntegerStep()).end(new DefaultStep()) - .pipeline("subprocess").next(new Step4()).next(execBuilder.apply(Attributes.ASYNC, true).apply(Attributes.TIMEOUT, 1000).newAdapter(new Step6())).next(new ErrorStep()).end(); - - - EngineContext context = new EngineContext<>(); - context.setReq(1); - context.setResult("hello"); - - FlowEngine engine = builder.pipeline(pipelineBuilder.build()).executor(Executors.newFixedThreadPool(10)).build(); - engine.setExceptionHandler(new ExceptionHandler() { - @Override - public void handle(EngineContext context, Throwable e) { - // do nothing - } - }); - engine.execute(context); - LOGGER.info("trace {}", context.getTrace()); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java deleted file mode 100644 index 0a5277c..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/attributes/AttributeTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.smartboot.flow.example.attributes; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.example.*; -import org.smartboot.flow.core.builder.EngineBuilder; -import org.smartboot.flow.core.builder.ExecutableBuilder; -import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.attribute.Attributes; -import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; - -/** - * @author qinluo - * @date 2022/11/18 22:23 - * @since 1.0.0 - */ -public class AttributeTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); - - - @Test - public void testEnabled() { - - PipelineBuilder builder = new PipelineBuilder<>("DefaultPipeline"); - Pipeline build = builder.next(new IfCondition()).apply(Attributes.DEGRADABLE, true).then(new DefaultStep()) - .choose(new ChooseCondition()).newBranch(1, new IntegerStep()) - .apply(Attributes.DEGRADABLE, true).end() - .next(ExecutableBuilder.newBuilder().apply(Attributes.ENABLED, false).newAdapter(new Step5())) - .build(); - - EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine"); - FlowEngine engine = engineBuilder.pipeline(build).build(); - - EngineContext context = engine.execute(1); - LOGGER.info("trace {}", context.getTrace()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-disabled"); - visitor.visit(engine); - - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java deleted file mode 100644 index a22c1c1..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/AdapterBuilderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.smartboot.flow.example.builder; - -import org.junit.jupiter.api.Test; -import org.smartboot.flow.core.Adapter; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.attribute.Attributes; -import org.smartboot.flow.core.builder.AdapterBuilder; -import org.smartboot.flow.core.common.Pair; - -/** - * @author qinluo - * @date 2022-12-08 19:06:06 - * @since 1.0.0 - */ -public class AdapterBuilderTest { - - @Test - public void testAdapterBuilder() { - AdapterBuilder builder - = new AdapterBuilder<>(new Adapter() { - @Override - public Pair before(EngineContext context) { - return null; - } - - @Override - public void after(EngineContext origin, EngineContext newContext) { - - } - - @Override - public String describe() { - return null; - } - }, null); - - builder.apply(Attributes.ASYNC, true); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java deleted file mode 100644 index 01fac1a..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/builder/IfComponentBuilderTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.smartboot.flow.example.builder; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.builder.EngineBuilder; -import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.attribute.Attributes; -import org.smartboot.flow.example.*; -import org.smartboot.flow.example.attributes.AttributeTest; - -/** - * @author yamikaze - * @date 2022/11/13 - */ -public class IfComponentBuilderTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); - - @Test - public void testBuild() { - - PipelineBuilder builder = new PipelineBuilder<>("DefaultPipeline"); - Pipeline build = builder.next(new IfCondition()).apply(Attributes.DEGRADABLE, true).then(new DefaultStep()) - .choose(new ChooseCondition()).newBranch(1, new IntegerStep()) - .apply(Attributes.DEGRADABLE, true).end().build(); - - EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine"); - FlowEngine engine = engineBuilder.pipeline(build).build(); - - EngineContext context = engine.execute(1); - LOGGER.info("trace {}", context.getTrace()); - - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java deleted file mode 100644 index cf554a3..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/degrade/DegradeCallbackTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.smartboot.flow.example.degrade; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.manager.DefaultEngineManager; -import org.smartboot.flow.core.parser.DefaultParser; -import org.smartboot.flow.example.EngineTest; - -/** - * @author qinluo - * @date 2022-11-15 23:42:32 - * @since 1.0.0 - */ -public class DegradeCallbackTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); - - - @BeforeEach - public void setUp() { - DefaultEngineManager.getDefaultManager().detachAll(); - } - - @Test - public void testDegradeCallback() { - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/degrade-callback.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute((Integer)null); - LOGGER.info("trace \n{}", execute.getTrace()); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java deleted file mode 100644 index e14e1b3..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/manager/ManagerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.smartboot.flow.example.manager; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.Pipeline; -import org.smartboot.flow.core.manager.ComponentModel; -import org.smartboot.flow.core.manager.DefaultEngineManager; -import org.smartboot.flow.core.manager.EngineManager; -import org.smartboot.flow.core.manager.EngineModel; -import org.smartboot.flow.example.*; -import org.smartboot.flow.example.attributes.AttributeTest; -import org.smartboot.flow.core.builder.EngineBuilder; -import org.smartboot.flow.core.builder.ExecutableBuilder; -import org.smartboot.flow.core.builder.PipelineBuilder; -import org.smartboot.flow.core.attribute.AttributeHolder; -import org.smartboot.flow.core.attribute.Attributes; - -import java.util.Map; - -/** - * @author qinluo - * @date 2022/11/18 22:23 - * @since 1.0.0 - */ -public class ManagerTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(AttributeTest.class); - - @BeforeEach - public void setUp() { - DefaultEngineManager.getDefaultManager().detachAll(); - } - - @Test - public void testModifyAttributes() { - DefaultEngineManager.getDefaultManager().detachAll(); - - PipelineBuilder builder = new PipelineBuilder<>("DefaultPipeline"); - Pipeline build = builder.next(new IfCondition()).apply(Attributes.DEGRADABLE, true).then(new DefaultStep()) - .choose(new ChooseCondition()).newBranch(1, new IntegerStep()) - .apply(Attributes.DEGRADABLE, true).end() - .next(ExecutableBuilder.newBuilder().apply(Attributes.NAME, "step5").newAdapter(new Step5())) - .next(new Step6()).next(new Step1()).next(new Step2()).next(new Step3()) - .pipeline("subprocess##2").next(new AsyncStep1()).next(new AsyncStep2()).next(new AsyncStep3()).end() - .build(); - - EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine"); - FlowEngine engine = engineBuilder.pipeline(build).build(); - - EngineContext context = engine.execute(1); - LOGGER.info("trace {}", context.getTrace()); - - LOGGER.info("=================================================================================="); - - EngineManager defaultManager = DefaultEngineManager.getDefaultManager(); - EngineModel engineModel = defaultManager.getEngineModel("defaultEngine"); - Map components = engineModel.getComponents(); - String identifier = null; - for (Map.Entry modelEntry : components.entrySet()) { - if (modelEntry.getValue().getDescribe().contains("pipeline@subprocess##2")) { - identifier = modelEntry.getKey(); - } - - LOGGER.info("identifier {} name {} describe {}", modelEntry.getKey(), modelEntry.getValue().getName(), modelEntry.getValue().getDescribe()); - } - - AttributeHolder attributeHolder = new AttributeHolder(Attributes.ENABLED, false); - defaultManager.changeAttributes(identifier, attributeHolder); - - - context = engine.execute(1); - LOGGER.info("trace {}", context.getTrace()); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java deleted file mode 100644 index d97fdcd..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/parser/DefaultParserTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.smartboot.flow.example.parser; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.exception.ExceptionHandler; -import org.smartboot.flow.core.exception.FlowException; -import org.smartboot.flow.core.parser.DefaultParser; -import org.smartboot.flow.example.EngineTest; -import org.smartboot.flow.core.manager.DefaultEngineManager; -import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor; - -import java.io.InputStream; -import java.util.concurrent.Executors; - -/** - * @author qinluo - * @date 2022-11-15 23:42:32 - * @since 1.0.0 - */ -public class DefaultParserTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); - - - @BeforeEach - public void setUp() { - DefaultEngineManager.getDefaultManager().detachAll(); - } - - @Test - public void testParseNull() { - DefaultParser parser = new DefaultParser(); - Exception e = Assertions.assertThrows(FlowException.class, () -> parser.parse((InputStream) null)); - LOGGER.error("", e); - } - - @Test - public void testParseWithUncorrectedRootElement() { - DefaultParser parser = new DefaultParser(); - Exception e = Assertions.assertThrows(FlowException.class, () -> - parser.parse(this.getClass().getResourceAsStream("/flow-example.xml"))); - LOGGER.error("", e); - } - - @Test - public void testParseSimple() { - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example3.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - testEngine.execute(1); - } - - @Test - public void testParseNestedPipelineInPipeline() { - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example4.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - } - - @Test - public void testParseNestedElementsInPipeline() { - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example5.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - } - - @Test - public void testParseNestedElementsInPipeline2() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example6.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - } - - @Test - public void testParseNestedElementsInPipeline3() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example7.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); - visitor.visit(testEngine); - } - - @Test - public void testParseNestedElementsInPipeline4() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example-subprocess-non-degradable.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - testEngine.setExecutor(Executors.newSingleThreadExecutor()); - testEngine.setExceptionHandler(new ExceptionHandler() { - @Override - public void handle(EngineContext context, Throwable e) { - System.out.println("handle " + e.getMessage()); - } - }); - - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - - LOGGER.error("fatal ", execute.getFatal()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); - visitor.visit(testEngine); - } - - @Test - public void testParseMultipleAsPipeline() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example-parse-multiple-as-pipeline.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - testEngine.setExecutor(Executors.newSingleThreadExecutor()); - testEngine.setExceptionHandler(new ExceptionHandler() { - @Override - public void handle(EngineContext context, Throwable e) { - System.out.println("handle " + e.getMessage()); - } - }); - - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - - LOGGER.error("fatal ", execute.getFatal()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); - visitor.visit(testEngine); - } - - @Test - public void testParseSingleAsComponent() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example-parse-single-as-component.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - testEngine.setExecutor(Executors.newSingleThreadExecutor()); - testEngine.setExceptionHandler(new ExceptionHandler() { - @Override - public void handle(EngineContext context, Throwable e) { - System.out.println("handle " + e.getMessage()); - } - }); - - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); - visitor.visit(testEngine); - } - - @Test - public void testWhile() { - - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/flow-example-while.xml")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - testEngine.setExecutor(Executors.newSingleThreadExecutor()); - testEngine.setExceptionHandler(new ExceptionHandler() { - @Override - public void handle(EngineContext context, Throwable e) { - e.printStackTrace(); - } - }); - - EngineContext execute = testEngine.execute(1); - LOGGER.info("trace \n{}", execute.getTrace()); - - PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow2"); - visitor.visit(testEngine); - } -} diff --git a/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java b/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java deleted file mode 100644 index 0f57863..0000000 --- a/smart-flow-example/src/test/java/org/smartboot/flow/example/script/ScriptTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.smartboot.flow.example.script; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.FlowEngine; -import org.smartboot.flow.core.manager.DefaultEngineManager; -import org.smartboot.flow.core.parser.DefaultParser; -import org.smartboot.flow.example.EngineTest; - -/** - * @author qinluo - * @date 2022-11-15 23:42:32 - * @since 1.0.0 - */ -public class ScriptTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(EngineTest.class); - - - @BeforeEach - public void setUp() { - DefaultEngineManager.getDefaultManager().detachAll(); - } - - @Test - public void testScript() { - DefaultParser parser = new DefaultParser(); - parser.parse(this.getClass().getResourceAsStream("/script-use.xsd")); - LOGGER.info("engines {}", parser.getEngineNames()); - - FlowEngine testEngine = parser.getEngine("testEngine"); - EngineContext execute = testEngine.execute((Integer)null); - LOGGER.info("trace \n{}", execute.getTrace()); - } -} -- Gitee From e75b957d4bbbbe28693f9241ac5d7b5b7bfd522a Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 17 Dec 2022 13:56:03 +0800 Subject: [PATCH 54/54] qinluo: - upgrade version --- README.md | 10 +++++----- pom.xml | 2 +- smart-flow-core/pom.xml | 2 +- smart-flow-manager/pom.xml | 4 ++-- smart-flow-script-condition/pom.xml | 4 ++-- .../smart-flow-script-groovy/pom.xml | 2 +- .../smart-flow-script-ognl/pom.xml | 2 +- .../smart-flow-script-qlexpress/pom.xml | 2 +- smart-flow-spring-extension/pom.xml | 4 ++-- smart-flow-springboot-starter/pom.xml | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ce42a35..df53ace 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ cd smart-flow mvn -DskipTests=true clean install ``` 安装完毕后在项目中进行引入 -`lastest.version` = 1.0.2 +`lastest.version` = 1.0.3 ```XML org.smartboot @@ -596,7 +596,7 @@ smart-flow中默认提供了常用条件表达式的实现,您只需要在scri org.smartboot smart-flow-script-ognl - 1.0.2 + 1.0.3 ``` @@ -608,7 +608,7 @@ groovy与javascript使用相同的依赖 org.smartboot smart-flow-script-groovy - 1.0.2 + 1.0.3 ``` @@ -618,7 +618,7 @@ groovy与javascript使用相同的依赖 org.smartboot smart-flow-script-qlexpress - 1.0.2 + 1.0.3 ``` 为了方便使用,当使用短语时,您可以不必区分大小写,例如Groovy与GROOVY、groovy都是等价的。 @@ -649,7 +649,7 @@ javascript=org.smartboot.flow.condition.extension.groovy.JavaScriptCondition org.smartboot smart-flow-spring-extension - 1.0.2 + 1.0.3 ``` diff --git a/pom.xml b/pom.xml index aa2b9b2..9775e19 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartboot flow-engine - 1.0.2 + 1.0.3 4.0.0 pom diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index a2a2b49..757c406 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -5,7 +5,7 @@ org.smartboot flow-engine - 1.0.2 + 1.0.3 4.0.0 diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 5b06e3b..0cc0375 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.2 + 1.0.3 4.0.0 @@ -20,7 +20,7 @@ org.smartboot smart-flow-core - 1.0.2 + 1.0.3 diff --git a/smart-flow-script-condition/pom.xml b/smart-flow-script-condition/pom.xml index 0514d75..985430c 100644 --- a/smart-flow-script-condition/pom.xml +++ b/smart-flow-script-condition/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.2 + 1.0.3 4.0.0 pom @@ -27,7 +27,7 @@ org.smartboot smart-flow-core - 1.0.2 + 1.0.3 diff --git a/smart-flow-script-condition/smart-flow-script-groovy/pom.xml b/smart-flow-script-condition/smart-flow-script-groovy/pom.xml index 2318916..b572cb3 100644 --- a/smart-flow-script-condition/smart-flow-script-groovy/pom.xml +++ b/smart-flow-script-condition/smart-flow-script-groovy/pom.xml @@ -5,7 +5,7 @@ smart-flow-script-condition org.smartboot - 1.0.2 + 1.0.3 4.0.0 diff --git a/smart-flow-script-condition/smart-flow-script-ognl/pom.xml b/smart-flow-script-condition/smart-flow-script-ognl/pom.xml index dcba2a1..f1e2c68 100644 --- a/smart-flow-script-condition/smart-flow-script-ognl/pom.xml +++ b/smart-flow-script-condition/smart-flow-script-ognl/pom.xml @@ -5,7 +5,7 @@ smart-flow-script-condition org.smartboot - 1.0.2 + 1.0.3 4.0.0 diff --git a/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml b/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml index 6417326..c4d6f1a 100644 --- a/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml +++ b/smart-flow-script-condition/smart-flow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ smart-flow-script-condition org.smartboot - 1.0.2 + 1.0.3 4.0.0 diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml index 806b0d4..470e989 100644 --- a/smart-flow-spring-extension/pom.xml +++ b/smart-flow-spring-extension/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.2 + 1.0.3 4.0.0 @@ -21,7 +21,7 @@ org.smartboot smart-flow-core - 1.0.2 + 1.0.3 diff --git a/smart-flow-springboot-starter/pom.xml b/smart-flow-springboot-starter/pom.xml index 8d0f033..6ad21a8 100644 --- a/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-springboot-starter/pom.xml @@ -5,7 +5,7 @@ flow-engine org.smartboot - 1.0.2 + 1.0.3 4.0.0 @@ -25,12 +25,12 @@ org.smartboot smart-flow-spring-extension - 1.0.2 + 1.0.3 org.smartboot smart-flow-manager - 1.0.2 + 1.0.3 -- Gitee