From e868ca7d0c3a13ae03a2cb55ff02b13e60325137 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Sun, 20 Nov 2022 23:09:37 +0800
Subject: [PATCH 01/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=201=E3=80=81?=
=?UTF-8?q?=E4=BC=98=E5=8C=96xml=E8=A7=A3=E6=9E=90=EF=BC=8C=E6=94=AF?=
=?UTF-8?q?=E6=8C=81=E5=A4=9A=E6=96=87=E4=BB=B6=E8=A7=A3=E6=9E=90=EF=BC=8C?=
=?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=20=20=20?=
=?UTF-8?q?=20=20=20-=202=E3=80=81=E4=BC=98=E5=8C=96=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE=E6=94=B9identifier?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=B9=E5=BC=8F=20=20=20=20=20=20-=203?=
=?UTF-8?q?=E3=80=81=E4=BC=98=E5=8C=96builder?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
smart-flow-core/pom.xml | 7 ++
.../org/smartboot/flow/core/FlowEngine.java | 2 +-
.../flow/core/builder/EngineBuilder.java | 8 ++-
.../flow/core/builder/PipelineBuilder.java | 17 ++---
.../flow/core/component/Component.java | 2 +-
.../flow/core/extension/ExtensionFactory.java | 14 +++-
.../core/manager/DefaultEngineManager.java | 32 +++++++--
.../flow/core/manager/EngineManager.java | 12 ++++
.../core/manager/NamedIdentifierManager.java | 24 -------
.../core/manager/RegisterEngineVisitor.java | 11 +--
.../manager/RegisteredComponentVisitor.java | 18 +++--
.../manager/RegisteredPipelineVisitor.java | 10 ++-
.../core/parser/BuilderDefinitionVisitor.java | 8 +--
.../flow/core/parser/DefaultParser.java | 71 ++++++++++++++-----
.../smartboot/flow/core/parser/Parser.java | 12 +++-
.../flow/core/util/ContactUtils.java | 13 ++++
.../src/main/resources/smart-flow-1.0.0.xsd | 50 ++++++-------
.../org/smartboot/flow/core/BaseTest.java | 7 ++
.../org/smartboot/flow/core/EngineTest.java | 10 +--
.../smartboot/flow/core/async/AsyncTest.java | 2 +-
.../flow/core/attributes/AttributeTest.java | 4 +-
.../core/builder/IfComponentBuilderTest.java | 4 +-
.../flow/core/manager/ManagerTest.java | 11 ++-
.../flow/core/parser/DefaultParserTest.java | 21 +++---
.../src/test/resources/flow-example.xsd | 49 -------------
.../src/test/resources/flow-example2.xsd | 42 -----------
smart-flow-spring-extension/pom.xml | 7 ++
27 files changed, 235 insertions(+), 233 deletions(-)
delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/NamedIdentifierManager.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
delete mode 100644 smart-flow-core/src/test/resources/flow-example2.xsd
diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml
index 85b8511..fe5bba9 100644
--- a/smart-flow-core/pom.xml
+++ b/smart-flow-core/pom.xml
@@ -25,6 +25,13 @@
test
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.1
+ test
+
+
ch.qos.logback
logback-core
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 a29bcbb..6494c4f 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
@@ -125,7 +125,7 @@ public class FlowEngine implements Describable, Validator {
}
AssertUtil.notBlank(name, "engine's name must not be null");
- AssertUtil.notNull(pipeline, "engine[ " + getName() + " ]pipeline must not be null");
+ AssertUtil.notNull(pipeline, "engine[ " + name + " ]pipeline must not be null");
pipeline.validate();
validateCalled = true;
DefaultEngineManager.getDefaultManager().register(this);
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/EngineBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/EngineBuilder.java
index 4a81339..d54e1c0 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/EngineBuilder.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/EngineBuilder.java
@@ -18,8 +18,8 @@ public class EngineBuilder {
private String name;
private ExecutorService executor;
- public EngineBuilder() {
- this.name = "defaultEngine";
+ public EngineBuilder(String name) {
+ this.name = name;
}
public EngineBuilder pipeline(Pipeline pipeline) {
@@ -29,7 +29,7 @@ public class EngineBuilder {
}
public EngineBuilder name(String name) {
- AssertUtil.notNull(name, "must not be null");
+ AssertUtil.notBlank(name, "engine's name is required");
this.name = name;
return this;
}
@@ -42,6 +42,8 @@ public class EngineBuilder {
public FlowEngine build() {
+ AssertUtil.notBlank(name, "engine's name is required");
+
FlowEngine engine = new FlowEngine<>();
engine.setName(name);
engine.setPipeline(pipeline);
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 c033704..4b5adff 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
@@ -32,15 +32,11 @@ public class PipelineBuilder {
}
public PipelineBuilder(String name) {
- this((PipelineBuilder)null, name);
- }
-
- public PipelineBuilder() {
- this((PipelineBuilder)null, "DefaultPipeline");
+ this(null, name);
}
public PipelineBuilder name(String name) {
- AssertUtil.notNull(name, "must not be null");
+ AssertUtil.notBlank(name, "must not be null");
this.name = name;
return this;
}
@@ -68,12 +64,8 @@ public class PipelineBuilder {
return new ChooseBuilder<>(this, condition);
}
- public PipelineBuilder pipeline() {
- return pipeline("Subprocess");
- }
-
public PipelineBuilder pipeline(String name) {
- AssertUtil.notNull(name, "must not be null");
+ AssertUtil.notBlank(name, "must not be null");
return new PipelineBuilder<>(this, name);
}
@@ -85,12 +77,15 @@ public class PipelineBuilder {
Pipeline pipeline = build();
PipelineComponent pipelineComponent = new PipelineComponent<>(pipeline);
+ pipelineComponent.setName("anonymous@" + name);
parent.next(pipelineComponent);
return parent;
}
public Pipeline build() {
+ AssertUtil.notBlank(name, "pipeline's name is required");
+
Pipeline pipeline = new Pipeline<>();
pipeline.setComponents(this.components);
pipeline.setName(name);
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 bb5b75c..ac3ef4e 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
@@ -30,7 +30,7 @@ public abstract class Component implements Rollback, Describable, Va
private boolean async;
private long timeout;
private List dependsOn;
- private String name = "none";
+ private String name;
private boolean enabled = true;
protected final List attributes = new ArrayList<>(0);
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
index 9e30d23..a03bf84 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
@@ -2,7 +2,9 @@ package org.smartboot.flow.core.extension;
import org.smartboot.flow.core.util.AssertUtil;
+import java.util.Map;
import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
/**
* @author qinluo
@@ -11,15 +13,25 @@ import java.util.ServiceLoader;
*/
public class ExtensionFactory {
+ /**
+ * 默认扩展
+ */
+ private static final Map, Object> REGISTERED_DEFAULT = new ConcurrentHashMap<>();
+
+ static {
+ REGISTERED_DEFAULT.put(ObjectCreator.class, new DefaultObjectCreator());
+ }
+
/**
* 获取扩展实现
*/
+ @SuppressWarnings("unchecked")
public static T getExtension(Class type) {
AssertUtil.notNull(type, "type must not be null!");
ServiceLoader loaded = ServiceLoader.load(type);
if (!loaded.iterator().hasNext()) {
- return null;
+ return (T)REGISTERED_DEFAULT.get(type);
}
return loaded.iterator().next();
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 722214f..0607a78 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
@@ -1,7 +1,8 @@
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.IdentifierManager;
import org.smartboot.flow.core.component.AttributeHolder;
import org.smartboot.flow.core.util.AssertUtil;
@@ -16,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class DefaultEngineManager implements EngineManager {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultEngineManager.class);
private static final DefaultEngineManager INSTANCE = new DefaultEngineManager();
private final Map registeredEngines = new ConcurrentHashMap<>();
@@ -26,8 +28,18 @@ public class DefaultEngineManager implements EngineManager {
@Override
public void register(FlowEngine engine) {
- IdentifierManager identifierManager = new NamedIdentifierManager(engine.getName());
- RegisterEngineVisitor visitor = new RegisterEngineVisitor(identifierManager);
+ AssertUtil.notNull(engine, "registered engine must not be null");
+ AssertUtil.notBlank(engine.getName(), "registered engine name must not be blank");
+
+ if (registeredEngines.get(engine.getName()) != null) {
+ LOGGER.error("engine {} already registered", engine.getName());
+ return;
+ }
+
+ // Ensure engine and components is valid
+ engine.validate();
+
+ RegisterEngineVisitor visitor = new RegisterEngineVisitor();
visitor.visit(engine);
EngineModel model = visitor.getEngine();
@@ -36,12 +48,13 @@ public class DefaultEngineManager implements EngineManager {
@Override
public EngineModel getEngineModel(String name) {
- AssertUtil.notNull(name, "name must not be null!");
+ AssertUtil.notBlank(name, "name must not be blank!");
return registeredEngines.get(name);
}
@Override
public void changeAttributes(String identifier, List attributeHolders) {
+ AssertUtil.notBlank(identifier, "identifier must not be blank!");
if (registeredEngines.containsKey(identifier)) {
// change engine attributes.
return;
@@ -54,4 +67,15 @@ public class DefaultEngineManager implements EngineManager {
}
}
}
+
+ @Override
+ public void detachAll() {
+ this.registeredEngines.clear();
+ }
+
+ @Override
+ public void detach(String name) {
+ AssertUtil.notBlank(name, "name must not be blank!");
+ this.registeredEngines.remove(name);
+ }
}
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 accf946..02bb830 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
@@ -47,4 +47,16 @@ public interface EngineManager {
default void changeAttributes(String identifier, AttributeHolder holder) {
this.changeAttributes(identifier, Collections.singletonList(holder));
}
+
+ /**
+ * Make all engine detach from manager.
+ */
+ void detachAll();
+
+ /**
+ * Make specific engine detach from manager
+ *
+ * @param name engine name.
+ */
+ void detach(String name);
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/NamedIdentifierManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/NamedIdentifierManager.java
deleted file mode 100644
index 3e1d886..0000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/NamedIdentifierManager.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.smartboot.flow.core.manager;
-
-import org.smartboot.flow.core.DefaultIdentifierManager;
-import org.smartboot.flow.core.IdentifierManager;
-
-/**
- * @author qinluo
- * @date 2022/11/19 12:37
- * @since 1.0.0
- */
-public class NamedIdentifierManager implements IdentifierManager {
-
- private final String name;
- private final IdentifierManager delegate = new DefaultIdentifierManager();
-
- public NamedIdentifierManager(String name) {
- this.name = name;
- }
-
- @Override
- public String generateIdentifier(String prefix) {
- return delegate.generateIdentifier(name + "-" + prefix);
- }
-}
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 4163e3e..3ff2a26 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,7 +1,7 @@
package org.smartboot.flow.core.manager;
-import org.smartboot.flow.core.IdentifierManager;
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;
@@ -13,11 +13,6 @@ import org.smartboot.flow.core.visitor.PipelineVisitor;
public class RegisterEngineVisitor extends EngineVisitor {
private EngineModel model;
- private final IdentifierManager identifierManager;
-
- public RegisterEngineVisitor(IdentifierManager identifierManager) {
- this.identifierManager = identifierManager;
- }
@Override
public void visitEnd() {
@@ -31,9 +26,9 @@ public class RegisterEngineVisitor extends EngineVisitor {
@Override
public PipelineVisitor visitPipeline(Pipeline pipeline) {
- PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), identifierManager.generateIdentifier(pipeline.describe()));
+ PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(this.model.getIdentifier(), pipeline.describe()));
this.model.setPipeline(pipelineModel);
- return new RegisteredPipelineVisitor(pipelineModel, identifierManager);
+ return new RegisteredPipelineVisitor(pipelineModel);
}
public EngineModel getEngine() {
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 e383a79..5e46d58 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,10 +1,10 @@
package org.smartboot.flow.core.manager;
-import org.smartboot.flow.core.IdentifierManager;
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.component.Component;
+import org.smartboot.flow.core.util.ContactUtils;
import org.smartboot.flow.core.visitor.ComponentVisitor;
import org.smartboot.flow.core.visitor.PipelineVisitor;
@@ -18,19 +18,17 @@ import java.util.List;
public class RegisteredComponentVisitor extends ComponentVisitor {
private final ComponentModel model;
- private final IdentifierManager identifierManager;
- public RegisteredComponentVisitor(ComponentModel comp, IdentifierManager identifierManager) {
+ public RegisteredComponentVisitor(ComponentModel comp) {
this.model = comp;
- this.identifierManager = identifierManager;
}
@Override
public PipelineVisitor visitPipeline(Pipeline pipeline) {
- PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), identifierManager.generateIdentifier("pipeline"));
+ PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(model.getIdentifier(), pipeline.describe()));
this.model.pipeline = pipelineModel;
this.model.type = (ComponentType.PIPELINE);
- return new RegisteredPipelineVisitor(pipelineModel, identifierManager);
+ return new RegisteredPipelineVisitor(pipelineModel);
}
@Override
@@ -41,9 +39,9 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
@Override
public ComponentVisitor visitComponent(Component component) {
- ComponentModel comp = new ComponentModel(identifierManager.generateIdentifier(component.getName()), component);
+ ComponentModel comp = new ComponentModel(ContactUtils.contact(model.getIdentifier(), component.getName()), component);
this.model.addComponent(comp);
- return new RegisteredComponentVisitor(comp, identifierManager);
+ return new RegisteredComponentVisitor(comp);
}
@Override
@@ -53,11 +51,11 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
@Override
public ComponentVisitor visitBranch(Object branch, Component component) {
- ComponentModel model = new ComponentModel(identifierManager.generateIdentifier(component.getName()), component);
+ ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), component.getName()), component);
model.branch = (String.valueOf(branch));
this.model.addComponent(model);
this.model.type = (ComponentType.CHOOSE);
- return new RegisteredComponentVisitor(model, identifierManager);
+ return new RegisteredComponentVisitor(model);
}
@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 e79ae84..0962ff2 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,7 +1,7 @@
package org.smartboot.flow.core.manager;
-import org.smartboot.flow.core.IdentifierManager;
import org.smartboot.flow.core.component.Component;
+import org.smartboot.flow.core.util.ContactUtils;
import org.smartboot.flow.core.visitor.ComponentVisitor;
import org.smartboot.flow.core.visitor.PipelineVisitor;
@@ -13,17 +13,15 @@ import org.smartboot.flow.core.visitor.PipelineVisitor;
public class RegisteredPipelineVisitor extends PipelineVisitor {
private final PipelineModel pipelineModel;
- private final IdentifierManager identifierManager;
- public RegisteredPipelineVisitor(PipelineModel pipelineModel, IdentifierManager identifierManager) {
+ public RegisteredPipelineVisitor(PipelineModel pipelineModel) {
this.pipelineModel = pipelineModel;
- this.identifierManager = identifierManager;
}
@Override
public ComponentVisitor visitComponent(Component component) {
- ComponentModel comp = new ComponentModel(identifierManager.generateIdentifier(this.pipelineModel.getName() + "-" +component.getName()), component);
+ ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), component.getName()), component);
this.pipelineModel.addComponent(comp);
- return new RegisteredComponentVisitor(comp, identifierManager);
+ return new RegisteredComponentVisitor(comp);
}
}
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 e86ff22..608796e 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,7 +11,6 @@ import org.smartboot.flow.core.builder.PipelineBuilder;
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.extension.DefaultObjectCreator;
import org.smartboot.flow.core.extension.ExtensionFactory;
import org.smartboot.flow.core.extension.ObjectCreator;
import org.smartboot.flow.core.parser.definition.ChooseDefinition;
@@ -38,15 +37,12 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor {
private final Map> namedPipelines = new ConcurrentHashMap<>();
private final Map> namedEngines = new ConcurrentHashMap<>();
private final Map> callbacks = new ConcurrentHashMap<>();
- private ObjectCreator objectCreator;
+ private final ObjectCreator objectCreator;
private final boolean useCache;
public BuilderDefinitionVisitor(boolean useCache) {
this.useCache = useCache;
objectCreator = ExtensionFactory.getExtension(ObjectCreator.class);
- if (objectCreator == null) {
- objectCreator = new DefaultObjectCreator();
- }
}
@Override
@@ -77,7 +73,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor {
@Override
public void visit(EngineDefinition ed) {
String engineName = ed.getIdentifier();
- EngineBuilder, ?> engineBuilder = new EngineBuilder<>().name(engineName);
+ EngineBuilder, ?> engineBuilder = new EngineBuilder<>(engineName);
PipelineBuilder pipelineBuilder = this.namedPipelines.get(ed.getPipeline());
if (pipelineBuilder == null) {
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 7fbe2a5..c2348ab 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
@@ -28,32 +28,71 @@ public class DefaultParser implements Parser {
}
private BuilderDefinitionVisitor visitor;
+ private final ParserContext context = new ParserContext();
@Override
- public void parse(InputStream is) {
+ public void parse(InputStream is, InputStream... streams) {
AssertUtil.notNull(is, "Stream must not be null");
- Element root = readRoot(is);
- AssertUtil.notNull(root, "Read root element is null");
- AssertUtil.assertEquals(ElementUtils.getName(root), ParseConstants.ENGINES, "Root element must be engines");
-
- List elements = ElementUtils.subElements(root);
- AssertUtil.isTrue(elements.size() != 0, "[engines] element's sub elements must not be empty");
-
- ParserContext context = new ParserContext();
- for (Element sub : elements) {
- String subName = ElementUtils.getName(sub);
- AssertUtil.isTrue(ALLOWED.contains(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);
+ List willParsedStreams = new ArrayList<>();
+ willParsedStreams.add(is);
+
+ if (streams != null && streams.length != 0) {
+ for (InputStream stream : streams) {
+ AssertUtil.notNull(stream, "Stream must not be null");
+ willParsedStreams.add(stream);
+ }
+ }
+
+ boolean useCache = true;
+
+ for (InputStream stream : willParsedStreams) {
+ Element root = readRoot(stream);
+ AssertUtil.notNull(root, "Read root element is null");
+ AssertUtil.assertEquals(ElementUtils.getName(root), ParseConstants.ENGINES, "Root element must be engines");
+
+ List elements = ElementUtils.subElements(root);
+ AssertUtil.isTrue(elements.size() != 0, "[engines] element's sub elements must not be empty");
+
+ for (Element sub : elements) {
+ String subName = ElementUtils.getName(sub);
+ AssertUtil.isTrue(ALLOWED.contains(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);
+ }
}
- boolean useCache = Boolean.parseBoolean(root.getAttribute("useCache"));
this.visitor = new BuilderDefinitionVisitor(useCache);
context.getRegistered().forEach(ElementDefinition::validate);
context.getRegistered().forEach(p -> visitor.visit(p));
}
+ @Override
+ public void parse(String f, String... files) {
+ AssertUtil.notBlank(f, "filename must not be null!");
+ if (files != null && files.length != 0) {
+ for (String file : files) {
+ AssertUtil.notBlank(file, "filename must not be null!");
+ }
+ }
+
+ InputStream fstream = this.getClass().getResourceAsStream(f);
+ AssertUtil.notNull(fstream, "filename " + f + " not exist");
+
+ InputStream[] streams = new InputStream[0];
+ int index = 0;
+ if (files != null && files.length != 0) {
+ streams = new InputStream[files.length];
+ for (String file : files) {
+ InputStream stream = this.getClass().getResourceAsStream(f);
+ AssertUtil.notNull(stream, "filename " + file + " not exist");
+ streams[index++] = stream;
+ }
+ }
+
+ this.parse(fstream, streams);
+ }
+
public FlowEngine getEngine(String name) {
return visitor.getEngine(name);
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/Parser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/Parser.java
index a6d5706..58ddbdb 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/Parser.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/Parser.java
@@ -10,7 +10,17 @@ public interface Parser {
/**
* Parse config file
+ * @param is is
+ * @param streams other multiple is.
+ */
+ void parse(InputStream is, InputStream ... streams);
+
+ /**
+ * Parse file and other multiple files.
*
+ * @param f file location
+ * @param files other multiple file location
*/
- void parse(InputStream is);
+ void parse(String f, String... files);
+
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
new file mode 100644
index 0000000..4bc78b3
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
@@ -0,0 +1,13 @@
+package org.smartboot.flow.core.util;
+
+/**
+ * @author qinluo
+ * @date 2022/11/20 22:10
+ * @since 1.0.0
+ */
+public final class ContactUtils {
+
+ public static String contact(String p, String s) {
+ return p + "-" + s;
+ }
+}
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.0.xsd
index bcbdbfe..a7c7130 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.0.xsd
@@ -1,48 +1,34 @@
+ elementFormDefault="qualified">
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -54,7 +40,6 @@
-
@@ -62,7 +47,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -86,7 +86,6 @@
-
@@ -107,7 +106,6 @@
-
@@ -147,7 +145,6 @@
-
@@ -168,7 +165,6 @@
-
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
index b4949e9..12b0b87 100644
--- 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
@@ -1,7 +1,9 @@
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
@@ -11,4 +13,9 @@ 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/EngineTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java
index 79775ba..e705f52 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/EngineTest.java
@@ -66,8 +66,8 @@ public class EngineTest {
@Test
public void testSimpleBuilder() {
- EngineBuilder builder = new EngineBuilder<>();
- FlowEngine engine = builder.pipeline(new PipelineBuilder().next(new AbstractExecutable() {
+ 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);
@@ -99,8 +99,8 @@ public class EngineTest {
@Test
public void testSimpleBuilder02() {
- EngineBuilder builder = new EngineBuilder<>();
- FlowEngine engine = builder.pipeline(new PipelineBuilder().next(new AbstractExecutable() {
+ 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);
@@ -166,7 +166,7 @@ public class EngineTest {
@Test
public void testBuildPipeline() {
- EngineBuilder builder = new EngineBuilder<>();
+ EngineBuilder builder = new EngineBuilder<>("defaultEngine");
PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process");
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java
index 43b4008..54e5afd 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/async/AsyncTest.java
@@ -41,7 +41,7 @@ public class AsyncTest extends BaseTest {
@Test
public void testAsync() {
- EngineBuilder builder = new EngineBuilder<>();
+ EngineBuilder builder = new EngineBuilder<>("defaultEngine");
PipelineBuilder pipelineBuilder = new PipelineBuilder<>("main process");
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java
index c24ed16..d16e59f 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/attributes/AttributeTest.java
@@ -26,14 +26,14 @@ public class AttributeTest extends BaseTest {
@Test
public void testEnabled() {
- PipelineBuilder builder = new PipelineBuilder<>();
+ 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<>();
+ EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine");
FlowEngine engine = engineBuilder.pipeline(build).build();
EngineContext context = engine.execute(1);
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java
index 4f54506..f7677c2 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/builder/IfComponentBuilderTest.java
@@ -20,12 +20,12 @@ public class IfComponentBuilderTest extends BaseTest{
@Test
public void testBuild() {
- PipelineBuilder builder = new PipelineBuilder<>();
+ 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<>();
+ EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine");
FlowEngine engine = engineBuilder.pipeline(build).build();
EngineContext context = engine.execute(1);
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
index c8cd6be..fdbdc4f 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
@@ -1,5 +1,6 @@
package org.smartboot.flow.core.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;
@@ -32,10 +33,16 @@ import java.util.Map;
*/
public class ManagerTest extends BaseTest {
+ @BeforeEach
+ public void setUp() {
+ DefaultEngineManager.getDefaultManager().detachAll();
+ LOGGER.info("detachAll executed");
+ }
+
@Test
public void testModifyAttributes() {
- PipelineBuilder builder = new PipelineBuilder<>();
+ 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()
@@ -44,7 +51,7 @@ public class ManagerTest extends BaseTest {
.pipeline("subprocess##2").next(new AsyncStep1()).next(new AsyncStep2()).next(new AsyncStep3()).end()
.build();
- EngineBuilder engineBuilder = new EngineBuilder<>();
+ EngineBuilder engineBuilder = new EngineBuilder<>("defaultEngine");
FlowEngine engine = engineBuilder.pipeline(build).build();
EngineContext context = engine.execute(1);
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java
index 6314b2a..725bc13 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/parser/DefaultParserTest.java
@@ -1,12 +1,16 @@
package org.smartboot.flow.core.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.smartboot.flow.core.EngineContext;
import org.smartboot.flow.core.FlowEngine;
+import org.smartboot.flow.core.manager.DefaultEngineManager;
import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor;
+import java.io.InputStream;
+
/**
* @author qinluo
* @date 2022-11-15 23:42:32
@@ -14,10 +18,15 @@ import org.smartboot.flow.core.view.plantuml.PlantumlEngineVisitor;
*/
public class DefaultParserTest extends BaseTest {
+ @BeforeEach
+ public void setUp() {
+ DefaultEngineManager.getDefaultManager().detachAll();
+ }
+
@Test
public void testParseNull() {
DefaultParser parser = new DefaultParser();
- Exception e = Assertions.assertThrows(IllegalArgumentException.class, () -> parser.parse(null));
+ Exception e = Assertions.assertThrows(IllegalArgumentException.class, () -> parser.parse((InputStream) null));
LOGGER.error("", e);
}
@@ -29,14 +38,6 @@ public class DefaultParserTest extends BaseTest {
LOGGER.error("", e);
}
- @Test
- public void testParseWithUncorrectedSubElement() {
- DefaultParser parser = new DefaultParser();
- Exception e = Assertions.assertThrows(IllegalArgumentException.class, () ->
- parser.parse(this.getClass().getResourceAsStream("/flow-example2.xsd")));
- LOGGER.error("", e);
- }
-
@Test
public void testParseSimple() {
DefaultParser parser = new DefaultParser();
@@ -71,7 +72,6 @@ public class DefaultParserTest extends BaseTest {
@Test
public void testParseNestedElementsInPipeline2() {
- System.setProperty("use.try", "true");
DefaultParser parser = new DefaultParser();
parser.parse(this.getClass().getResourceAsStream("/flow-example6.xsd"));
@@ -84,7 +84,6 @@ public class DefaultParserTest extends BaseTest {
@Test
public void testParseNestedElementsInPipeline3() {
- System.setProperty("use.try", "true");
DefaultParser parser = new DefaultParser();
parser.parse(this.getClass().getResourceAsStream("/flow-example7.xsd"));
diff --git a/smart-flow-core/src/test/resources/flow-example.xsd b/smart-flow-core/src/test/resources/flow-example.xsd
index 644ae1b..7231d98 100644
--- a/smart-flow-core/src/test/resources/flow-example.xsd
+++ b/smart-flow-core/src/test/resources/flow-example.xsd
@@ -5,53 +5,4 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/smart-flow-core/src/test/resources/flow-example2.xsd b/smart-flow-core/src/test/resources/flow-example2.xsd
deleted file mode 100644
index 8e3035b..0000000
--- a/smart-flow-core/src/test/resources/flow-example2.xsd
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml
index feb576d..285eacc 100644
--- a/smart-flow-spring-extension/pom.xml
+++ b/smart-flow-spring-extension/pom.xml
@@ -68,5 +68,12 @@
5.9.1
test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.1
+ test
+
\ No newline at end of file
--
Gitee
From e3a36701ccf98f246b4d35b38cf64cc19cedea2e Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Mon, 21 Nov 2022 09:51:10 +0800
Subject: [PATCH 02/14] qinluo: - optimized
---
.../java/org/smartboot/flow/core/parser/DefaultParser.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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 c2348ab..64ce5e7 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
@@ -43,7 +43,7 @@ public class DefaultParser implements Parser {
}
}
- boolean useCache = true;
+ boolean useCache = false;
for (InputStream stream : willParsedStreams) {
Element root = readRoot(stream);
@@ -60,6 +60,8 @@ public class DefaultParser implements Parser {
AssertUtil.notNull(parser, "Could not find parser for element " + subName);
parser.parseElement(sub, context);
}
+
+ useCache = useCache || Boolean.parseBoolean(root.getAttribute("useCache"));
}
this.visitor = new BuilderDefinitionVisitor(useCache);
--
Gitee
From 460b47958e844bb8f58a0328081bb4c1360a53e5 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Mon, 21 Nov 2022 12:01:29 +0800
Subject: [PATCH 03/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20identifier?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E4=BC=98=E5=8C=96=20=20=20=20=20=20-=20plant?=
=?UTF-8?q?uml=E5=9B=BE=E5=83=8F=E5=A4=84=E7=90=86=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../flow/core/DefaultIdentifierManager.java | 8 +++++---
.../flow/core/component/ChooseComponent.java | 2 +-
.../flow/core/component/IfComponent.java | 2 +-
.../flow/core/component/PipelineComponent.java | 2 +-
.../flow/core/manager/ComponentModel.java | 11 +++++++++--
.../manager/RegisteredComponentVisitor.java | 10 ++++++++--
.../core/manager/RegisteredPipelineVisitor.java | 3 ++-
.../flow/core/parser/ElementUtils.java | 15 ---------------
.../flow/core/util/AuxiliaryUtils.java | 17 +++++++++++++++++
.../smartboot/flow/core/util/ContactUtils.java | 11 +++++++++--
.../core/view/plantuml/PlantumlComponent.java | 3 ++-
.../view/plantuml/PlantumlEngineVisitor.java | 2 ++
.../flow/core/manager/ManagerTest.java | 2 +-
.../src/test/resources/flow-example7.xsd | 2 +-
14 files changed, 59 insertions(+), 31 deletions(-)
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/DefaultIdentifierManager.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/DefaultIdentifierManager.java
index 0dbe682..92a75c4 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/DefaultIdentifierManager.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/DefaultIdentifierManager.java
@@ -1,9 +1,10 @@
package org.smartboot.flow.core;
-import org.smartboot.flow.core.parser.ElementUtils;
+import org.smartboot.flow.core.util.ContactUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* @author qinluo
@@ -16,14 +17,15 @@ public class DefaultIdentifierManager implements IdentifierManager {
* Generated identifiers.
*/
private final Map identifiers = new ConcurrentHashMap<>();
+ private final AtomicInteger sequence = new AtomicInteger(0);
@Override
public String generateIdentifier(String prefix) {
- String identifier = ElementUtils.random(prefix);
+ String identifier = ContactUtils.contact(prefix, sequence.getAndAdd(1));
// Ensure identifier is unique.
while (identifiers.containsKey(identifier) || identifiers.put(identifier, 1) != null) {
- identifier = ElementUtils.random(prefix);
+ identifier = ContactUtils.contact(prefix, sequence.getAndAdd(1));
}
return identifier;
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 d831e6f..b03c439 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
@@ -107,7 +107,7 @@ public class ChooseComponent extends Component {
@Override
public String describe() {
- return "choose##" + condition.describe();
+ return "choose@" + condition.describe();
}
@Override
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 25706d2..edb453f 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
@@ -85,7 +85,7 @@ public class IfComponent extends Component{
@Override
public String describe() {
- return "if-component condition = " + condition.describe();
+ return "if@" + condition.describe();
}
@Override
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 8c2b18c..83c5322 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
@@ -53,7 +53,7 @@ public class PipelineComponent extends Component {
@Override
public String describe() {
- return "pipeline##" + pipeline.describe();
+ return "pipeline@" + pipeline.describe();
}
@Override
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 e844c38..6118e81 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
@@ -74,9 +74,16 @@ public class ComponentModel extends Uniqueness {
if (type == ComponentType.PIPELINE) {
this.pipeline.collect();
return pipeline.getComponents();
+ } else if (type == ComponentType.BASIC) {
+ Map temp = new HashMap<>();
+ temp.put(this.identifier, this);
+ return temp;
+ } else {
+ Map temp = new HashMap<>();
+ this.components.forEach((k, v) -> temp.putAll(v.getComponents()));
+ temp.put(this.identifier, this);
+ return temp;
}
-
- return components;
}
void addComponent(ComponentModel 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 5e46d58..25e1589 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
@@ -4,6 +4,7 @@ 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.component.Component;
+import org.smartboot.flow.core.util.AuxiliaryUtils;
import org.smartboot.flow.core.util.ContactUtils;
import org.smartboot.flow.core.visitor.ComponentVisitor;
import org.smartboot.flow.core.visitor.PipelineVisitor;
@@ -39,7 +40,12 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
@Override
public ComponentVisitor visitComponent(Component component) {
- ComponentModel comp = new ComponentModel(ContactUtils.contact(model.getIdentifier(), component.getName()), component);
+ String identifier = ContactUtils.contact(model.getIdentifier(), AuxiliaryUtils.or(component.getName(), component.describe()));
+ if (this.model.type == ComponentType.CHOOSE) {
+ identifier = ContactUtils.contact(model.getIdentifier(), "default");
+ }
+
+ ComponentModel comp = new ComponentModel(identifier, component);
this.model.addComponent(comp);
return new RegisteredComponentVisitor(comp);
}
@@ -51,7 +57,7 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
@Override
public ComponentVisitor visitBranch(Object branch, Component component) {
- ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), component.getName()), component);
+ ComponentModel model = new ComponentModel(ContactUtils.contact(this.model.getIdentifier(), "branch", String.valueOf(branch)), component);
model.branch = (String.valueOf(branch));
this.model.addComponent(model);
this.model.type = (ComponentType.CHOOSE);
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 0962ff2..9c62bad 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.util.AuxiliaryUtils;
import org.smartboot.flow.core.util.ContactUtils;
import org.smartboot.flow.core.visitor.ComponentVisitor;
import org.smartboot.flow.core.visitor.PipelineVisitor;
@@ -20,7 +21,7 @@ public class RegisteredPipelineVisitor extends PipelineVisitor {
@Override
public ComponentVisitor visitComponent(Component component) {
- ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), component.getName()), component);
+ ComponentModel comp = new ComponentModel(ContactUtils.contact(this.pipelineModel.getIdentifier(), AuxiliaryUtils.or(component.getName(), component.describe())), component);
this.pipelineModel.addComponent(comp);
return new RegisteredComponentVisitor(comp);
}
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 2e435b4..de9a862 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
@@ -9,7 +9,6 @@ import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.ThreadLocalRandom;
/**
* @author qinluo
@@ -18,12 +17,6 @@ import java.util.concurrent.ThreadLocalRandom;
*/
public final class ElementUtils {
- private static final byte[] CHARS = new byte[] {'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u',
- 'v', 'w', 'x', 'y', 'z', '0', '1',
- '2', '3', '4', '5', '6', '7', '8', '9'};
-
/**
* Extra all well-known attributes.
*/
@@ -78,14 +71,6 @@ public final class ElementUtils {
return localName;
}
- public static String random(String prefix) {
- StringBuilder sb = new StringBuilder(prefix).append("-");
- for (int i = 0; i < 8; i++) {
- sb.append((char)CHARS[ThreadLocalRandom.current().nextInt(CHARS.length)]);
- }
- return sb.toString();
- }
-
public static boolean isBlank(String value) {
return value == null || value.trim().length() == 0;
}
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
new file mode 100644
index 0000000..5d51749
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/AuxiliaryUtils.java
@@ -0,0 +1,17 @@
+package org.smartboot.flow.core.util;
+
+/**
+ * @author qinluo
+ * @date 2022-11-20 11:32:23
+ * @since 1.0.0
+ */
+public final class AuxiliaryUtils {
+
+ public static T or(T t, T defaultValue) {
+ return t != null ? t : defaultValue;
+ }
+
+ public static String or(String t, String defaultValue) {
+ return t != null && t.trim().length() > 0 ? t : defaultValue;
+ }
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
index 4bc78b3..e197918 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/ContactUtils.java
@@ -7,7 +7,14 @@ package org.smartboot.flow.core.util;
*/
public final class ContactUtils {
- public static String contact(String p, String s) {
- return p + "-" + s;
+ public static String contact(String p, Object ...s) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(p);
+
+ for (Object suffix : s) {
+ sb.append("-").append(suffix);
+ }
+
+ return sb.toString();
}
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/view/plantuml/PlantumlComponent.java
index c401e98..52ee904 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
@@ -134,8 +134,9 @@ public class PlantumlComponent {
content.append("endswitch\n");
} else if (getType() == ComponentType.PIPELINE) {
- content.append(":").append("subprocess:").append(pipeline.getName()).append(";\n");
+ 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 87d2841..40c013f 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
@@ -60,6 +60,8 @@ public class PlantumlEngineVisitor extends EngineVisitor {
}
content.append("\nend split\n");
+ content.append("\n : start ;\n");
+
plantumlEngine.getPipeline().generate(content);
content.append("\n : end ;\n");
diff --git a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java b/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
index fdbdc4f..b7f40c4 100644
--- a/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
+++ b/smart-flow-core/src/test/java/org/smartboot/flow/core/manager/ManagerTest.java
@@ -64,7 +64,7 @@ public class ManagerTest extends BaseTest {
Map components = engineModel.getComponents();
String identifier = null;
for (Map.Entry modelEntry : components.entrySet()) {
- if (modelEntry.getValue().getDescribe().contains("pipeline##subprocess##2")) {
+ if (modelEntry.getValue().getDescribe().contains("pipeline@subprocess##2")) {
identifier = modelEntry.getKey();
}
diff --git a/smart-flow-core/src/test/resources/flow-example7.xsd b/smart-flow-core/src/test/resources/flow-example7.xsd
index 23103a0..24d3345 100644
--- a/smart-flow-core/src/test/resources/flow-example7.xsd
+++ b/smart-flow-core/src/test/resources/flow-example7.xsd
@@ -7,7 +7,7 @@
-
+
--
Gitee
From 97a1de47d256c561ceb262106d85b847f01522dd Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Mon, 21 Nov 2022 12:02:42 +0800
Subject: [PATCH 04/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20plantuml?=
=?UTF-8?q?=E5=9B=BE=E5=83=8F=E5=A4=84=E7=90=86=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../smartboot/flow/core/view/plantuml/PlantumlComponent.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 52ee904..ee2f519 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
@@ -99,7 +99,7 @@ public class PlantumlComponent {
}
public void generate(StringBuilder content) {
- String nodeName = name == null ? describe : name + "#" + describe;
+ String nodeName = name == null ? describe : name;
if (getType() == ComponentType.BASIC) {
String serialAttributes = serialAttributes();
--
Gitee
From 369e8e3568ed466aedcd5f957a8c3336e8cb2d86 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Tue, 22 Nov 2022 19:42:07 +0800
Subject: [PATCH 05/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20identifier?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../smartboot/flow/core/NamedCondition.java | 20 ++++++++++++++++++
.../core/parser/AbstractElementParser.java | 21 ++++++++++---------
.../flow/core/parser/ChooseElementParser.java | 7 ++++---
.../core/parser/ComponentElementParser.java | 9 ++++----
.../flow/core/parser/ElementUtils.java | 11 ++--------
.../flow/core/parser/EngineElementParser.java | 2 +-
.../flow/core/parser/IfElementParser.java | 7 ++++---
.../core/parser/PipelineElementParser.java | 17 +++++++--------
.../flow/core/util/AuxiliaryUtils.java | 8 +++++++
.../core/view/plantuml/PlantumlComponent.java | 13 ++++++------
.../plantuml/PlantumlComponentVisitor.java | 2 +-
.../extension/BeanDefinitionVisitor.java | 8 +++----
.../spring/extension/NameAwareCondition.java | 18 ++++++++++++++++
.../extension/NamedAbstractExecutable.java | 2 +-
.../src/test/resources/bean.xml | 6 ++++++
15 files changed, 100 insertions(+), 51 deletions(-)
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/NamedCondition.java
create mode 100644 smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/NamedCondition.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/NamedCondition.java
new file mode 100644
index 0000000..ee5e559
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/NamedCondition.java
@@ -0,0 +1,20 @@
+package org.smartboot.flow.core;
+
+/**
+ * @author qinluo
+ * @date 2022-11-11 21:57:29
+ * @since 1.0.0
+ */
+public abstract class NamedCondition extends Condition {
+
+ private String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String describe() {
+ return this.name;
+ }
+}
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 4375f5f..07e22ba 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
@@ -22,7 +22,7 @@ public abstract class AbstractElementParser implements ElementParser {
AssertUtil.notNull(element, "[" + getElementName() + "] element must not be null!");
String localName = ElementUtils.getName(element);
AssertUtil.assertEquals(localName, getElementName(), "element must be [" + getElementName() + "] tag");
- this.parseElementInternal(element, context);
+ this.doParse(element, context);
}
protected String getIdentifier(Element element, ParserContext context) {
@@ -48,24 +48,25 @@ public abstract class AbstractElementParser implements ElementParser {
/**
* Parse internal.
*/
- public abstract void parseElementInternal(Element element, ParserContext context);
+ public abstract void doParse(Element element, ParserContext context);
protected ElementDefinition parseElementsAsPipeline(Element element, ParserContext context) {
// pipeline identifier.
- String identifier = context.allocateIdentifier("anonymous-pipeline");
+ String pipelineIdentifier = context.allocateIdentifier("anonymous-pipeline");
// Wrap sub elements as pipeline.
+ String identifier = context.allocateIdentifier("anonymous-pipeline-wrapper");
PipelineComponentDefinition def = new PipelineComponentDefinition();
- def.setName("anonymous-pipeline-component");
- def.setIdentifier(context.allocateIdentifier("anonymous-pipeline-component"));
- def.setPipeline(identifier);
+ def.setName(identifier);
+ def.setIdentifier(identifier);
+ def.setPipeline(pipelineIdentifier);
def.getAttributes().addAll(ElementUtils.extraAttributes(element));
context.register(def);
// Wrap as pipeline.
PipelineDefinition pipelineDef = new PipelineDefinition();
- pipelineDef.setName("anonymous-pipeline");
- pipelineDef.setIdentifier(identifier);
+ pipelineDef.setName(pipelineIdentifier);
+ pipelineDef.setIdentifier(pipelineIdentifier);
List subs = ElementUtils.subElements(element);
AssertUtil.isTrue(subs.size() != 0, "[" + ElementUtils.getName(element) + "] childNodes can't be null");
@@ -82,8 +83,8 @@ public abstract class AbstractElementParser implements ElementParser {
// nested subprocess
if (Objects.equals(subName, ParseConstants.PIPELINE)) {
PipelineComponentDefinition nestedWrap = new PipelineComponentDefinition();
- String nestedIdentifier = context.allocateIdentifier("pipelineComponent");
- nestedWrap.setName(ElementUtils.resolveName(sub, "pipeline-component"));
+ 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);
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 c33d987..57f0888 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
@@ -3,6 +3,7 @@ package org.smartboot.flow.core.parser;
import org.smartboot.flow.core.parser.definition.ChooseDefinition;
import org.smartboot.flow.core.parser.definition.ElementDefinition;
import org.smartboot.flow.core.util.AssertUtil;
+import org.smartboot.flow.core.util.AuxiliaryUtils;
import org.w3c.dom.Element;
import java.util.ArrayList;
@@ -27,10 +28,10 @@ public class ChooseElementParser extends AbstractElementParser{
}
@Override
- public void parseElementInternal(Element element, ParserContext context) {
+ public void doParse(Element element, ParserContext context) {
String test = element.getAttribute(ParseConstants.TEST);
String ref = element.getAttribute(ParseConstants.REF);
- if (ElementUtils.isBlank(ref) && ElementUtils.isBlank(test)) {
+ if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(test)) {
throw new IllegalArgumentException("attribute [ref] [type] cannot be null");
}
@@ -68,7 +69,7 @@ public class ChooseElementParser extends AbstractElementParser{
String type = subElement.getAttribute(ParseConstants.TYPE);
ref = subElement.getAttribute(ParseConstants.REF);
- if (ElementUtils.isNotBlank(type) || ElementUtils.isNotBlank(ref)) {
+ if (AuxiliaryUtils.isNotBlank(type) || AuxiliaryUtils.isNotBlank(ref)) {
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 1f73f91..3795839 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.AuxiliaryUtils;
import org.w3c.dom.Element;
/**
@@ -18,7 +19,7 @@ public class ComponentElementParser extends AbstractElementParser {
*/
@Override
- public void parseElementInternal(Element element, ParserContext context) {
+ public void doParse(Element element, ParserContext context) {
ElementDefinition elementDefinition = new ElementDefinition();
ElementDefinition.build(elementDefinition, element);
@@ -26,10 +27,10 @@ public class ComponentElementParser extends AbstractElementParser {
elementDefinition.setIdentifier(super.getIdentifier(element, context));
String subprocess = element.getAttribute(ParseConstants.SUBPROCESS);
- if (ElementUtils.isNotBlank(subprocess)) {
+ if (AuxiliaryUtils.isNotBlank(subprocess)) {
PipelineComponentDefinition def = new PipelineComponentDefinition();
ElementDefinition.build(def, element);
- def.setName(ElementUtils.resolveName(element, "pipeline-component"));
+ def.setName(ElementUtils.resolveName(element, "pipeline-wrapper-" + subprocess));
def.setIdentifier(super.getIdentifier(element, context));
def.setPipeline(subprocess);
context.register(def);
@@ -38,7 +39,7 @@ public class ComponentElementParser extends AbstractElementParser {
String ref = elementDefinition.getRef();
String type = elementDefinition.getType();
- if (ElementUtils.isBlank(ref) && ElementUtils.isBlank(type)) {
+ if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(type)) {
throw new IllegalArgumentException("attribute [ref] [type] cannot be null");
}
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 de9a862..35143ac 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
@@ -2,6 +2,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.util.AuxiliaryUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -56,7 +57,7 @@ public final class ElementUtils {
public static String resolveName(Element element, String suffix) {
String name = element.getAttribute(ParseConstants.NAME);
- if (isBlank(name)) {
+ if (AuxiliaryUtils.isBlank(name)) {
return "anonymous-" + suffix;
}
@@ -70,12 +71,4 @@ public final class ElementUtils {
}
return localName;
}
-
- public static boolean isBlank(String value) {
- return value == null || value.trim().length() == 0;
- }
-
- public static boolean isNotBlank(String value) {
- return !isBlank(value);
- }
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/EngineElementParser.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/EngineElementParser.java
index b835c06..4c398de 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/EngineElementParser.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/EngineElementParser.java
@@ -19,7 +19,7 @@ import org.w3c.dom.Element;
public class EngineElementParser extends AbstractElementParser {
@Override
- public void parseElementInternal(Element element, ParserContext context) {
+ public void doParse(Element element, ParserContext context) {
EngineDefinition definition = new EngineDefinition();
// name
String name = element.getAttribute(ParseConstants.NAME);
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 6bb1360..2fa9b95 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
@@ -3,6 +3,7 @@ package org.smartboot.flow.core.parser;
import org.smartboot.flow.core.parser.definition.ElementDefinition;
import org.smartboot.flow.core.parser.definition.IfElementDefinition;
import org.smartboot.flow.core.util.AssertUtil;
+import org.smartboot.flow.core.util.AuxiliaryUtils;
import org.w3c.dom.Element;
import java.util.ArrayList;
@@ -29,10 +30,10 @@ public class IfElementParser extends AbstractElementParser {
}
@Override
- public void parseElementInternal(Element element, ParserContext context) {
+ public void doParse(Element element, ParserContext context) {
String test = element.getAttribute(ParseConstants.TEST);
String ref = element.getAttribute(ParseConstants.REF);
- if (ElementUtils.isBlank(ref) && ElementUtils.isBlank(test)) {
+ if (AuxiliaryUtils.isBlank(ref) && AuxiliaryUtils.isBlank(test)) {
throw new IllegalArgumentException("attribute [ref] [type] cannot be null");
}
@@ -71,7 +72,7 @@ public class IfElementParser extends AbstractElementParser {
String type = subElement.getAttribute(ParseConstants.TYPE);
ref = subElement.getAttribute(ParseConstants.REF);
- if (ElementUtils.isNotBlank(type) || ElementUtils.isNotBlank(ref)) {
+ if (AuxiliaryUtils.isNotBlank(type) || AuxiliaryUtils.isNotBlank(ref)) {
continue;
}
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 c319117..64576f8 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
@@ -30,19 +30,18 @@ import java.util.Objects;
public class PipelineElementParser extends AbstractElementParser {
@Override
- public void parseElementInternal(Element element, ParserContext context) {
+ public void doParse(Element element, ParserContext context) {
PipelineDefinition definition = new PipelineDefinition();
- // identifier
- String identifier = context.getIdentifier(element);
- if (identifier == null && ElementUtils.isBlank(element.getAttribute(ParseConstants.NAME))) {
- throw new IllegalArgumentException("pipeline name must not be null");
- }
+ // pipeline name as identifier
+ String identifier = element.getAttribute(ParseConstants.NAME);
+ AssertUtil.notBlank(identifier, "pipeline name must not be null");
+ // Check has any elements.
List elements = ElementUtils.subElements(element);
AssertUtil.isTrue(elements.size() != 0, "[pipeline] element's sub elements must not be empty");
definition.setName(element.getAttribute(ParseConstants.NAME));
- definition.setIdentifier(super.getIdentifier(element, context));
+ definition.setIdentifier(identifier);
definition.getAttributes().addAll(ElementUtils.extraAttributes(element));
List subDefinitions = new ArrayList<>();
@@ -57,8 +56,8 @@ public class PipelineElementParser extends AbstractElementParser {
// nested subprocess
if (Objects.equals(subName, ParseConstants.PIPELINE)) {
PipelineComponentDefinition nestedWrap = new PipelineComponentDefinition();
- String nestedIdentifier = context.allocateIdentifier("pipelineComponent");
- nestedWrap.setName(ElementUtils.resolveName(sub, "pipelineComponent"));
+ 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);
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 5d51749..c6d6694 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
@@ -14,4 +14,12 @@ public final class AuxiliaryUtils {
public static String or(String t, String defaultValue) {
return t != null && t.trim().length() > 0 ? t : defaultValue;
}
+
+ public static boolean isBlank(String value) {
+ return value == null || value.trim().length() == 0;
+ }
+
+ public static boolean isNotBlank(String value) {
+ return !isBlank(value);
+ }
}
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 ee2f519..9602c7a 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
@@ -3,6 +3,7 @@ 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.util.AuxiliaryUtils;
import java.util.ArrayList;
import java.util.List;
@@ -23,7 +24,7 @@ public class PlantumlComponent {
private String condition;
private String branch;
private final List components = new ArrayList<>();
- private String wrapped;
+ private String executable;
public PlantumlComponent(String name, String describe) {
this.name = name;
@@ -90,16 +91,16 @@ public class PlantumlComponent {
this.components.add(component);
}
- public String getWrapped() {
- return wrapped;
+ public String getExecutable() {
+ return executable;
}
- public void setWrapped(String wrapped) {
- this.wrapped = wrapped;
+ public void setExecutable(String executable) {
+ this.executable = executable;
}
public void generate(StringBuilder content) {
- String nodeName = name == null ? describe : name;
+ String nodeName = AuxiliaryUtils.isBlank(name) ? describe : name;
if (getType() == ComponentType.BASIC) {
String serialAttributes = serialAttributes();
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 869699e..5eb8a41 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
@@ -60,6 +60,6 @@ public class PlantumlComponentVisitor extends ComponentVisitor {
@Override
public void visitExecutable(String executable) {
this.plantumlComponent.setType(ComponentType.BASIC);
- this.plantumlComponent.setWrapped(executable);
+ this.plantumlComponent.setExecutable(executable);
}
}
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 f7ad11b..e85745d 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,7 +3,6 @@ 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.parser.DefinitionVisitor;
-import org.smartboot.flow.core.parser.ElementUtils;
import org.smartboot.flow.core.parser.definition.ChooseDefinition;
import org.smartboot.flow.core.parser.definition.ElementDefinition;
import org.smartboot.flow.core.parser.definition.EngineDefinition;
@@ -11,6 +10,7 @@ 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 org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
@@ -108,7 +108,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor {
definition.setBeanClass(ed.resolveType());
definition.getPropertyValues().addPropertyValue(name);
- if (ElementUtils.isNotBlank(ed.getType()) && isType(ed.getType())) {
+ if (AuxiliaryUtils.isNotBlank(ed.getType()) && isType(ed.getType())) {
RootBeanDefinition conditionDef = new RootBeanDefinition();
conditionDef.setBeanClassName(ed.getType());
definition.getPropertyValues().add("executable", conditionDef);
@@ -138,7 +138,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor {
definition.setBeanClass(ed.resolveType());
definition.getPropertyValues().addPropertyValue(name);
- if (ElementUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) {
+ if (AuxiliaryUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) {
RootBeanDefinition conditionDef = new RootBeanDefinition();
conditionDef.setBeanClassName(ed.getTest());
definition.getPropertyValues().add("condition", conditionDef);
@@ -172,7 +172,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor {
definition.getPropertyValues().addPropertyValue(name);
definition.getPropertyValues().add("allBranchWasString", true);
- if (ElementUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) {
+ if (AuxiliaryUtils.isNotBlank(ed.getTest()) && isType(ed.getTest())) {
RootBeanDefinition conditionDef = new RootBeanDefinition();
conditionDef.setBeanClassName(ed.getTest());
definition.getPropertyValues().add("condition", conditionDef);
diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java
new file mode 100644
index 0000000..6f753bf
--- /dev/null
+++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java
@@ -0,0 +1,18 @@
+package org.smartboot.flow.spring.extension;
+
+import org.smartboot.flow.core.NamedCondition;
+import org.springframework.beans.factory.BeanNameAware;
+
+/**
+ * @author qinluo
+ * @date 2022-11-11 21:57:29
+ * @since 1.0.0
+ */
+public abstract class NameAwareCondition extends NamedCondition implements BeanNameAware {
+
+ @SuppressWarnings("NullableProblems")
+ @Override
+ public void setBeanName(String name) {
+ super.setName(name);
+ }
+}
diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java
index e36ab04..17783f5 100644
--- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java
+++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java
@@ -20,6 +20,6 @@ public abstract class NamedAbstractExecutable extends AbstractExecutable
+
+
+
+
+
+
--
Gitee
From a7683f0d9e688deb36f73fad7b0f6cd37c5b9506 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Tue, 22 Nov 2022 22:18:17 +0800
Subject: [PATCH 06/14] qinluo: - define new manage model.
---
.../flow/core/manager/ManagerAction.java | 25 +++++++++++++++++
.../manager/export/ExportedComponent.java | 28 +++++++++++++++++++
.../core/manager/export/ExportedEngine.java | 28 +++++++++++++++++++
.../core/manager/export/ExportedPipeline.java | 24 ++++++++++++++++
4 files changed, 105 insertions(+)
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
new file mode 100644
index 0000000..3ff16fa
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
@@ -0,0 +1,25 @@
+package org.smartboot.flow.core.manager;
+
+/**
+ * @author qinluo
+ * @date 2022/11/22 22:02
+ * @since 1.0.0
+ */
+public enum ManagerAction {
+ /**
+ * Change component attributes.
+ */
+ CHANGE_ATTRIBUTES,
+
+ /**
+ * Add a new component.
+ */
+ NEW_COMPONENT,
+
+ /**
+ * Reset statistic metrics.
+ */
+ RESET_METRICS,
+
+ ;
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
new file mode 100644
index 0000000..e41c95a
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
@@ -0,0 +1,28 @@
+package org.smartboot.flow.core.manager.export;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author qinluo
+ * @date 2022/11/22 22:15
+ * @since 1.0.0
+ */
+public class ExportedComponent implements Serializable {
+
+ private static final long serialVersionUID = -8140183209490928696L;
+
+ private final Map attributes = new ConcurrentHashMap<>();
+ private String name;
+ private String describe;
+ private final Map components = new ConcurrentHashMap<>();
+
+ private String executable;
+ // basic, if, choose, pipeline;
+ private String type;
+ // Used with type pipeline.
+ private ExportedPipeline pipeline;
+ private String condition;
+ private String branch;
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
new file mode 100644
index 0000000..5fa5f31
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
@@ -0,0 +1,28 @@
+package org.smartboot.flow.core.manager.export;
+
+import org.smartboot.flow.core.manager.ComponentModel;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author qinluo
+ * @date 2022/11/22 22:04
+ * @since 1.0.0
+ */
+public class ExportedEngine implements Serializable {
+ private static final long serialVersionUID = -4249807930225356740L;
+
+ private String name;
+ private ExportedPipeline pipeline;
+ private final Map components = new ConcurrentHashMap<>();
+
+ /*
+ * Metrics
+ */
+ private AtomicInteger executes;
+ private long maxExecuteMills;
+ private AtomicInteger totalExecuteMills;
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
new file mode 100644
index 0000000..b34fb03
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
@@ -0,0 +1,24 @@
+package org.smartboot.flow.core.manager.export;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author qinluo
+ * @date 2022/11/22 22:13
+ * @since 1.0.0
+ */
+public class ExportedPipeline implements Serializable {
+ private static final long serialVersionUID = 5375836760557921268L;
+
+ private String name;
+ private List components;
+
+ /*
+ * Metrics
+ */
+ private AtomicInteger executes;
+ private long maxExecuteMills;
+ private AtomicInteger totalExecuteMills;
+}
--
Gitee
From dc16e1911f67a39c104a1a087014fd8070755bef Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Wed, 23 Nov 2022 21:51:00 +0800
Subject: [PATCH 07/14] qinluo: - add reporter - add changer -
add metric
---
pom.xml | 1 +
.../flow/core/extension/ExtensionFactory.java | 39 ----------
.../core/manager/DefaultEngineManager.java | 11 +++
.../flow/core/manager/EngineManager.java | 14 ++++
.../manager/export/ExportedComponent.java | 28 -------
.../core/manager/export/ExportedEngine.java | 28 -------
.../core/manager/export/ExportedPipeline.java | 24 ------
.../smartboot/flow/core/metrics/Counter.java | 23 ++++++
.../flow/core/metrics/MaxCounter.java | 17 +++++
.../flow/core/metrics/MetricKind.java | 14 ++++
.../smartboot/flow/core/metrics/Metrics.java | 41 ++++++++++
.../core/parser/BuilderDefinitionVisitor.java | 6 +-
.../DefaultObjectCreator.java | 2 +-
.../flow/core/parser/DefaultParser.java | 6 +-
.../{extension => parser}/ObjectCreator.java | 2 +-
smart-flow-manager/pom.xml | 27 +++++++
.../flow/manager/change/ChangeModel.java | 40 ++++++++++
.../flow/manager/change/Changer.java | 16 ++++
.../flow/manager/report/AbstractReporter.java | 75 +++++++++++++++++++
.../flow/manager/report/HttpReporter.java | 44 +++++++++++
20 files changed, 332 insertions(+), 126 deletions(-)
delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
delete mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
rename smart-flow-core/src/main/java/org/smartboot/flow/core/{extension => parser}/DefaultObjectCreator.java (95%)
rename smart-flow-core/src/main/java/org/smartboot/flow/core/{extension => parser}/ObjectCreator.java (88%)
create mode 100644 smart-flow-manager/pom.xml
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/Changer.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java
diff --git a/pom.xml b/pom.xml
index cb8485f..8105af8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,6 +12,7 @@
smart-flow-core
smart-flow-spring-extension
+ smart-flow-manager
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
deleted file mode 100644
index a03bf84..0000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ExtensionFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.smartboot.flow.core.extension;
-
-import org.smartboot.flow.core.util.AssertUtil;
-
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author qinluo
- * @date 2022/11/19 14:23
- * @since 1.0.0
- */
-public class ExtensionFactory {
-
- /**
- * 默认扩展
- */
- private static final Map, Object> REGISTERED_DEFAULT = new ConcurrentHashMap<>();
-
- static {
- REGISTERED_DEFAULT.put(ObjectCreator.class, new DefaultObjectCreator());
- }
-
- /**
- * 获取扩展实现
- */
- @SuppressWarnings("unchecked")
- public static T getExtension(Class type) {
- AssertUtil.notNull(type, "type must not be null!");
-
- ServiceLoader loaded = ServiceLoader.load(type);
- if (!loaded.iterator().hasNext()) {
- return (T)REGISTERED_DEFAULT.get(type);
- }
-
- return loaded.iterator().next();
- }
-}
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 0607a78..5e3175a 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
@@ -6,6 +6,7 @@ import org.smartboot.flow.core.FlowEngine;
import org.smartboot.flow.core.component.AttributeHolder;
import org.smartboot.flow.core.util.AssertUtil;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -68,6 +69,16 @@ public class DefaultEngineManager implements EngineManager {
}
}
+ @Override
+ public List getRegisteredEngineNames() {
+ return new ArrayList<>(registeredEngines.keySet());
+ }
+
+ @Override
+ public void resetStatistic(String identifier) {
+
+ }
+
@Override
public void detachAll() {
this.registeredEngines.clear();
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 02bb830..92406ee 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
@@ -38,6 +38,13 @@ public interface EngineManager {
*/
void changeAttributes(String identifier, List attributeHolders);
+ /**
+ * Returns all registered engine's name.
+ *
+ * @return engine's names.
+ */
+ List getRegisteredEngineNames();
+
/**
* Dynamic change component attributes.
*
@@ -48,6 +55,13 @@ public interface EngineManager {
this.changeAttributes(identifier, Collections.singletonList(holder));
}
+ /**
+ * Reset statistic data.
+ *
+ * @param identifier component identifier
+ */
+ void resetStatistic(String identifier);
+
/**
* Make all engine detach from manager.
*/
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
deleted file mode 100644
index e41c95a..0000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedComponent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.smartboot.flow.core.manager.export;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author qinluo
- * @date 2022/11/22 22:15
- * @since 1.0.0
- */
-public class ExportedComponent implements Serializable {
-
- private static final long serialVersionUID = -8140183209490928696L;
-
- private final Map attributes = new ConcurrentHashMap<>();
- private String name;
- private String describe;
- private final Map components = new ConcurrentHashMap<>();
-
- private String executable;
- // basic, if, choose, pipeline;
- private String type;
- // Used with type pipeline.
- private ExportedPipeline pipeline;
- private String condition;
- private String branch;
-}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
deleted file mode 100644
index 5fa5f31..0000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedEngine.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.smartboot.flow.core.manager.export;
-
-import org.smartboot.flow.core.manager.ComponentModel;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author qinluo
- * @date 2022/11/22 22:04
- * @since 1.0.0
- */
-public class ExportedEngine implements Serializable {
- private static final long serialVersionUID = -4249807930225356740L;
-
- private String name;
- private ExportedPipeline pipeline;
- private final Map components = new ConcurrentHashMap<>();
-
- /*
- * Metrics
- */
- private AtomicInteger executes;
- private long maxExecuteMills;
- private AtomicInteger totalExecuteMills;
-}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
deleted file mode 100644
index b34fb03..0000000
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/export/ExportedPipeline.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.smartboot.flow.core.manager.export;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author qinluo
- * @date 2022/11/22 22:13
- * @since 1.0.0
- */
-public class ExportedPipeline implements Serializable {
- private static final long serialVersionUID = 5375836760557921268L;
-
- private String name;
- private List components;
-
- /*
- * Metrics
- */
- private AtomicInteger executes;
- private long maxExecuteMills;
- private AtomicInteger totalExecuteMills;
-}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java
new file mode 100644
index 0000000..b2c27b4
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java
@@ -0,0 +1,23 @@
+package org.smartboot.flow.core.metrics;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Count some metrics.
+ *
+ * @author qinluo
+ * @date 2022/11/23 21:35
+ * @since 1.0.0
+ */
+public class Counter {
+
+ protected final AtomicLong sum = new AtomicLong();
+
+ public void increment(long value) {
+ sum.addAndGet(value);
+ }
+
+ public long get() {
+ return sum.get();
+ }
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java
new file mode 100644
index 0000000..e4bded0
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java
@@ -0,0 +1,17 @@
+package org.smartboot.flow.core.metrics;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 21:41
+ * @since 1.0.0
+ */
+public class MaxCounter extends Counter {
+
+ @Override
+ public void increment(long value) {
+ while (sum.get() < value) {
+ sum.compareAndSet(sum.get(), value);
+ }
+
+ }
+}
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
new file mode 100644
index 0000000..e779d07
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricKind.java
@@ -0,0 +1,14 @@
+package org.smartboot.flow.core.metrics;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 21:45
+ * @since 1.0.0
+ */
+public enum MetricKind {
+
+ ACCUMULATE,
+
+ MAX,
+ ;
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
new file mode 100644
index 0000000..fb379d3
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
@@ -0,0 +1,41 @@
+package org.smartboot.flow.core.metrics;
+
+import org.smartboot.flow.core.util.AssertUtil;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 21:35
+ * @since 1.0.0
+ */
+public class Metrics {
+
+ private final Map COUNTERS = new ConcurrentHashMap<>();
+
+ public void addMetric(String name, long value) {
+ this.addMetric(MetricKind.ACCUMULATE, name, value);
+ }
+
+ public void addMetric(MetricKind kind, String name, long value) {
+ AssertUtil.notNull(name, "metric name must not be null");
+ AssertUtil.notNull(kind, "metric kind must not be null");
+
+ Counter counter = COUNTERS.computeIfAbsent(name, k -> createCounter(kind));
+ counter.increment(value);
+ }
+
+ public Map getMetrics() {
+ return Collections.unmodifiableMap(COUNTERS);
+ }
+
+ private Counter createCounter(MetricKind kind) {
+ if (kind == MetricKind.MAX) {
+ return new MaxCounter();
+ }
+
+ return new Counter();
+ }
+}
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 608796e..c8521b6 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,8 +11,6 @@ import org.smartboot.flow.core.builder.PipelineBuilder;
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.extension.ExtensionFactory;
-import org.smartboot.flow.core.extension.ObjectCreator;
import org.smartboot.flow.core.parser.definition.ChooseDefinition;
import org.smartboot.flow.core.parser.definition.ElementDefinition;
import org.smartboot.flow.core.parser.definition.EngineDefinition;
@@ -40,9 +38,9 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor {
private final ObjectCreator objectCreator;
private final boolean useCache;
- public BuilderDefinitionVisitor(boolean useCache) {
+ public BuilderDefinitionVisitor(boolean useCache, ObjectCreator objectCreator) {
this.useCache = useCache;
- objectCreator = ExtensionFactory.getExtension(ObjectCreator.class);
+ this.objectCreator = objectCreator;
}
@Override
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/DefaultObjectCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java
similarity index 95%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/extension/DefaultObjectCreator.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java
index a67db12..67df7a5 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/DefaultObjectCreator.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/DefaultObjectCreator.java
@@ -1,4 +1,4 @@
-package org.smartboot.flow.core.extension;
+package org.smartboot.flow.core.parser;
import org.smartboot.flow.core.util.AssertUtil;
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 64ce5e7..1af113a 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
@@ -64,7 +64,7 @@ public class DefaultParser implements Parser {
useCache = useCache || Boolean.parseBoolean(root.getAttribute("useCache"));
}
- this.visitor = new BuilderDefinitionVisitor(useCache);
+ this.visitor = new BuilderDefinitionVisitor(useCache, getObjectCreator());
context.getRegistered().forEach(ElementDefinition::validate);
context.getRegistered().forEach(p -> visitor.visit(p));
}
@@ -95,6 +95,10 @@ public class DefaultParser implements Parser {
this.parse(fstream, streams);
}
+ protected ObjectCreator getObjectCreator() {
+ return new DefaultObjectCreator();
+ }
+
public FlowEngine getEngine(String name) {
return visitor.getEngine(name);
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ObjectCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java
similarity index 88%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ObjectCreator.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java
index a038456..28c0550 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/extension/ObjectCreator.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ObjectCreator.java
@@ -1,4 +1,4 @@
-package org.smartboot.flow.core.extension;
+package org.smartboot.flow.core.parser;
/**
* @author qinluo
diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml
new file mode 100644
index 0000000..0aae888
--- /dev/null
+++ b/smart-flow-manager/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ flow-engine
+ org.smartboot
+ 1.0.0
+
+ 4.0.0
+
+ smart-flow-manager
+
+
+ 8
+ 8
+
+
+
+
+ org.smartboot
+ smart-flow-core
+ 1.0.0
+
+
+
+
\ No newline at end of file
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
new file mode 100644
index 0000000..ad3c3f3
--- /dev/null
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/ChangeModel.java
@@ -0,0 +1,40 @@
+package org.smartboot.flow.manager.change;
+
+import java.io.Serializable;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 21:29
+ * @since 1.0.0
+ */
+public class ChangeModel implements Serializable {
+ private static final long serialVersionUID = -3610942087085947434L;
+
+ /**
+ * Change action
+ *
+ * @see org.smartboot.flow.core.manager.ManagerAction
+ */
+ private String action;
+
+ /**
+ * Change value json.
+ */
+ private String value;
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/Changer.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/Changer.java
new file mode 100644
index 0000000..1710ebd
--- /dev/null
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/Changer.java
@@ -0,0 +1,16 @@
+package org.smartboot.flow.manager.change;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 20:57
+ * @since 1.0.0
+ */
+public interface Changer {
+
+ /**
+ *
+ * @param identifier identifier of components.
+ * @param model changed value.
+ */
+ void change(String identifier, ChangeModel model);
+}
diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
new file mode 100644
index 0000000..ffb2791
--- /dev/null
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
@@ -0,0 +1,75 @@
+package org.smartboot.flow.manager.report;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.smartboot.flow.core.manager.DefaultEngineManager;
+import org.smartboot.flow.core.manager.EngineManager;
+import org.smartboot.flow.core.manager.EngineModel;
+
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 20:35
+ * @since 1.0.0
+ */
+public abstract class AbstractReporter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractReporter.class);
+ private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
+
+ private final AtomicInteger sequence = new AtomicInteger(0);
+ @Override
+ public Thread newThread(Runnable r) {
+ if (r instanceof Thread) {
+ ((Thread) r).setName("export-thread-" + sequence.addAndGet(1));
+ return (Thread) r;
+ }
+
+ Thread t = new Thread(r);
+ t.setName("export-thread-" + sequence.addAndGet(1));
+ return t;
+ }
+ });
+
+ /**
+ * Report idle in mills.
+ */
+ protected long reportIdle;
+
+ final void export() {
+ EngineManager defaultManager = DefaultEngineManager.getDefaultManager();
+ List registeredEngineNames = defaultManager.getRegisteredEngineNames();
+
+ try {
+ for (String name : registeredEngineNames) {
+ this.doExport(defaultManager.getEngineModel(name));
+ }
+ } catch (Exception e) {
+ LOGGER.error("{} export engine model failed.", getClass().getName(), e);
+ } finally {
+ executorService.schedule(this::export, reportIdle, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ /**
+ * Start to export data.
+ */
+ public void start() {
+ this.export();
+ }
+
+
+ /**
+ * Export engine model
+ *
+ * @param model engine model.
+ */
+ public abstract void doExport(EngineModel model);
+
+}
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
new file mode 100644
index 0000000..210cde7
--- /dev/null
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReporter.java
@@ -0,0 +1,44 @@
+package org.smartboot.flow.manager.report;
+
+import org.smartboot.flow.core.manager.EngineModel;
+
+/**
+ * @author qinluo
+ * @date 2022/11/23 20:47
+ * @since 1.0.0
+ */
+public class HttpReporter extends AbstractReporter {
+
+ private String url;
+ private int port;
+ private long timeout;
+
+ @Override
+ public void doExport(EngineModel model) {
+ // httpclient.httpPostTimeout
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public long getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+}
--
Gitee
From c82d2a93db3cac4414fdadaf555eb65d31437b28 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Thu, 24 Nov 2022 17:50:16 +0800
Subject: [PATCH 08/14] qinluo: - report
---
pom.xml | 7 +-
smart-flow-example/pom.xml | 47 +++++++++++
.../flow/example/extension/AsyncStep1.java | 19 +++++
.../flow/example/extension/AsyncStep2.java | 23 ++++++
.../flow/example/extension/AsyncStep3.java | 23 ++++++
.../example/extension/ChooseCondition.java | 26 ++++++
.../flow/example/extension/DefaultStep.java | 19 +++++
.../flow/example/extension/ElseStep.java | 19 +++++
.../flow/example/extension/ErrorStep.java | 19 +++++
.../flow/example/extension/IfCondition.java | 19 +++++
.../flow/example/extension/IfCondition2.java | 19 +++++
.../flow/example/extension/IfCondition3.java | 19 +++++
.../flow/example/extension/IntegerStep.java | 19 +++++
.../flow/example/extension/NullStep.java | 19 +++++
.../flow/example/extension/Step1.java | 17 ++++
.../flow/example/extension/Step2.java | 17 ++++
.../flow/example/extension/Step3.java | 19 +++++
.../flow/example/extension/Step4.java | 19 +++++
.../flow/example/extension/Step5.java | 19 +++++
.../flow/example/extension/Step6.java | 19 +++++
.../src/main/resources/bean.xml | 60 ++++++++++++++
.../src/main/resources/log4j.properties | 59 +++++++++++++
.../src/main/resources/log4j2.properties | 6 ++
.../main/resources/log4jdbc.log4j2.properties | 2 +
.../src/main/resources/logback.xml | 37 +++++++++
.../org/smartboot/flow/example/ParseTest.java | 38 +++++++++
smart-flow-manager/pom.xml | 12 +++
.../flow/manager/report/AbstractReporter.java | 12 ++-
.../flow/manager/report/HttpReporter.java | 82 ++++++++++++++++---
29 files changed, 697 insertions(+), 18 deletions(-)
create mode 100644 smart-flow-example/pom.xml
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep1.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java
create mode 100644 smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java
create mode 100644 smart-flow-example/src/main/resources/bean.xml
create mode 100644 smart-flow-example/src/main/resources/log4j.properties
create mode 100644 smart-flow-example/src/main/resources/log4j2.properties
create mode 100644 smart-flow-example/src/main/resources/log4jdbc.log4j2.properties
create mode 100644 smart-flow-example/src/main/resources/logback.xml
create mode 100644 smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java
diff --git a/pom.xml b/pom.xml
index 8105af8..101b7fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,15 +13,10 @@
smart-flow-core
smart-flow-spring-extension
smart-flow-manager
+ smart-flow-example
-
- com.google.guava
- guava
- 31.1-jre
-
-
org.slf4j
diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml
new file mode 100644
index 0000000..0a59967
--- /dev/null
+++ b/smart-flow-example/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+ flow-engine
+ org.smartboot
+ 1.0.0
+
+ 4.0.0
+
+ smart-flow-example
+
+
+ 8
+ 8
+
+
+
+
+ org.smartboot
+ smart-flow-manager
+ 1.0.0
+
+
+
+ org.smartboot
+ smart-flow-spring-extension
+ 1.0.0
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.9.1
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.1
+ test
+
+
+
+
\ No newline at end of file
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/extension/AsyncStep1.java
new file mode 100644
index 0000000..67645c0
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep1.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/AsyncStep2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java
new file mode 100644
index 0000000..8bff547
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep2.java
@@ -0,0 +1,23 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/AsyncStep3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java
new file mode 100644
index 0000000..f326a1d
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/AsyncStep3.java
@@ -0,0 +1,23 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/ChooseCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java
new file mode 100644
index 0000000..0bba277
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ChooseCondition.java
@@ -0,0 +1,26 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/DefaultStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java
new file mode 100644
index 0000000..679f1a7
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/DefaultStep.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/ElseStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java
new file mode 100644
index 0000000..22d4295
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ElseStep.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/ErrorStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java
new file mode 100644
index 0000000..f0b97fe
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/ErrorStep.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+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/extension/IfCondition.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java
new file mode 100644
index 0000000..99b01b2
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/IfCondition2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java
new file mode 100644
index 0000000..4533495
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition2.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/IfCondition3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java
new file mode 100644
index 0000000..1fb61d9
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IfCondition3.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/IntegerStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java
new file mode 100644
index 0000000..54dbeb4
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/IntegerStep.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/NullStep.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java
new file mode 100644
index 0000000..3eb7704
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/NullStep.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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) {
+ System.out.println(getClass());
+ }
+}
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
new file mode 100644
index 0000000..a0ff762
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step1.java
@@ -0,0 +1,17 @@
+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/java/org/smartboot/flow/example/extension/Step2.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java
new file mode 100644
index 0000000..0fa36eb
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step2.java
@@ -0,0 +1,17 @@
+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 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/extension/Step3.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java
new file mode 100644
index 0000000..5c1a1da
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step3.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/Step4.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java
new file mode 100644
index 0000000..d343a89
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step4.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/Step5.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java
new file mode 100644
index 0000000..3cd8014
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step5.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/extension/Step6.java b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java
new file mode 100644
index 0000000..54b3661
--- /dev/null
+++ b/smart-flow-example/src/main/java/org/smartboot/flow/example/extension/Step6.java
@@ -0,0 +1,19 @@
+package org.smartboot.flow.example.extension;
+
+
+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/bean.xml b/smart-flow-example/src/main/resources/bean.xml
new file mode 100644
index 0000000..19f91f0
--- /dev/null
+++ b/smart-flow-example/src/main/resources/bean.xml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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
new file mode 100644
index 0000000..05ad41f
--- /dev/null
+++ b/smart-flow-example/src/main/resources/log4j.properties
@@ -0,0 +1,59 @@
+### 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-example/src/main/resources/log4j2.properties b/smart-flow-example/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..fced116
--- /dev/null
+++ b/smart-flow-example/src/main/resources/log4j2.properties
@@ -0,0 +1,6 @@
+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-example/src/main/resources/log4jdbc.log4j2.properties b/smart-flow-example/src/main/resources/log4jdbc.log4j2.properties
new file mode 100644
index 0000000..76f2440
--- /dev/null
+++ b/smart-flow-example/src/main/resources/log4jdbc.log4j2.properties
@@ -0,0 +1,2 @@
+#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/logback.xml b/smart-flow-example/src/main/resources/logback.xml
new file mode 100644
index 0000000..347cb45
--- /dev/null
+++ b/smart-flow-example/src/main/resources/logback.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} [%file:%line] - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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
new file mode 100644
index 0000000..9f01709
--- /dev/null
+++ b/smart-flow-example/src/test/java/org/smartboot/flow/example/ParseTest.java
@@ -0,0 +1,38 @@
+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.view.plantuml.PlantumlEngineVisitor;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @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());
+
+ PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow3");
+ visitor.visit(testEngine);
+
+
+ Thread.sleep(60000);
+ }
+}
diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml
index 0aae888..84bf720 100644
--- a/smart-flow-manager/pom.xml
+++ b/smart-flow-manager/pom.xml
@@ -22,6 +22,18 @@
smart-flow-core
1.0.0
+
+
+ org.smartboot.http
+ smart-http-client
+ 1.1.17
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.70
+
\ No newline at end of file
diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
index ffb2791..5ba43d4 100644
--- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/AbstractReporter.java
@@ -40,7 +40,15 @@ public abstract class AbstractReporter {
/**
* Report idle in mills.
*/
- protected long reportIdle;
+ protected long idle;
+
+ public long getIdle() {
+ return idle;
+ }
+
+ public void setIdle(long idle) {
+ this.idle = idle;
+ }
final void export() {
EngineManager defaultManager = DefaultEngineManager.getDefaultManager();
@@ -53,7 +61,7 @@ public abstract class AbstractReporter {
} catch (Exception e) {
LOGGER.error("{} export engine model failed.", getClass().getName(), e);
} finally {
- executorService.schedule(this::export, reportIdle, TimeUnit.MILLISECONDS);
+ executorService.schedule(this::export, idle, TimeUnit.MILLISECONDS);
}
}
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 210cde7..4351e56 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,19 @@
package org.smartboot.flow.manager.report;
+import com.alibaba.fastjson.JSON;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.smartboot.flow.core.manager.EngineModel;
+import org.smartboot.flow.core.util.AssertUtil;
+import org.smartboot.http.client.HttpClient;
+import org.smartboot.http.client.HttpPost;
+import org.smartboot.http.client.HttpResponse;
+import org.smartboot.http.common.enums.HeaderNameEnum;
+
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.function.Consumer;
/**
* @author qinluo
@@ -9,29 +22,70 @@ import org.smartboot.flow.core.manager.EngineModel;
*/
public class HttpReporter extends AbstractReporter {
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpReporter.class);
+
private String url;
- private int port;
private long timeout;
+ private URL parsedUrl;
+ private Map headers;
+ private HttpClient httpClient;
+ private boolean validate;
+
+ @Override
+ public void start() {
+ try {
+ this.parsedUrl = new URL(url);
+ } catch (Exception e) {
+ throw new IllegalStateException("invalid url " + url, e);
+ }
+
+ super.start();
+ }
@Override
public void doExport(EngineModel model) {
- // httpclient.httpPostTimeout
+ AssertUtil.notNull(parsedUrl, "url is invalid.");
+ httpClient = new HttpClient(parsedUrl.getHost(), parsedUrl.getPort());
+ httpClient.connect();
+ httpClient.timeout((int)timeout);
+ HttpPost post = httpClient.post(parsedUrl.getPath());
+
+ if (headers != null) {
+ headers.forEach(post::addHeader);
+ }
+
+ String values = JSON.toJSONString(model);
+ byte[] bytes = values.getBytes(StandardCharsets.UTF_8);
+
+ post.addHeader(HeaderNameEnum.CONTENT_TYPE.getName(), "application/json;charset=UTF-8");
+ post.addHeader(HeaderNameEnum.CONTENT_LENGTH.getName(), String.valueOf(bytes.length));
+
+ // Use body stream write.
+ post.bodyStream().write(bytes, 0, bytes.length);
+ post.bodyStream().flush();
+ post.onSuccess(httpResponse -> {
+ LOGGER.info("send success");
+ }).onFailure(throwable -> {
+ LOGGER.info("send failed", throwable);
+ });
+
+ post.send();
}
- public String getUrl() {
- return url;
+ public Map getHeaders() {
+ return headers;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setHeaders(Map headers) {
+ this.headers = headers;
}
- public int getPort() {
- return port;
+ public String getUrl() {
+ return url;
}
- public void setPort(int port) {
- this.port = port;
+ public void setUrl(String url) {
+ this.url = url;
}
public long getTimeout() {
@@ -41,4 +95,12 @@ public class HttpReporter extends AbstractReporter {
public void setTimeout(long timeout) {
this.timeout = timeout;
}
+
+ public boolean getValidate() {
+ return validate;
+ }
+
+ public void setValidate(boolean validate) {
+ this.validate = validate;
+ }
}
--
Gitee
From 2c089faac2dd1e78da4d9170fac5fbd233a7c4bf Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Thu, 24 Nov 2022 18:53:13 +0800
Subject: [PATCH 09/14] qinluo: - reporter
---
.../flow/core/manager/ComponentModel.java | 11 +++++--
.../flow/core/manager/EngineModel.java | 5 ++--
.../flow/core/manager/PipelineModel.java | 19 +++++++-----
.../flow/manager/report/HttpReporter.java | 29 +++++++------------
4 files changed, 32 insertions(+), 32 deletions(-)
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 6118e81..defe9e0 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
@@ -71,16 +71,21 @@ public class ComponentModel extends Uniqueness {
}
public Map getComponents() {
+ return new HashMap<>(components);
+ }
+
+ Map collect() {
if (type == ComponentType.PIPELINE) {
- this.pipeline.collect();
- return pipeline.getComponents();
+ Map collected = this.pipeline.collect();
+ collected.put(this.identifier, this);
+ return collected;
} else if (type == ComponentType.BASIC) {
Map temp = new HashMap<>();
temp.put(this.identifier, this);
return temp;
} else {
Map temp = new HashMap<>();
- this.components.forEach((k, v) -> temp.putAll(v.getComponents()));
+ this.components.forEach((k, v) -> temp.putAll(v.collect()));
temp.put(this.identifier, this);
return temp;
}
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 88febc2..16db366 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
@@ -20,7 +20,7 @@ public class EngineModel extends Uniqueness {
private static final Logger LOGGER = LoggerFactory.getLogger(EngineModel.class);
private PipelineModel pipeline;
- private final Map components = new ConcurrentHashMap<>();
+ private transient final Map components = new ConcurrentHashMap<>();
public EngineModel(String name) {
// Engine's name must be global unique.
@@ -54,7 +54,6 @@ public class EngineModel extends Uniqueness {
}
void collect() {
- this.pipeline.collect();
- this.components.putAll(this.pipeline.getComponents());
+ this.components.putAll(this.pipeline.collect());
}
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
index 1212261..76a230b 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
@@ -2,7 +2,9 @@ package org.smartboot.flow.core.manager;
import org.smartboot.flow.core.common.Uniqueness;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -13,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class PipelineModel extends Uniqueness {
- private final Map components = new ConcurrentHashMap<>();
+ private final List components = new ArrayList<>();
private final String name;
PipelineModel(String name, String identifier) {
@@ -21,21 +23,24 @@ public class PipelineModel extends Uniqueness {
this.identifier = identifier;
}
- public Map getComponents() {
- return new HashMap<>(components);
+ public List getComponents() {
+ return new ArrayList<>(components);
}
void addComponent(ComponentModel component) {
- this.components.put(component.getIdentifier(), component);
+ this.components.add(component);
}
public String getName() {
return name;
}
- void collect() {
- for (ComponentModel model : components.values()) {
- this.components.putAll(model.getComponents());
+ Map collect() {
+ HashMap collected = new HashMap<>(components.size());
+ for (ComponentModel model : components) {
+ collected.putAll(model.collect());
}
+
+ return collected;
}
}
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 4351e56..4e6ccf7 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
@@ -7,13 +7,11 @@ import org.smartboot.flow.core.manager.EngineModel;
import org.smartboot.flow.core.util.AssertUtil;
import org.smartboot.http.client.HttpClient;
import org.smartboot.http.client.HttpPost;
-import org.smartboot.http.client.HttpResponse;
import org.smartboot.http.common.enums.HeaderNameEnum;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
-import java.util.function.Consumer;
/**
* @author qinluo
@@ -28,8 +26,6 @@ public class HttpReporter extends AbstractReporter {
private long timeout;
private URL parsedUrl;
private Map headers;
- private HttpClient httpClient;
- private boolean validate;
@Override
public void start() {
@@ -45,10 +41,16 @@ public class HttpReporter extends AbstractReporter {
@Override
public void doExport(EngineModel model) {
AssertUtil.notNull(parsedUrl, "url is invalid.");
- httpClient = new HttpClient(parsedUrl.getHost(), parsedUrl.getPort());
+
+ String path = parsedUrl.getPath();
+ if (parsedUrl.getQuery() != null) {
+ path = path + "?" + parsedUrl.getQuery();
+ }
+
+ HttpClient httpClient = new HttpClient(parsedUrl.getHost(), parsedUrl.getPort());
httpClient.connect();
httpClient.timeout((int)timeout);
- HttpPost post = httpClient.post(parsedUrl.getPath());
+ HttpPost post = httpClient.post(path);
if (headers != null) {
headers.forEach(post::addHeader);
@@ -63,11 +65,8 @@ public class HttpReporter extends AbstractReporter {
// Use body stream write.
post.bodyStream().write(bytes, 0, bytes.length);
post.bodyStream().flush();
- post.onSuccess(httpResponse -> {
- LOGGER.info("send success");
- }).onFailure(throwable -> {
- LOGGER.info("send failed", throwable);
- });
+ post.onSuccess(httpResponse -> LOGGER.info("send statistic success, engine: {}", model.getIdentifier()))
+ .onFailure(throwable -> LOGGER.info("send statistic failed, engine: {}", model.getIdentifier(), throwable));
post.send();
}
@@ -95,12 +94,4 @@ public class HttpReporter extends AbstractReporter {
public void setTimeout(long timeout) {
this.timeout = timeout;
}
-
- public boolean getValidate() {
- return validate;
- }
-
- public void setValidate(boolean validate) {
- this.validate = validate;
- }
}
--
Gitee
From ba85f566d1b0b39c4d8a1ebe924410fd8fdb8abe Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Thu, 24 Nov 2022 19:59:28 +0800
Subject: [PATCH 10/14] qinluo: - optimized model. - remove
test-classes
---
.../flow/core/manager/ComponentModel.java | 15 ++++-
.../manager/RegisteredComponentVisitor.java | 7 ++-
.../flow/spring/extension/AsyncStep1.java | 19 ------
.../flow/spring/extension/AsyncStep2.java | 23 --------
.../flow/spring/extension/AsyncStep3.java | 23 --------
.../spring/extension/ChooseCondition.java | 26 --------
.../flow/spring/extension/DefaultStep.java | 19 ------
.../flow/spring/extension/ElseStep.java | 19 ------
.../flow/spring/extension/ErrorStep.java | 19 ------
.../flow/spring/extension/IfCondition.java | 19 ------
.../flow/spring/extension/IfCondition2.java | 19 ------
.../flow/spring/extension/IfCondition3.java | 19 ------
.../flow/spring/extension/IntegerStep.java | 19 ------
.../flow/spring/extension/NullStep.java | 19 ------
.../flow/spring/extension/ParseTest.java | 35 -----------
.../flow/spring/extension/Step1.java | 17 ------
.../flow/spring/extension/Step2.java | 17 ------
.../flow/spring/extension/Step3.java | 19 ------
.../flow/spring/extension/Step4.java | 19 ------
.../flow/spring/extension/Step5.java | 19 ------
.../flow/spring/extension/Step6.java | 19 ------
.../src/test/resources/bean.xml | 54 -----------------
.../src/test/resources/log4j.properties | 59 -------------------
.../src/test/resources/log4j2.properties | 6 --
.../test/resources/log4jdbc.log4j2.properties | 2 -
.../src/test/resources/logback.xml | 37 ------------
26 files changed, 18 insertions(+), 550 deletions(-)
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep1.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep2.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep3.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ChooseCondition.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/DefaultStep.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ElseStep.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ErrorStep.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition2.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition3.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IntegerStep.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/NullStep.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ParseTest.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step1.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step2.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step3.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step4.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step5.java
delete mode 100644 smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step6.java
delete mode 100644 smart-flow-spring-extension/src/test/resources/bean.xml
delete mode 100644 smart-flow-spring-extension/src/test/resources/log4j.properties
delete mode 100644 smart-flow-spring-extension/src/test/resources/log4j2.properties
delete mode 100644 smart-flow-spring-extension/src/test/resources/log4jdbc.log4j2.properties
delete mode 100644 smart-flow-spring-extension/src/test/resources/logback.xml
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 defe9e0..4db3a24 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
@@ -31,7 +31,7 @@ public class ComponentModel extends Uniqueness {
// Used with type pipeline.
PipelineModel pipeline;
String condition;
- String branch;
+ private String branch;
ComponentModel(String identifier, Component component) {
this.identifier = identifier;
@@ -70,6 +70,10 @@ public class ComponentModel extends Uniqueness {
return branch;
}
+ public void setBranch(String branch) {
+ this.branch = branch;
+ }
+
public Map getComponents() {
return new HashMap<>(components);
}
@@ -92,7 +96,14 @@ public class ComponentModel extends Uniqueness {
}
void addComponent(ComponentModel model) {
- this.components.put(model.getIdentifier(), model);
+ if (this.type == ComponentType.CHOOSE) {
+ this.components.put(model.getBranch(), model);
+ } else if (this.type == ComponentType.IF) {
+ String key = this.components.size() > 0 ? "else" : "then";
+ this.components.put(key, model);
+ } else {
+ this.components.put(model.getIdentifier(), model);
+ }
}
public String getName() {
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 25e1589..a5b5dea 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
@@ -41,11 +41,14 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
@Override
public ComponentVisitor visitComponent(Component component) {
String identifier = ContactUtils.contact(model.getIdentifier(), AuxiliaryUtils.or(component.getName(), component.describe()));
+ String branch = null;
if (this.model.type == ComponentType.CHOOSE) {
identifier = ContactUtils.contact(model.getIdentifier(), "default");
+ branch = "default";
}
ComponentModel comp = new ComponentModel(identifier, component);
+ comp.setBranch(branch);
this.model.addComponent(comp);
return new RegisteredComponentVisitor(comp);
}
@@ -58,9 +61,9 @@ 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);
- model.branch = (String.valueOf(branch));
- this.model.addComponent(model);
+ model.setBranch((String.valueOf(branch)));
this.model.type = (ComponentType.CHOOSE);
+ this.model.addComponent(model);
return new RegisteredComponentVisitor(model);
}
diff --git a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep1.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep1.java
deleted file mode 100644
index e99b3b3..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep1.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep2.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep2.java
deleted file mode 100644
index dfe3704..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep2.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep3.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep3.java
deleted file mode 100644
index 8043017..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/AsyncStep3.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ChooseCondition.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ChooseCondition.java
deleted file mode 100644
index 521f06b..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ChooseCondition.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/DefaultStep.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/DefaultStep.java
deleted file mode 100644
index aebfe7c..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/DefaultStep.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ElseStep.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ElseStep.java
deleted file mode 100644
index cfb95e3..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ElseStep.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ErrorStep.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ErrorStep.java
deleted file mode 100644
index e259f8e..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ErrorStep.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition.java
deleted file mode 100644
index 2a0be94..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition2.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition2.java
deleted file mode 100644
index 02020f6..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition2.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition3.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition3.java
deleted file mode 100644
index edf5695..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IfCondition3.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IntegerStep.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IntegerStep.java
deleted file mode 100644
index 1e2223e..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/IntegerStep.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/NullStep.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/NullStep.java
deleted file mode 100644
index 6c17815..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/NullStep.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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) {
- System.out.println(getClass());
- }
-}
diff --git a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ParseTest.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ParseTest.java
deleted file mode 100644
index 623c891..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/ParseTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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.view.plantuml.PlantumlEngineVisitor;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-/**
- * @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() {
- 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());
-
- PlantumlEngineVisitor visitor = new PlantumlEngineVisitor("engine-flow3");
- visitor.visit(testEngine);
- }
-}
diff --git a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step1.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step1.java
deleted file mode 100644
index 70a31cc..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step1.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.smartboot.flow.spring.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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step2.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step2.java
deleted file mode 100644
index 2e450dd..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step2.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step3.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step3.java
deleted file mode 100644
index b479de4..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step3.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step4.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step4.java
deleted file mode 100644
index 53f6af0..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step4.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step5.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step5.java
deleted file mode 100644
index c41c06f..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step5.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step6.java b/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step6.java
deleted file mode 100644
index 1e51c81..0000000
--- a/smart-flow-spring-extension/src/test/java/org/smartboot/flow/spring/extension/Step6.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.smartboot.flow.spring.extension;
-
-
-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-spring-extension/src/test/resources/bean.xml b/smart-flow-spring-extension/src/test/resources/bean.xml
deleted file mode 100644
index 004398b..0000000
--- a/smart-flow-spring-extension/src/test/resources/bean.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/smart-flow-spring-extension/src/test/resources/log4j.properties b/smart-flow-spring-extension/src/test/resources/log4j.properties
deleted file mode 100644
index 05ad41f..0000000
--- a/smart-flow-spring-extension/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-spring-extension/src/test/resources/log4j2.properties b/smart-flow-spring-extension/src/test/resources/log4j2.properties
deleted file mode 100644
index fced116..0000000
--- a/smart-flow-spring-extension/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-spring-extension/src/test/resources/log4jdbc.log4j2.properties b/smart-flow-spring-extension/src/test/resources/log4jdbc.log4j2.properties
deleted file mode 100644
index 76f2440..0000000
--- a/smart-flow-spring-extension/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-spring-extension/src/test/resources/logback.xml b/smart-flow-spring-extension/src/test/resources/logback.xml
deleted file mode 100644
index 347cb45..0000000
--- a/smart-flow-spring-extension/src/test/resources/logback.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} [%file:%line] - %msg%n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
Gitee
From a83b9c973456f66a10174ad78b59f0be83078535 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Thu, 24 Nov 2022 20:02:12 +0800
Subject: [PATCH 11/14] qinluo: - optimized counter
---
.../org/smartboot/flow/core/metrics/Metrics.java | 2 ++
.../flow/core/metrics/{ => counter}/Counter.java | 10 +++++-----
.../core/metrics/{ => counter}/MaxCounter.java | 15 ++++++++++++---
3 files changed, 19 insertions(+), 8 deletions(-)
rename smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/{ => counter}/Counter.java (50%)
rename smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/{ => counter}/MaxCounter.java (36%)
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
index fb379d3..48b05ed 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Metrics.java
@@ -1,5 +1,7 @@
package org.smartboot.flow.core.metrics;
+import org.smartboot.flow.core.metrics.counter.Counter;
+import org.smartboot.flow.core.metrics.counter.MaxCounter;
import org.smartboot.flow.core.util.AssertUtil;
import java.util.Collections;
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/Counter.java
similarity index 50%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/Counter.java
index b2c27b4..4d0fa1d 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/Counter.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/Counter.java
@@ -1,6 +1,6 @@
-package org.smartboot.flow.core.metrics;
+package org.smartboot.flow.core.metrics.counter;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
/**
* Count some metrics.
@@ -11,13 +11,13 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class Counter {
- protected final AtomicLong sum = new AtomicLong();
+ protected final LongAdder sum = new LongAdder();
public void increment(long value) {
- sum.addAndGet(value);
+ sum.add(value);
}
public long get() {
- return sum.get();
+ return sum.sum();
}
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/MaxCounter.java
similarity index 36%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/MaxCounter.java
index e4bded0..ce15a56 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MaxCounter.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/counter/MaxCounter.java
@@ -1,4 +1,6 @@
-package org.smartboot.flow.core.metrics;
+package org.smartboot.flow.core.metrics.counter;
+
+import java.util.concurrent.atomic.AtomicLong;
/**
* @author qinluo
@@ -7,11 +9,18 @@ package org.smartboot.flow.core.metrics;
*/
public class MaxCounter extends Counter {
+ private final AtomicLong counter = new AtomicLong();
+
@Override
public void increment(long value) {
- while (sum.get() < value) {
- sum.compareAndSet(sum.get(), value);
+ while (counter.get() < value) {
+ counter.compareAndSet(counter.get(), value);
}
}
+
+ @Override
+ public long get() {
+ return counter.get();
+ }
}
--
Gitee
From b3e06a8ef069248f3f1600ae85efc1dff54cc186 Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Sat, 26 Nov 2022 01:56:56 +0800
Subject: [PATCH 12/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E4=BC=98?=
=?UTF-8?q?=E5=8C=96reporter=E6=A8=A1=E5=9E=8B=20=20=20=20=20=20-=20?=
=?UTF-8?q?=E6=96=B0=E5=A2=9EhttpManager=EF=BC=8C=E4=BD=BF=E7=94=A8?=
=?UTF-8?q?=E6=8B=89=E6=A8=A1=E5=9E=8B=E8=8E=B7=E5=8F=96=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?=E5=B1=9E=E6=80=A7=20=20=20=20=20=20-=20=E5=8A=A0=E5=85=A5Execu?=
=?UTF-8?q?tionListener=E8=AE=BE=E8=AE=A1=20=20=20=20=20=20-=20=E6=B7=BB?=
=?UTF-8?q?=E5=8A=A0Metrics=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1=20=20=20?=
=?UTF-8?q?=20=20=20-=20=E4=BC=98=E5=8C=96=E8=B0=83=E7=94=A8=E8=B7=AF?=
=?UTF-8?q?=E5=BE=84=20=20=20=20=20=20-=20=E4=BC=98=E5=8C=96=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9E=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../smartboot/flow/core/EngineContext.java | 62 +++++-
.../flow/core/ExecutionListener.java | 14 ++
.../flow/core/ExecutionListenerRegistry.java | 28 +++
.../flow/core/ExecutionListenerSupport.java | 29 +++
.../flow/core/ExecutionListeners.java | 66 +++++++
.../org/smartboot/flow/core/FlowEngine.java | 18 +-
.../org/smartboot/flow/core/Measurable.java | 31 +++
.../org/smartboot/flow/core/Pipeline.java | 10 +-
.../flow/core/component/ChooseComponent.java | 10 +-
.../flow/core/component/Component.java | 3 +-
.../flow/core/component/IfComponent.java | 8 +-
.../core/component/PipelineComponent.java | 4 +-
.../core/executable/ExecutableAdapter.java | 8 +-
.../flow/core/manager/ComponentModel.java | 12 ++
.../core/manager/DefaultEngineManager.java | 15 ++
.../flow/core/manager/EngineModel.java | 25 +++
.../flow/core/manager/ManagerAction.java | 17 +-
.../flow/core/manager/PipelineModel.java | 15 ++
.../core/manager/RegisterEngineVisitor.java | 12 +-
.../manager/RegisteredComponentVisitor.java | 1 +
.../core/metrics/DefaultMetricsCreator.java | 14 ++
.../core/metrics/MetricExecutionListener.java | 108 +++++++++++
.../smartboot/flow/core/metrics/Metrics.java | 4 +
.../flow/core/metrics/MetricsCreator.java | 16 ++
.../flow/core/metrics/MetricsManager.java | 36 ++++
.../flow/core/metrics/counter/Counter.java | 6 +-
.../flow/core/metrics/counter/MaxCounter.java | 8 +-
.../flow/example/extension/NullStep.java | 4 +
.../src/main/resources/bean.xml | 13 +-
.../org/smartboot/flow/example/ParseTest.java | 4 +-
.../flow/manager/NamedThreadFactory.java | 31 +++
.../flow/manager/change/ChangeModel.java | 30 ++-
.../flow/manager/change/Changer.java | 16 --
.../flow/manager/change/HttpManager.java | 182 ++++++++++++++++++
.../flow/manager/change/RequestModel.java | 40 ++++
.../flow/manager/report/AbstractReporter.java | 19 +-
.../flow/manager/report/HostUtils.java | 51 +++++
.../flow/manager/report/HttpReportModel.java | 51 +++++
.../flow/manager/report/HttpReporter.java | 12 +-
39 files changed, 946 insertions(+), 87 deletions(-)
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerRegistry.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/Measurable.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/DefaultMetricsCreator.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsCreator.java
create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricsManager.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/NamedThreadFactory.java
delete mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/Changer.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/HttpManager.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/RequestModel.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HostUtils.java
create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/report/HttpReportModel.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 d3cc257..6aa5b36 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
@@ -20,6 +20,10 @@ import java.util.concurrent.Future;
*/
public class EngineContext {
+ public static final int DISABLED = -1;
+ public static final int EXECUTING = 1;
+ public static final int ROLLBACK = 2;
+
public static final Logger LOGGER = LoggerFactory.getLogger(EngineContext.class);
private T req;
private S result;
@@ -31,6 +35,12 @@ public class EngineContext {
private ExceptionHandler handler;
private boolean rollback;
private final Map> asyncInvokes = new ConcurrentHashMap<>();
+ private String engineName;
+ private ExecutionListener listener;
+ /**
+ * 执行状态
+ */
+ private int executing;
/**
* Returns current invoked trace.
@@ -93,6 +103,26 @@ public class EngineContext {
this.handler = handler;
}
+ public int getExecuting() {
+ return executing;
+ }
+
+ public void setExecuting(int executing) {
+ this.executing = executing;
+ }
+
+ public void setListener(ExecutionListener listener) {
+ this.listener = listener;
+ }
+
+ public String getEngineName() {
+ return engineName;
+ }
+
+ public void setEngineName(String engineName) {
+ this.engineName = engineName;
+ }
+
public void addAsyncInvoke(Component component, Future future, List> belongs) {
AsyncCallResult result = new AsyncCallResult<>();
result.setFuture(future);
@@ -111,19 +141,30 @@ public class EngineContext {
this.asyncInvokes.forEach((k, v) -> v.checkAndWait(this));
}
- /*
- Delegate methods
- */
- public void enter(String message) {
+ public void enter(Object obj) {
+ String message = this.executing == ROLLBACK ? "rollback " : "";
+ if (obj instanceof Describable) {
+ message += ("rollback " + ((Describable) obj).describe());
+ } else if (obj instanceof String) {
+ message += ("rollback " + obj);
+ }
+
this.tracer.enter(message);
- }
- public void exit() {
- this.tracer.exit();
+ if (executing == EXECUTING) {
+ listener.beforeExecute(this, obj);
+ } else if (executing == ROLLBACK) {
+ listener.beforeRollback(this, obj);
+ }
}
- public void enterRollback(String message) {
- this.tracer.enter("rollback " + message);
+ public void exit(Object obj) {
+ this.tracer.exit();
+ if (executing == EXECUTING) {
+ listener.afterExecute(this, obj);
+ } else if (executing == ROLLBACK) {
+ listener.afterRollback(this, obj);
+ }
}
@SuppressWarnings("unchecked")
@@ -154,6 +195,9 @@ public class EngineContext {
this.broken = false;
this.rollback = false;
this.fatal = null;
+ this.listener = null;
+ this.engineName = null;
+ this.executing = DISABLED;
}
private static class Value implements Serializable {
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
new file mode 100644
index 0000000..8832875
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java
@@ -0,0 +1,14 @@
+package org.smartboot.flow.core;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 20:34:35
+ * @since 1.0.0
+ */
+public interface ExecutionListener {
+
+ void beforeExecute(EngineContext context, Object object);
+ void afterExecute(EngineContext context, Object object);
+ void beforeRollback(EngineContext context, Object object);
+ void afterRollback(EngineContext context, Object object);
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerRegistry.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerRegistry.java
new file mode 100644
index 0000000..2e7b752
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerRegistry.java
@@ -0,0 +1,28 @@
+package org.smartboot.flow.core;
+
+import org.smartboot.flow.core.util.AssertUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 21:15:22
+ * @since 1.0.0
+ */
+public class ExecutionListenerRegistry {
+
+ private static final List REGISTERED = new ArrayList<>();
+
+ public synchronized static void register(ExecutionListener listener) {
+ AssertUtil.notNull(listener, "listener must not be null");
+
+ if (!REGISTERED.contains(listener)) {
+ REGISTERED.add(listener);
+ }
+ }
+
+ public static List getRegistered() {
+ return new ArrayList<>(REGISTERED);
+ }
+}
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
new file mode 100644
index 0000000..f8062d7
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListenerSupport.java
@@ -0,0 +1,29 @@
+package org.smartboot.flow.core;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 21:29:22
+ * @since 1.0.0
+ */
+public class ExecutionListenerSupport implements ExecutionListener {
+
+ @Override
+ public void beforeExecute(EngineContext context, Object object) {
+
+ }
+
+ @Override
+ public void afterExecute(EngineContext context, Object object) {
+
+ }
+
+ @Override
+ public void beforeRollback(EngineContext context, Object object) {
+
+ }
+
+ @Override
+ public void afterRollback(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
new file mode 100644
index 0000000..5e62709
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java
@@ -0,0 +1,66 @@
+package org.smartboot.flow.core;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 21:54:14
+ * @since 1.0.0
+ */
+public class ExecutionListeners implements ExecutionListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExecutionListeners.class);
+
+ private final List listeners;
+
+ public ExecutionListeners(List listeners) {
+ this.listeners = listeners;
+ }
+
+ @Override
+ public void beforeExecute(EngineContext context, Object object) {
+ for (ExecutionListener listener : listeners) {
+ try {
+ listener.beforeExecute(context, object);
+ } catch (Throwable e) {
+ LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e);
+ }
+ }
+ }
+
+ @Override
+ public void afterExecute(EngineContext context, Object object) {
+ for (ExecutionListener listener : listeners) {
+ try {
+ listener.afterExecute(context, object);
+ } catch (Throwable e) {
+ LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e);
+ }
+ }
+ }
+
+ @Override
+ public void beforeRollback(EngineContext context, Object object) {
+ for (ExecutionListener listener : listeners) {
+ try {
+ listener.beforeRollback(context, object);
+ } catch (Throwable e) {
+ LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e);
+ }
+ }
+ }
+
+ @Override
+ public void afterRollback(EngineContext context, Object object) {
+ for (ExecutionListener listener : listeners) {
+ try {
+ listener.afterRollback(context, object);
+ } catch (Throwable e) {
+ LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e);
+ }
+ }
+ }
+}
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 6494c4f..3389146 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.ExceptionHandler;
import org.smartboot.flow.core.manager.DefaultEngineManager;
+import org.smartboot.flow.core.metrics.MetricExecutionListener;
import org.smartboot.flow.core.util.AssertUtil;
import org.smartboot.flow.core.visitor.EngineVisitor;
import org.smartboot.flow.core.visitor.PipelineVisitor;
@@ -15,7 +16,7 @@ import java.util.concurrent.ExecutorService;
* @date 2022-11-12 21:58:12
* @since 1.0.0
*/
-public class FlowEngine implements Describable, Validator {
+public class FlowEngine implements Describable, Validator, Measurable {
private Pipeline pipeline;
private ExceptionHandler exceptionHandler;
@@ -43,7 +44,7 @@ public class FlowEngine implements Describable, Validator {
initContext(context);
- context.enter(describe());
+ context.enter(this);
boolean rollback = false;
try {
@@ -56,10 +57,13 @@ public class FlowEngine implements Describable, Validator {
context.ensureFinished();
if (rollback || context.getRollback()) {
+ context.setExecuting(EngineContext.ROLLBACK);
pipeline.rollback(context);
}
- context.exit();
+ // For end flow-engine.
+ context.setExecuting(EngineContext.EXECUTING);
+ context.exit(this);
if (context.getFatal() != null && exceptionHandler != null) {
context.getHandler().handle(context, context.getFatal());
@@ -72,6 +76,12 @@ public class FlowEngine implements Describable, Validator {
context.clear();
context.setHandler(exceptionHandler);
context.executor = executor;
+ context.setEngineName(this.name);
+ context.setExecuting(EngineContext.EXECUTING);
+
+ // Execution Listener.
+ ExecutionListeners listeners = new ExecutionListeners(ExecutionListenerRegistry.getRegistered());
+ context.setListener(listeners);
}
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
@@ -128,6 +138,8 @@ public class FlowEngine implements Describable, Validator {
AssertUtil.notNull(pipeline, "engine[ " + name + " ]pipeline must not be null");
pipeline.validate();
validateCalled = true;
+ // Register metrics listener.
+ ExecutionListenerRegistry.register(MetricExecutionListener.getInstance());
DefaultEngineManager.getDefaultManager().register(this);
}
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Measurable.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Measurable.java
new file mode 100644
index 0000000..57a12ca
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Measurable.java
@@ -0,0 +1,31 @@
+package org.smartboot.flow.core;
+
+import org.smartboot.flow.core.metrics.Metrics;
+import org.smartboot.flow.core.metrics.MetricsManager;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 20:31:12
+ * @since 1.0.0
+ */
+public interface Measurable {
+
+ /**
+ * 获取可度量的指标数据
+ *
+ * @return 指标数据
+ */
+ default Metrics getMetrics() {
+ return MetricsManager.allocate(this);
+ }
+
+ /**
+ * Reset metrics
+ */
+ default void reset() {
+ Metrics metrics = MetricsManager.allocate(this);
+ if (metrics != null) {
+ metrics.reset();
+ }
+ }
+}
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 efbdc09..b9d8457 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
@@ -15,7 +15,7 @@ import java.util.concurrent.Future;
* @date 2022-11-12 21:57:43
* @since 1.0.0
*/
-public class Pipeline implements Rollback, Describable, Validator {
+public class Pipeline implements Rollback, Describable, Validator, Measurable {
private final List> components = new ArrayList<>();
private String name;
@@ -35,7 +35,7 @@ public class Pipeline implements Rollback, Describable, Validator {
context.putExt(Key.of(this), executed);
// Enter record track
- context.enter(describe());
+ context.enter(this);
for (Component component : components) {
if (context.isBroken()) {
@@ -67,7 +67,7 @@ public class Pipeline implements Rollback, Describable, Validator {
}
// Exit record track
- context.exit();
+ context.exit(this);
}
private void ensureAllDependsExecuted(Component component, EngineContext context) {
@@ -118,7 +118,7 @@ public class Pipeline implements Rollback, Describable, Validator {
return;
}
- context.enterRollback(describe());
+ context.enter(this);
// Execute rollback desc.
for (int i = executed.size() - 1; i >= 0; i--) {
@@ -130,7 +130,7 @@ public class Pipeline implements Rollback, Describable, Validator {
}
}
- context.exit();
+ context.exit(this);
}
public boolean isRollbackable(EngineContext context) {
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 b03c439..4e4563e 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
@@ -50,7 +50,7 @@ public class ChooseComponent extends Component {
@Override
public int invoke(EngineContext context) throws Exception {
- context.enter(describe());
+ context.enter(this);
try {
Object branch = condition.test(context);
Component execute = null;
@@ -73,11 +73,11 @@ public class ChooseComponent extends Component {
try {
return execute.invoke(context);
} finally {
- context.exit();
+ context.exit("branch##" + branch);
}
}
} finally {
- context.exit();
+ context.exit(this);
}
return 1;
@@ -96,11 +96,11 @@ public class ChooseComponent extends Component {
return;
}
- context.enterRollback(describe());
+ context.enter(this);
try {
executed.rollback(context);
} finally {
- context.exit();
+ context.exit(this);
}
}
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 ac3ef4e..25f2415 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
@@ -3,6 +3,7 @@ package org.smartboot.flow.core.component;
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.visitor.ComponentVisitor;
@@ -16,7 +17,7 @@ import java.util.List;
* @date 2022-11-12 17:58:34
* @since 1.0.0
*/
-public abstract class Component implements Rollback, Describable, Validator {
+public abstract class Component implements Rollback, Describable, Validator, Measurable {
/**
* 是否可降级
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 edb453f..e04fa63 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
@@ -40,7 +40,7 @@ public class IfComponent extends Component{
@Override
public int invoke(EngineContext context) throws Exception {
- context.enter(describe());
+ context.enter(this);
try {
Object test = condition.test(context);
Component execute = null;
@@ -56,7 +56,7 @@ public class IfComponent extends Component{
return execute.invoke(context);
}
} finally {
- context.exit();
+ context.exit(this);
}
return 1;
@@ -75,11 +75,11 @@ public class IfComponent extends Component{
return;
}
- context.enterRollback(describe());
+ context.enter(this);
try {
executed.rollback(context);
} finally {
- context.exit();
+ 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 83c5322..8f8b01b 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
@@ -43,11 +43,11 @@ public class PipelineComponent extends Component {
if (!isRollbackable(context)) {
return;
}
- context.enterRollback(describe());
+ context.enter(this);
try {
pipeline.rollback(context);
} finally {
- context.exit();
+ context.exit(this);
}
}
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 43c5848..b5423dc 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
@@ -29,12 +29,12 @@ public class ExecutableAdapter extends Component implements Rollback<
}
public int invoke(EngineContext context) {
- context.enter(describe());
+ context.enter(this);
try {
executable.execute(context);
} finally {
- context.exit();
+ context.exit(this);
}
return 1;
@@ -43,12 +43,12 @@ public class ExecutableAdapter extends Component implements Rollback<
@Override
public void rollback(EngineContext context) {
- context.enter("rollback " + describe());
+ context.enter(this);
try {
executable.rollback(context);
} finally {
- context.exit();
+ 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 4db3a24..4176901 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
@@ -5,6 +5,7 @@ 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.component.Component;
+import org.smartboot.flow.core.metrics.Metrics;
import java.util.HashMap;
import java.util.List;
@@ -32,12 +33,14 @@ public class ComponentModel extends Uniqueness {
PipelineModel pipeline;
String condition;
private String branch;
+ private final 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();
}
public Map getHolders() {
@@ -127,4 +130,13 @@ public class ComponentModel extends Uniqueness {
}
}
+
+ public Metrics getMetrics() {
+ return metrics;
+ }
+
+ public void reset() {
+ this.metrics.reset();
+ components.forEach((k, v) -> v.reset());
+ }
}
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 5e3175a..1af1541 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
@@ -76,7 +76,22 @@ public class DefaultEngineManager implements EngineManager {
@Override
public void resetStatistic(String identifier) {
+ AssertUtil.notBlank(identifier, "identifier must not be blank!");
+ for (Map.Entry entry : registeredEngines.entrySet()) {
+ if (entry.getKey().equals(identifier) || entry.getValue().getPipeline().getIdentifier().equals(identifier)) {
+ entry.getValue().reset();
+ break;
+ }
+
+ }
+ for (Map.Entry entry : registeredEngines.entrySet()) {
+ if (entry.getValue().containsComponent(identifier)) {
+ entry.getValue().reset(identifier);
+ break;
+ }
+
+ }
}
@Override
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 16db366..cd5ee5a 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
@@ -4,6 +4,7 @@ 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.metrics.Metrics;
import java.util.HashMap;
import java.util.List;
@@ -21,6 +22,7 @@ public class EngineModel extends Uniqueness {
private PipelineModel pipeline;
private transient final Map components = new ConcurrentHashMap<>();
+ private Metrics metrics;
public EngineModel(String name) {
// Engine's name must be global unique.
@@ -56,4 +58,27 @@ public class EngineModel extends Uniqueness {
void collect() {
this.components.putAll(this.pipeline.collect());
}
+
+ public Metrics getMetrics() {
+ return metrics;
+ }
+
+ public void setMetrics(Metrics metrics) {
+ this.metrics = metrics;
+ }
+
+ public void reset() {
+ this.metrics.reset();
+ this.pipeline.reset();
+ }
+
+ public void reset(String identifier) {
+ ComponentModel model = components.get(identifier);
+ if (model == null) {
+ LOGGER.warn("change component attributes failed, identifier = {}", identifier);
+ return;
+ }
+
+ model.reset();
+ }
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
index 3ff16fa..b0d536f 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ManagerAction.java
@@ -1,5 +1,7 @@
package org.smartboot.flow.core.manager;
+import java.util.Objects;
+
/**
* @author qinluo
* @date 2022/11/22 22:02
@@ -11,15 +13,20 @@ public enum ManagerAction {
*/
CHANGE_ATTRIBUTES,
- /**
- * Add a new component.
- */
- NEW_COMPONENT,
-
/**
* Reset statistic metrics.
*/
RESET_METRICS,
;
+
+ public static ManagerAction get(String name) {
+ if (Objects.equals(name, CHANGE_ATTRIBUTES.name())) {
+ return CHANGE_ATTRIBUTES;
+ } else if (Objects.equals(name, RESET_METRICS.name())) {
+ return RESET_METRICS;
+ }
+
+ return null;
+ }
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
index 76a230b..0c03cf7 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java
@@ -1,6 +1,7 @@
package org.smartboot.flow.core.manager;
import org.smartboot.flow.core.common.Uniqueness;
+import org.smartboot.flow.core.metrics.Metrics;
import java.util.ArrayList;
import java.util.HashMap;
@@ -17,6 +18,7 @@ public class PipelineModel extends Uniqueness {
private final List components = new ArrayList<>();
private final String name;
+ private Metrics metrics;
PipelineModel(String name, String identifier) {
this.name = name;
@@ -43,4 +45,17 @@ public class PipelineModel extends Uniqueness {
return collected;
}
+
+ public Metrics getMetrics() {
+ return metrics;
+ }
+
+ public void setMetrics(Metrics metrics) {
+ this.metrics = metrics;
+ }
+
+ public void reset() {
+ this.metrics.reset();
+ components.forEach(ComponentModel::reset);
+ }
}
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 3ff2a26..6b66aa4 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,5 +1,6 @@
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;
@@ -15,19 +16,22 @@ public class RegisterEngineVisitor extends EngineVisitor {
private EngineModel model;
@Override
- public void visitEnd() {
- this.model.collect();
+ public void visit(FlowEngine flowEngine) {
+ this.model = new EngineModel(flowEngine.getName());
+ this.model.setMetrics(flowEngine.getMetrics());
+ super.visit(flowEngine);
}
@Override
- public void visit(String engine) {
- this.model = new EngineModel(engine);
+ public void visitEnd() {
+ this.model.collect();
}
@Override
public PipelineVisitor visitPipeline(Pipeline pipeline) {
PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(this.model.getIdentifier(), pipeline.describe()));
this.model.setPipeline(pipelineModel);
+ pipelineModel.setMetrics(pipeline.getMetrics());
return new RegisteredPipelineVisitor(pipelineModel);
}
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 a5b5dea..0193f4a 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
@@ -29,6 +29,7 @@ public class RegisteredComponentVisitor extends ComponentVisitor {
PipelineModel pipelineModel = new PipelineModel(pipeline.describe(), ContactUtils.contact(model.getIdentifier(), pipeline.describe()));
this.model.pipeline = pipelineModel;
this.model.type = (ComponentType.PIPELINE);
+ pipelineModel.setMetrics(pipeline.getMetrics());
return new RegisteredPipelineVisitor(pipelineModel);
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/DefaultMetricsCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/DefaultMetricsCreator.java
new file mode 100644
index 0000000..2f15888
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/DefaultMetricsCreator.java
@@ -0,0 +1,14 @@
+package org.smartboot.flow.core.metrics;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 21:51:52
+ * @since 1.0.0
+ */
+public class DefaultMetricsCreator implements MetricsCreator {
+
+ @Override
+ public Metrics create() {
+ return new Metrics();
+ }
+}
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
new file mode 100644
index 0000000..0d441c7
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/metrics/MetricExecutionListener.java
@@ -0,0 +1,108 @@
+package org.smartboot.flow.core.metrics;
+
+import org.smartboot.flow.core.EngineContext;
+import org.smartboot.flow.core.ExecutionListener;
+import org.smartboot.flow.core.Key;
+import org.smartboot.flow.core.Measurable;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author qinluo
+ * @date 2022-11-25 21:23:28
+ * @since 1.0.0
+ */
+public class MetricExecutionListener implements ExecutionListener {
+
+ private static final ExecutionListener INSTANCE = new MetricExecutionListener();
+
+ public static ExecutionListener getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public void beforeExecute(EngineContext context, Object object) {
+ if (!(object instanceof Measurable)) {
+ return;
+ }
+
+ Map
\ No newline at end of file
diff --git a/smart-flow-example/pom.xml b/smart-flow-example/pom.xml
index 0a59967..fd01f88 100644
--- a/smart-flow-example/pom.xml
+++ b/smart-flow-example/pom.xml
@@ -5,7 +5,7 @@
flow-engine
org.smartboot
- 1.0.0
+ 1.0.1
4.0.0
@@ -20,13 +20,13 @@
org.smartboot
smart-flow-manager
- 1.0.0
+ 1.0.1
org.smartboot
smart-flow-spring-extension
- 1.0.0
+ 1.0.1
@@ -42,6 +42,13 @@
5.9.1
test
+
+
+ org.slf4j
+ slf4j-log4j12
+ 2.0.3
+
+
\ No newline at end of file
diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml
index 84bf720..39dea51 100644
--- a/smart-flow-manager/pom.xml
+++ b/smart-flow-manager/pom.xml
@@ -5,7 +5,7 @@
flow-engine
org.smartboot
- 1.0.0
+ 1.0.1
4.0.0
@@ -20,7 +20,7 @@
org.smartboot
smart-flow-core
- 1.0.0
+ 1.0.1
@@ -32,7 +32,7 @@
com.alibaba
fastjson
- 1.2.70
+ 2.0.19
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 948c034..844d4c4 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
@@ -75,6 +75,8 @@ public class HttpManager {
model.setAddress(HostUtils.getHostIp());
model.setHost(HostUtils.getHostName());
model.setTimestamp(lastest);
+ // 只请求当前机器有的engines
+ model.setEngineNames(DefaultEngineManager.getDefaultManager().getRegisteredEngineNames());
String json = JSON.toJSONString(model);
byte[] bytes = json.getBytes(StandardCharsets.UTF_8);
diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/RequestModel.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/RequestModel.java
index b960421..8aee84d 100644
--- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/RequestModel.java
+++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/change/RequestModel.java
@@ -1,6 +1,7 @@
package org.smartboot.flow.manager.change;
import java.io.Serializable;
+import java.util.List;
/**
* @author qinluo
@@ -13,6 +14,15 @@ public class RequestModel implements Serializable {
private long timestamp;
private String address;
private String host;
+ private List engineNames;
+
+ public List getEngineNames() {
+ return engineNames;
+ }
+
+ public void setEngineNames(List engineNames) {
+ this.engineNames = engineNames;
+ }
public long getTimestamp() {
return timestamp;
diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml
index 285eacc..4fb8869 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.0
+ 1.0.1
4.0.0
@@ -21,7 +21,7 @@
org.smartboot
smart-flow-core
- 1.0.0
+ 1.0.1
--
Gitee
From 2b372a8a6b5c74c28cdb26eb614d8965e762a04d Mon Sep 17 00:00:00 2001
From: qinluo <1558642210@qq.com>
Date: Sat, 26 Nov 2022 23:57:24 +0800
Subject: [PATCH 14/14] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=88=A0?=
=?UTF-8?q?=E9=99=A4=E6=97=A0=E7=94=A8=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/test/resources/logback.xml | 37 -------------------
.../src/main/resources/logback.xml | 37 -------------------
2 files changed, 74 deletions(-)
delete mode 100644 smart-flow-core/src/test/resources/logback.xml
delete mode 100644 smart-flow-example/src/main/resources/logback.xml
diff --git a/smart-flow-core/src/test/resources/logback.xml b/smart-flow-core/src/test/resources/logback.xml
deleted file mode 100644
index 347cb45..0000000
--- a/smart-flow-core/src/test/resources/logback.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} [%file:%line] - %msg%n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/smart-flow-example/src/main/resources/logback.xml b/smart-flow-example/src/main/resources/logback.xml
deleted file mode 100644
index 347cb45..0000000
--- a/smart-flow-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} [%file:%line] - %msg%n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
Gitee