From 4332d054f2c3bda2f72701b62a61115b85b93578 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 27 Jul 2023 14:55:07 +0800 Subject: [PATCH 01/20] qinluo: - 1.1.3-SNAPSHOT Signed-off-by: qinluo <1558642210@qq.com> --- pom.xml | 4 ++-- smart-flow-admin/pom.xml | 4 ++-- smart-flow-core/pom.xml | 2 +- smart-flow-helper/pom.xml | 2 +- smart-flow-manager/pom.xml | 4 ++-- smart-flow-plugin/pom.xml | 2 +- smart-flow-plugin/smart-flow-bootstrap/pom.xml | 2 +- smart-flow-plugin/smart-flow-enhance-plugin/pom.xml | 2 +- smart-flow-script/pom.xml | 2 +- smart-flow-script/smart-flow-script-groovy/pom.xml | 2 +- smart-flow-script/smart-flow-script-ognl/pom.xml | 2 +- smart-flow-script/smart-flow-script-qlexpress/pom.xml | 2 +- smart-flow-spring-extension/pom.xml | 2 +- smart-flow-springboot-starter/pom.xml | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 53b03fa..1fc11b8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 pom smart-flow @@ -23,7 +23,7 @@ - 1.1.2 + 1.1.3-SNAPSHOT https://gitee.com/smartboot/smart-flow diff --git a/smart-flow-admin/pom.xml b/smart-flow-admin/pom.xml index 85828cc..f1c8545 100644 --- a/smart-flow-admin/pom.xml +++ b/smart-flow-admin/pom.xml @@ -5,10 +5,10 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 - 1.1.2 + 1.1.3-SNAPSHOT smart-flow-admin diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index 35b721c..a3d80cf 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-helper/pom.xml b/smart-flow-helper/pom.xml index 3d8489e..ef9dfb3 100644 --- a/smart-flow-helper/pom.xml +++ b/smart-flow-helper/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index db7aa9c..568a916 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 @@ -32,7 +32,7 @@ org.smartboot.http smart-http-client - 1.1.22 + 1.1.2 diff --git a/smart-flow-plugin/pom.xml b/smart-flow-plugin/pom.xml index d6c8537..97772a1 100644 --- a/smart-flow-plugin/pom.xml +++ b/smart-flow-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-parent - 1.1.2 + 1.1.3-SNAPSHOT smart-flow-plugin diff --git a/smart-flow-plugin/smart-flow-bootstrap/pom.xml b/smart-flow-plugin/smart-flow-bootstrap/pom.xml index a5625c0..8a9691e 100644 --- a/smart-flow-plugin/smart-flow-bootstrap/pom.xml +++ b/smart-flow-plugin/smart-flow-bootstrap/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.2 + 1.1.3-SNAPSHOT smart-flow-bootstrap diff --git a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml index 77a3bc2..82e0741 100644 --- a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml +++ b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.2 + 1.1.3-SNAPSHOT smart-flow-enhance-plugin diff --git a/smart-flow-script/pom.xml b/smart-flow-script/pom.xml index c41ee12..4d9da06 100644 --- a/smart-flow-script/pom.xml +++ b/smart-flow-script/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 pom diff --git a/smart-flow-script/smart-flow-script-groovy/pom.xml b/smart-flow-script/smart-flow-script-groovy/pom.xml index dcb9a35..28b6190 100644 --- a/smart-flow-script/smart-flow-script-groovy/pom.xml +++ b/smart-flow-script/smart-flow-script-groovy/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-script/smart-flow-script-ognl/pom.xml b/smart-flow-script/smart-flow-script-ognl/pom.xml index 71f7076..cd755ce 100644 --- a/smart-flow-script/smart-flow-script-ognl/pom.xml +++ b/smart-flow-script/smart-flow-script-ognl/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-script/smart-flow-script-qlexpress/pom.xml b/smart-flow-script/smart-flow-script-qlexpress/pom.xml index 3c1184b..bc54432 100644 --- a/smart-flow-script/smart-flow-script-qlexpress/pom.xml +++ b/smart-flow-script/smart-flow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml index 14ad1b0..2c3a55b 100644 --- a/smart-flow-spring-extension/pom.xml +++ b/smart-flow-spring-extension/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 diff --git a/smart-flow-springboot-starter/pom.xml b/smart-flow-springboot-starter/pom.xml index e90b4f5..867d88b 100644 --- a/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-springboot-starter/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.2 + 1.1.3-SNAPSHOT 4.0.0 -- Gitee From 498b0f274eb57b51c41886db3a8e200ad43b1a3f Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 27 Jul 2023 15:07:06 +0800 Subject: [PATCH 02/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=9B=B4?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E7=9A=84=E6=B5=81=E7=A8=8B=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- .../flow/core/EngineContextHelper.java | 39 +++++++++++++++++++ .../org/smartboot/flow/core/FlowEngine.java | 2 + .../core/executable/AbstractExecutable.java | 19 +++++++++ .../flow/core/invoker/AsyncRunner.java | 7 ++++ 4 files changed, 67 insertions(+) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java new file mode 100644 index 0000000..86341b2 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java @@ -0,0 +1,39 @@ +package org.smartboot.flow.core; + +/** + * @author qinluo + * @date 2023-07-27 14:55:42 + * @since 1.1.3 + */ +@SuppressWarnings("rawtypes") +public class EngineContextHelper { + + private static final ThreadLocal HOLDER = new ThreadLocal<>(); + + public static void set(EngineContext ctx) { + HOLDER.set(ctx); + } + + public static EngineContext get() { + return HOLDER.get(); + } + + public static void remove() { + HOLDER.remove(); + } + + public static void broken(boolean broken) { + EngineContext ctx = get(); + if (ctx != null) { + ctx.broken(broken); + } + } + + public static void brokenAll(boolean broken) { + EngineContext ctx = get(); + if (ctx != null) { + ctx.brokenAll(broken); + } + } + +} 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 5ee4d81..530660e 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 @@ -85,6 +85,7 @@ public class FlowEngine implements Describable, Validator, Measurable { } private void start(EngineContext context) { + EngineContextHelper.set(context); context.executedAt = System.currentTimeMillis(); context.listener.start(context); } @@ -92,6 +93,7 @@ public class FlowEngine implements Describable, Validator, Measurable { private void complete(EngineContext context) { context.completedAt = System.currentTimeMillis(); context.listener.completed(context); + EngineContextHelper.remove(); } protected void initContext(EngineContext context) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java index 12c6915..b4c7e31 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java @@ -2,6 +2,7 @@ package org.smartboot.flow.core.executable; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.EngineContextHelper; /** * 调用层,与业务相关 @@ -29,4 +30,22 @@ public abstract class AbstractExecutable implements Executable { public void rollback(T t, S s) { } + + /** + * Broken current subprocess. + * + * @since 1.1.3 + */ + protected void broken() { + EngineContextHelper.broken(true); + } + + /** + * Broken whole process. + * + * @since 1.1.3 + */ + protected void brokenAll() { + EngineContextHelper.brokenAll(true); + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java index 842ce47..c02a484 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/AsyncRunner.java @@ -1,5 +1,7 @@ package org.smartboot.flow.core.invoker; +import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.EngineContextHelper; import org.smartboot.flow.core.trace.Node; import org.smartboot.flow.core.trace.Tracer; @@ -10,15 +12,18 @@ import java.util.concurrent.Callable; * @date 2022-12-07 21:57:39 * @since 1.0.0 */ +@SuppressWarnings("rawtypes") public class AsyncRunner implements Callable { private final Callable task; private final Node root; private final long threadId; + private final EngineContext ctx; public AsyncRunner(Callable task) { this.task = task; this.root = Tracer.get(); + this.ctx = EngineContextHelper.get(); this.threadId = Thread.currentThread().getId(); } @@ -38,6 +43,7 @@ public class AsyncRunner implements Callable { if (tid != threadId) { Tracer.setNode(root); } + EngineContextHelper.set(ctx); } protected void doAfterRun() { @@ -45,5 +51,6 @@ public class AsyncRunner implements Callable { if (tid != threadId) { Tracer.remove(); } + EngineContextHelper.remove(); } } -- Gitee From fe166367984dce09ed12a1c96417f92635af454c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 28 Jul 2023 17:46:21 +0800 Subject: [PATCH 03/20] qinluo: - ignore Signed-off-by: qinluo <1558642210@qq.com> --- smart-flow-manager/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 568a916..5a4b28e 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -32,7 +32,7 @@ org.smartboot.http smart-http-client - 1.1.2 + 1.1.22 -- Gitee From 18de20d0924708690c520c3383daa0d91d39b777 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 2 Aug 2023 09:05:14 +0800 Subject: [PATCH 04/20] qinluo: - remove deprecated methods. Signed-off-by: qinluo <1558642210@qq.com> --- .../flow/core/manager/DefaultEngineManager.java | 11 ----------- 1 file changed, 11 deletions(-) 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 d13f34a..49e7fa6 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 @@ -23,17 +23,6 @@ public class DefaultEngineManager implements EngineManager { private final Map registeredEngines = new ConcurrentHashMap<>(); - /** - * Return singleton instance. - * Will remove at 1.1.0, please use {@link EngineManager#defaultManager()}. - * - * @return singleton instance. - */ - @Deprecated - public static EngineManager getDefaultManager() { - return INSTANCE; - } - /** * Rename getDefaultManager to getInstance. * -- Gitee From 9cd1fcd544610d5ad826cab8499107116fc96387 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 2 Aug 2023 10:02:43 +0800 Subject: [PATCH 05/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20trace?= =?UTF-8?q?=E9=87=87=E9=9B=86=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- smart-flow-manager/pom.xml | 1 + .../flow/manager/trace/HttpTraceReporter.java | 107 ++++++++ .../flow/manager/trace/LogTraceReporter.java | 27 ++ .../trace/ManagerExecutionListener.java | 8 +- .../flow/manager/trace/TraceCollector.java | 133 +++++++++ .../flow/manager/trace/TraceReporter.java | 255 +----------------- .../manager/trace/TraceRequestConverter.java | 87 ++++++ 7 files changed, 366 insertions(+), 252 deletions(-) create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/HttpTraceReporter.java create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/LogTraceReporter.java create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceRequestConverter.java diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 5a4b28e..fd293d7 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/HttpTraceReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/HttpTraceReporter.java new file mode 100644 index 0000000..7dad8b2 --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/HttpTraceReporter.java @@ -0,0 +1,107 @@ +package org.smartboot.flow.manager.trace; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.manager.EngineManager; +import org.smartboot.flow.manager.ManagerConstants; +import org.smartboot.flow.manager.UpdateContentTask; +import org.smartboot.http.client.HttpClient; +import org.smartboot.http.client.HttpPost; +import org.smartboot.http.common.enums.HeaderNameEnum; + +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +/** + * @author qinluo + * @date 2023-02-07 + * @since 1.1.3 + */ +public class HttpTraceReporter implements TraceReporter { + + private static final Logger LOGGER = LoggerFactory.getLogger(HttpTraceReporter.class); + + /** + * 服务端地址 + */ + private String serverAddress; + + /** + * 超时时间 + */ + private long timeout; + private String host; + private int port; + + private Map headers; + + @Override + public void report(TraceData trace) { + EngineManager defaultManager = EngineManager.defaultManager(); + + HttpClient httpClient = new HttpClient(host, port); + httpClient.configuration().connectTimeout((int) timeout); + HttpPost post = httpClient.post(ManagerConstants.REPORT_TRACE); + + if (headers != null) { + headers.forEach((key, value) -> post.header().add(key, value)); + } + + FlowEngine source = defaultManager.getEngineModel(trace.getEngineName()).getSource(); + TraceReportRequest request = TraceRequestConverter.convert(trace, source); + + String json = JSON.toJSONString(request, SerializerFeature.WriteEnumUsingToString); + byte[] bytes = json.getBytes(StandardCharsets.UTF_8); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("report trace data, engine = {}, data = {}", trace.getEngineName(), JSON.toJSONString(request)); + } + + post.header().add(HeaderNameEnum.CONTENT_TYPE.getName(), "application/json;charset=UTF-8").add(HeaderNameEnum.CONTENT_LENGTH.getName(), String.valueOf(bytes.length)); + + // Use body stream write. + post.body().write(bytes, 0, bytes.length).done() + .onSuccess(httpResponse -> LOGGER.info("send trace success")) + .onFailure(throwable -> LOGGER.error("send trace failed", throwable)); + } + + public void init() { + URL parsedUrl; + try { + parsedUrl = new URL(serverAddress); + } catch (Exception e) { + throw new IllegalStateException("invalid url " + serverAddress, e); + } + this.host = parsedUrl.getHost(); + this.port = parsedUrl.getPort(); + UpdateContentTask.startTask(host, port); + } + + public String getServerAddress() { + return serverAddress; + } + + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; + } + + public long getTimeout() { + return timeout; + } + + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/LogTraceReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/LogTraceReporter.java new file mode 100644 index 0000000..d035e9d --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/LogTraceReporter.java @@ -0,0 +1,27 @@ +package org.smartboot.flow.manager.trace; + +import com.alibaba.fastjson.JSON; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.manager.EngineManager; + +/** + * @author qinluo + * @date 2023-02-07 + * @since 1.1.3 + */ +public class LogTraceReporter implements TraceReporter { + + private static final Logger LOGGER = LoggerFactory.getLogger(LogTraceReporter.class); + + @Override + public void report(TraceData trace) { + EngineManager defaultManager = EngineManager.defaultManager(); + + FlowEngine source = defaultManager.getEngineModel(trace.getEngineName()).getSource(); + TraceReportRequest request = TraceRequestConverter.convert(trace, source); + + LOGGER.info("{}", JSON.toJSONString(request)); + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/ManagerExecutionListener.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/ManagerExecutionListener.java index 8da1055..48e12e9 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/ManagerExecutionListener.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/ManagerExecutionListener.java @@ -20,11 +20,11 @@ public class ManagerExecutionListener implements ExecutionListener { * Invoke trace in engine invoking. */ private static final Key TRACES = Key.of("traces"); - private final TraceReporter traceReporter; + private final TraceCollector traceCollector; private TraceSampleStrategy sampleStrategy; - public ManagerExecutionListener(TraceReporter traceReporter, TraceSampleStrategy sampleStrategy) { - this.traceReporter = traceReporter; + public ManagerExecutionListener(TraceCollector traceCollector, TraceSampleStrategy sampleStrategy) { + this.traceCollector = traceCollector; this.sampleStrategy = sampleStrategy; } @@ -135,6 +135,6 @@ public class ManagerExecutionListener implements ExecutionListener { } // 将执行采集到的数据进行上报 - traceReporter.submit(trace); + traceCollector.submit(trace); } } diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java new file mode 100644 index 0000000..ba8a5b5 --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java @@ -0,0 +1,133 @@ +package org.smartboot.flow.manager.trace; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.ExecutionListenerRegistry; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.manager.NamedThreadFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author qinluo + * @date 2023-02-07 + * @since 1.0.7 + */ +public class TraceCollector { + + private static final Logger LOGGER = LoggerFactory.getLogger(TraceCollector.class); + private final ScheduledThreadPoolExecutor executorService = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("export-trace")); + + /** + * Report idle in mills. + */ + protected long idle = 5000L; + private Double radio; + private TraceSampleStrategy sampleStrategy; + private ManagerExecutionListener executionListener; + + private Map headers; + private final BlockingQueue traceQueue = new ArrayBlockingQueue<>(20000); + private final List reporters = new ArrayList<>(8); + + public long getIdle() { + return idle; + } + + public void setIdle(long idle) { + AssertUtil.isTrue(idle > 0, "idle must great than zero"); + this.idle = idle; + } + + public void addReporter(TraceReporter reporter) { + reporters.add(reporter); + } + + public void removeReporter(TraceReporter reporter) { + reporters.remove(reporter); + } + + public void removeAll() { + reporters.clear(); + } + + public void setReporters(List reporters) { + this.reporters.addAll(reporters); + } + + public void export() { + try { + this.doExport(); + } catch (Throwable ex){ + LOGGER.error("report trace failed", ex); + } + } + + public void doExport() { + List traces = new ArrayList<>(); + if (traceQueue.drainTo(traces) < 0) { + return; + } + + for (TraceData trace : traces) { + for (TraceReporter reporter : reporters) { + reporter.report(trace); + } + + } + } + + public void start() { + // Register listener. + if (sampleStrategy == null && radio != null && radio > 0 && radio <= 1) { + sampleStrategy = new TraceSampleStrategy(); + sampleStrategy.setRadio(radio); + } + + executionListener = new ManagerExecutionListener(this, sampleStrategy); + ExecutionListenerRegistry.register(executionListener); + executorService.setMaximumPoolSize(1); + executorService.scheduleAtFixedRate(this::export, idle, idle, TimeUnit.MILLISECONDS); + } + + public void submit(TraceData item) { + //noinspection ResultOfMethodCallIgnored + traceQueue.offer(item); + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public Double getRadio() { + return radio; + } + + public void setRadio(Double radio) { + this.radio = radio; + if (sampleStrategy != null && radio != null && radio > 0 && radio <= 1) { + sampleStrategy.setRadio(radio); + } + } + + public TraceSampleStrategy getSampleStrategy() { + return sampleStrategy; + } + + public void setSampleStrategy(TraceSampleStrategy sampleStrategy) { + this.sampleStrategy = sampleStrategy; + if (this.executionListener != null) { + this.executionListener.setSampleStrategy(this.sampleStrategy); + } + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceReporter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceReporter.java index 9748369..0bb02d1 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceReporter.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceReporter.java @@ -1,257 +1,16 @@ package org.smartboot.flow.manager.trace; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.serializer.SerializerFeature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.ExecutionListenerRegistry; -import org.smartboot.flow.core.manager.EngineManager; -import org.smartboot.flow.core.util.AssertUtil; -import org.smartboot.flow.manager.FlatEngine; -import org.smartboot.flow.manager.FlatManager; -import org.smartboot.flow.manager.HostUtils; -import org.smartboot.flow.manager.ManagerConfiguration; -import org.smartboot.flow.manager.ManagerConstants; -import org.smartboot.flow.manager.NamedThreadFactory; -import org.smartboot.flow.manager.UpdateContentTask; -import org.smartboot.http.client.HttpClient; -import org.smartboot.http.client.HttpPost; -import org.smartboot.http.common.enums.HeaderNameEnum; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - /** * @author qinluo - * @date 2023-02-07 - * @since 1.0.7 + * @date 2023-08-02 09:13:20 + * @since 1.1.3 */ -public class TraceReporter { - - private static final Logger LOGGER = LoggerFactory.getLogger(TraceReporter.class); - private final ScheduledThreadPoolExecutor executorService = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("export-trace")); - - /** - * Report idle in mills. - */ - protected long idle = 5000L; +public interface TraceReporter { /** - * 服务端地址 + * Report trace record. + * + * @param trace trace. */ - private String serverAddress; - - /** - * 超时时间 - */ - private long timeout; - private String host; - private int port; - private Double radio; - private TraceSampleStrategy sampleStrategy; - private ManagerExecutionListener executionListener; - - private Map headers; - private final BlockingQueue traceQueue = new ArrayBlockingQueue<>(20000); - - public long getIdle() { - return idle; - } - - public void setIdle(long idle) { - AssertUtil.isTrue(idle > 0, "idle must great than zero"); - this.idle = idle; - } - - public void export() { - try { - this.doExport(); - } catch (Throwable ex){ - LOGGER.error("report trace failed", ex); - } - } - - public void doExport() { - List traces = new ArrayList<>(); - if (traceQueue.drainTo(traces) < 0) { - return; - } - - EngineManager defaultManager = EngineManager.defaultManager(); - - for (TraceData trace : traces) { - HttpClient httpClient = new HttpClient(host, port); - httpClient.configuration().connectTimeout((int) timeout); - HttpPost post = httpClient.post(ManagerConstants.REPORT_TRACE); - - if (headers != null) { - headers.forEach((key, value) -> post.header().add(key, value)); - } - - TraceReportRequest request = new TraceReportRequest(); - request.setAddress(HostUtils.getHostIp()); - request.setHost(HostUtils.getHostName()); - request.setTimestamp(System.currentTimeMillis()); - FlatEngine flatEngine = FlatManager.getInstance().getFlatEngine(defaultManager.getEngineModel(trace.getEngineName()).getSource()); - request.setMd5(flatEngine.getMd5()); - request.setTraceId(trace.getTraceId()); - request.setEngineName(trace.getEngineName()); - request.setSuccess(trace.getEx() == null); - request.setTraceTime(trace.getTraceTime()); - request.setEndTime(trace.getEndTime()); - if (!request.getSuccess()) { - request.setEx(serialExToString(trace.getEx())); - } - request.setRequest(toJSON(trace.getRequest())); - request.setResult(toJSON(trace.getResult())); - - if (flatEngine.getReportContent()) { - request.setContent(flatEngine.getContent()); - } - - JSONArray ja = new JSONArray(); - - trace.getComponents().forEach((k, v) -> { - JSONObject item = new JSONObject(); - item.put("name", k.getName()); - item.put("type", k.getType()); - item.put("start", v.getStart()); - item.put("escape", v.getEscape()); - item.put("ex", serialExToString(v.getEx())); - item.put("rollbackStart", v.getRollbackStart()); - item.put("rollbackEnd", v.getRollbackEnd()); - - ja.add(item); - }); - - request.setJson(ja); - - String json = JSON.toJSONString(request, SerializerFeature.WriteEnumUsingToString); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("report trace data, engine = {}, data = {}", trace.getEngineName(), JSON.toJSONString(request)); - } - - post.header().add(HeaderNameEnum.CONTENT_TYPE.getName(), "application/json;charset=UTF-8").add(HeaderNameEnum.CONTENT_LENGTH.getName(), String.valueOf(bytes.length)); - - // Use body stream write. - post.body().write(bytes, 0, bytes.length).done().onSuccess(httpResponse -> { - LOGGER.info("send trace success"); - }) - .onFailure(throwable -> { - LOGGER.error("send trace failed", throwable); - }); - - } - } - - private String serialExToString(Throwable ex) { - if (ex == null) { - return null; - } - - int maxDepth = ManagerConfiguration.reportMaxStackDepth; - StackTraceElement[] stackTrace = ex.getStackTrace(); - if (stackTrace.length > maxDepth) { - StackTraceElement[] newTrace = new StackTraceElement[maxDepth]; - System.arraycopy(stackTrace, 0, newTrace, 0, newTrace.length); - ex.setStackTrace(newTrace); - } - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintWriter writer = new PrintWriter(bos); - ex.printStackTrace(writer); - writer.flush(); - return bos.toString(); - } - - public void start() { - URL parsedUrl; - try { - parsedUrl = new URL(serverAddress); - } catch (Exception e) { - throw new IllegalStateException("invalid url " + serverAddress, e); - } - this.host = parsedUrl.getHost(); - this.port = parsedUrl.getPort(); - - // Register listener. - if (sampleStrategy == null && radio != null && radio > 0 && radio <= 1) { - sampleStrategy = new TraceSampleStrategy(); - sampleStrategy.setRadio(radio); - } - - executionListener = new ManagerExecutionListener(this, sampleStrategy); - ExecutionListenerRegistry.register(executionListener); - UpdateContentTask.startTask(host, port); - executorService.setMaximumPoolSize(1); - executorService.scheduleAtFixedRate(this::export, idle, idle, TimeUnit.MILLISECONDS); - } - - public void submit(TraceData item) { - //noinspection ResultOfMethodCallIgnored - traceQueue.offer(item); - } - - public String getServerAddress() { - return serverAddress; - } - - public void setServerAddress(String serverAddress) { - this.serverAddress = serverAddress; - } - - public long getTimeout() { - return timeout; - } - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - public Map getHeaders() { - return headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - - public Double getRadio() { - return radio; - } - - public void setRadio(Double radio) { - this.radio = radio; - if (sampleStrategy != null && radio != null && radio > 0 && radio <= 1) { - sampleStrategy.setRadio(radio); - } - } - - public TraceSampleStrategy getSampleStrategy() { - return sampleStrategy; - } - - public void setSampleStrategy(TraceSampleStrategy sampleStrategy) { - this.sampleStrategy = sampleStrategy; - if (this.executionListener != null) { - this.executionListener.setSampleStrategy(this.sampleStrategy); - } - } - - protected String toJSON(Object obj) { - return obj == null ? null : JSON.toJSONString(obj); - } + void report(TraceData trace); } diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceRequestConverter.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceRequestConverter.java new file mode 100644 index 0000000..9130947 --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceRequestConverter.java @@ -0,0 +1,87 @@ +package org.smartboot.flow.manager.trace; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.manager.FlatEngine; +import org.smartboot.flow.manager.FlatManager; +import org.smartboot.flow.manager.HostUtils; +import org.smartboot.flow.manager.ManagerConfiguration; + +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + +/** + * @author qinluo + * @date 2023-08-02 09:05:51 + * @since 1.1.3 + */ +public class TraceRequestConverter { + + public static TraceReportRequest convert(TraceData trace, FlowEngine engine) { + TraceReportRequest request = new TraceReportRequest(); + request.setAddress(HostUtils.getHostIp()); + request.setHost(HostUtils.getHostName()); + request.setTimestamp(System.currentTimeMillis()); + FlatEngine flatEngine = FlatManager.getInstance().getFlatEngine(engine); + request.setMd5(flatEngine.getMd5()); + request.setTraceId(trace.getTraceId()); + request.setEngineName(trace.getEngineName()); + request.setSuccess(trace.getEx() == null); + request.setTraceTime(trace.getTraceTime()); + request.setEndTime(trace.getEndTime()); + if (!request.getSuccess()) { + request.setEx(serialExToString(trace.getEx())); + } + request.setRequest(toJSON(trace.getRequest())); + request.setResult(toJSON(trace.getResult())); + + if (flatEngine.getReportContent()) { + request.setContent(flatEngine.getContent()); + } + + JSONArray ja = new JSONArray(); + + trace.getComponents().forEach((k, v) -> { + JSONObject item = new JSONObject(); + item.put("name", k.getName()); + item.put("type", k.getType()); + item.put("start", v.getStart()); + item.put("escape", v.getEscape()); + item.put("ex", serialExToString(v.getEx())); + item.put("rollbackStart", v.getRollbackStart()); + item.put("rollbackEnd", v.getRollbackEnd()); + + ja.add(item); + }); + + request.setJson(ja); + return request; + } + + private static String serialExToString(Throwable ex) { + if (ex == null) { + return null; + } + + int maxDepth = ManagerConfiguration.reportMaxStackDepth; + StackTraceElement[] stackTrace = ex.getStackTrace(); + if (stackTrace.length > maxDepth) { + StackTraceElement[] newTrace = new StackTraceElement[maxDepth]; + System.arraycopy(stackTrace, 0, newTrace, 0, newTrace.length); + ex.setStackTrace(newTrace); + } + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(bos); + ex.printStackTrace(writer); + writer.flush(); + return bos.toString(); + } + + private static String toJSON(Object obj) { + return obj == null ? null : JSON.toJSONString(obj); + } + +} -- Gitee From e4643777dd3b05cdf777c7164a542750d6e819fc Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 8 Aug 2023 11:31:59 +0800 Subject: [PATCH 06/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20traceCollect?= =?UTF-8?q?or=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- .../manager/trace/DefaultTraceCollector.java | 134 ++++++++++++++++++ .../flow/manager/trace/TraceCollector.java | 129 +---------------- 2 files changed, 140 insertions(+), 123 deletions(-) create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java new file mode 100644 index 0000000..e0b87bc --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java @@ -0,0 +1,134 @@ +package org.smartboot.flow.manager.trace; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.ExecutionListenerRegistry; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.manager.NamedThreadFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author qinluo + * @date 2023-02-07 + * @since 1.0.7 + */ +public class DefaultTraceCollector implements TraceCollector { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTraceCollector.class); + private final ScheduledThreadPoolExecutor executorService = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("export-trace")); + + /** + * Report idle in mills. + */ + protected long idle = 5000L; + private Double radio; + private TraceSampleStrategy sampleStrategy; + private ManagerExecutionListener executionListener; + + private Map headers; + private final BlockingQueue traceQueue = new ArrayBlockingQueue<>(20000); + private final List reporters = new ArrayList<>(8); + + public long getIdle() { + return idle; + } + + public void setIdle(long idle) { + AssertUtil.isTrue(idle > 0, "idle must great than zero"); + this.idle = idle; + } + + public void addReporter(TraceReporter reporter) { + reporters.add(reporter); + } + + public void removeReporter(TraceReporter reporter) { + reporters.remove(reporter); + } + + public void removeAll() { + reporters.clear(); + } + + public void setReporters(List reporters) { + this.reporters.addAll(reporters); + } + + public void export() { + try { + this.doExport(); + } catch (Throwable ex){ + LOGGER.error("report trace failed", ex); + } + } + + public void doExport() { + List traces = new ArrayList<>(); + if (traceQueue.drainTo(traces) < 0) { + return; + } + + for (TraceData trace : traces) { + for (TraceReporter reporter : reporters) { + reporter.report(trace); + } + + } + } + + public void start() { + // Register listener. + if (sampleStrategy == null && radio != null && radio > 0 && radio <= 1) { + sampleStrategy = new TraceSampleStrategy(); + sampleStrategy.setRadio(radio); + } + + executionListener = new ManagerExecutionListener(this, sampleStrategy); + ExecutionListenerRegistry.register(executionListener); + executorService.setMaximumPoolSize(1); + executorService.scheduleAtFixedRate(this::export, idle, idle, TimeUnit.MILLISECONDS); + } + + @Override + public void submit(TraceData item) { + //noinspection ResultOfMethodCallIgnored + traceQueue.offer(item); + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public Double getRadio() { + return radio; + } + + public void setRadio(Double radio) { + this.radio = radio; + if (sampleStrategy != null && radio != null && radio > 0 && radio <= 1) { + sampleStrategy.setRadio(radio); + } + } + + public TraceSampleStrategy getSampleStrategy() { + return sampleStrategy; + } + + public void setSampleStrategy(TraceSampleStrategy sampleStrategy) { + this.sampleStrategy = sampleStrategy; + if (this.executionListener != null) { + this.executionListener.setSampleStrategy(this.sampleStrategy); + } + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java index ba8a5b5..cdf80b5 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/TraceCollector.java @@ -1,133 +1,16 @@ package org.smartboot.flow.manager.trace; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smartboot.flow.core.ExecutionListenerRegistry; -import org.smartboot.flow.core.util.AssertUtil; -import org.smartboot.flow.manager.NamedThreadFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - /** * @author qinluo * @date 2023-02-07 - * @since 1.0.7 + * @since 1.1.3 */ -public class TraceCollector { - - private static final Logger LOGGER = LoggerFactory.getLogger(TraceCollector.class); - private final ScheduledThreadPoolExecutor executorService = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("export-trace")); +public interface TraceCollector { /** - * Report idle in mills. + * Submit trace data to TraceCollector. + * + * @param traceData traceData. */ - protected long idle = 5000L; - private Double radio; - private TraceSampleStrategy sampleStrategy; - private ManagerExecutionListener executionListener; - - private Map headers; - private final BlockingQueue traceQueue = new ArrayBlockingQueue<>(20000); - private final List reporters = new ArrayList<>(8); - - public long getIdle() { - return idle; - } - - public void setIdle(long idle) { - AssertUtil.isTrue(idle > 0, "idle must great than zero"); - this.idle = idle; - } - - public void addReporter(TraceReporter reporter) { - reporters.add(reporter); - } - - public void removeReporter(TraceReporter reporter) { - reporters.remove(reporter); - } - - public void removeAll() { - reporters.clear(); - } - - public void setReporters(List reporters) { - this.reporters.addAll(reporters); - } - - public void export() { - try { - this.doExport(); - } catch (Throwable ex){ - LOGGER.error("report trace failed", ex); - } - } - - public void doExport() { - List traces = new ArrayList<>(); - if (traceQueue.drainTo(traces) < 0) { - return; - } - - for (TraceData trace : traces) { - for (TraceReporter reporter : reporters) { - reporter.report(trace); - } - - } - } - - public void start() { - // Register listener. - if (sampleStrategy == null && radio != null && radio > 0 && radio <= 1) { - sampleStrategy = new TraceSampleStrategy(); - sampleStrategy.setRadio(radio); - } - - executionListener = new ManagerExecutionListener(this, sampleStrategy); - ExecutionListenerRegistry.register(executionListener); - executorService.setMaximumPoolSize(1); - executorService.scheduleAtFixedRate(this::export, idle, idle, TimeUnit.MILLISECONDS); - } - - public void submit(TraceData item) { - //noinspection ResultOfMethodCallIgnored - traceQueue.offer(item); - } - - public Map getHeaders() { - return headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - - public Double getRadio() { - return radio; - } - - public void setRadio(Double radio) { - this.radio = radio; - if (sampleStrategy != null && radio != null && radio > 0 && radio <= 1) { - sampleStrategy.setRadio(radio); - } - } - - public TraceSampleStrategy getSampleStrategy() { - return sampleStrategy; - } - - public void setSampleStrategy(TraceSampleStrategy sampleStrategy) { - this.sampleStrategy = sampleStrategy; - if (this.executionListener != null) { - this.executionListener.setSampleStrategy(this.sampleStrategy); - } - } + void submit(TraceData traceData); } -- Gitee From cbfe3a29b5547bf19b605287c3e5cccd057054fa Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 8 Aug 2023 15:15:02 +0800 Subject: [PATCH 07/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E6=9B=B4?= =?UTF-8?q?=E5=AE=BD=E6=9D=BE=E7=9A=84=E8=A7=A3=E6=9E=90=20=20=20=20=20=20?= =?UTF-8?q?-=20=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE=E4=BA=A4=E7=94=B1sprin?= =?UTF-8?q?g=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- .../smart/flow/admin/controller/WebUtils.java | 2 + .../flow/core/attribute/Attributes.java | 14 +++---- .../flow/core/manager/ComponentModel.java | 15 +++++++ .../manager/RegisteredComponentVisitor.java | 7 ++++ .../core/parser/BuilderDefinitionVisitor.java | 5 +++ .../flow/helper/mock/FakeValueResolver.java | 39 +++++++++++++++++++ smart-flow-spring-extension/pom.xml | 1 + .../extension/BeanDefinitionVisitor.java | 11 +----- 8 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeValueResolver.java diff --git a/smart-flow-admin/src/main/java/org/smartboot/smart/flow/admin/controller/WebUtils.java b/smart-flow-admin/src/main/java/org/smartboot/smart/flow/admin/controller/WebUtils.java index 01fc33c..0809d91 100644 --- a/smart-flow-admin/src/main/java/org/smartboot/smart/flow/admin/controller/WebUtils.java +++ b/smart-flow-admin/src/main/java/org/smartboot/smart/flow/admin/controller/WebUtils.java @@ -5,6 +5,7 @@ import org.smartboot.flow.core.exception.FlowException; import org.smartboot.flow.core.parser.DefaultParser; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.helper.mock.FakeObjectCreator; +import org.smartboot.flow.helper.mock.FakeValueResolver; import java.io.ByteArrayInputStream; import java.net.URLDecoder; @@ -21,6 +22,7 @@ public final class WebUtils { public static FlowEngine parseValidate(String content, boolean decodeIfNecessary) { DefaultParser parser = new DefaultParser(); parser.setObjectCreator(new FakeObjectCreator()); + parser.setAttributeValueResolver(new FakeValueResolver()); try { if (decodeIfNecessary) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java index ad293f7..0290bdc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java @@ -21,7 +21,6 @@ public enum Attributes { NAME("name", "组件名称", String.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setName((String) value); } }, @@ -29,7 +28,6 @@ public enum Attributes { ROLLBACK("rollback", "是否开启回滚", Boolean.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setRollback((Boolean) value); } }, @@ -37,7 +35,6 @@ public enum Attributes { DEGRADABLE("degradable", "是否开启降级", Boolean.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setDegradable((Boolean) value); } }, @@ -45,7 +42,6 @@ public enum Attributes { ASYNC("async", "是否开启异步", Boolean.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setAsync((Boolean) value); } }, @@ -53,7 +49,6 @@ public enum Attributes { TIMEOUT("timeout", "异步超时时间", Long.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setTimeout(((Number) value).longValue()); } }, @@ -61,7 +56,6 @@ public enum Attributes { DEPENDS_ON("dependsOn", "依赖的异步组件", List.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); //noinspection unchecked component.setDependsOn((List)value); } @@ -75,7 +69,6 @@ public enum Attributes { ENABLED("enabled", "启用开关", Boolean.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setEnabled((Boolean) value); } }, @@ -88,7 +81,6 @@ public enum Attributes { DEGRADE_CALLBACK("degrade-callback", "降级回调", DegradeCallback.class) { @Override public void apply(Component component, Object value) { - super.apply(component, value); component.setDegradeCallback((DegradeCallback) value); } }, @@ -140,12 +132,16 @@ public enum Attributes { return name; } + public Class getAccept() { + return accept; + } + public boolean accept(Object value) { return accept.isInstance(value); } public void apply(Component component, Object value) { - component.addAttribute(AttributeHolder.of(this, value)); + } public boolean isVisible() { 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 34cf89b..8aef0c2 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 @@ -6,6 +6,7 @@ import org.smartboot.flow.core.common.Uniqueness; import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.component.Component; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,6 +25,7 @@ public class ComponentModel extends Uniqueness { private final Map components = new ConcurrentHashMap<>(); private final ComponentType type; PipelineModel pipeline; + private List holders = new ArrayList<>(); ComponentModel(ComponentType type, String name) { this.name = name; @@ -31,6 +33,10 @@ public class ComponentModel extends Uniqueness { this.identifier = name; } + public void setHolders(List holders) { + this.holders = holders; + } + Map collect() { this.component.setName(name); if (type == ComponentType.SUBPROCESS) { @@ -57,13 +63,22 @@ public class ComponentModel extends Uniqueness { @SuppressWarnings("unchecked") public void changeAttributes(List holders) { AttributeValueResolver valueResolver = AttributeValueResolver.getInstance(); + List backup = new ArrayList<>(this.holders); + try { holders.forEach(p -> { Object resolvedValue = valueResolver.resolve(p.getAttribute(), p.getValue()); p.getAttribute().apply(component, resolvedValue); + // Remove and add new. + backup.removeIf(o -> p.getAttribute() == o.getAttribute()); + backup.add(p); }); + } catch (Exception ignored) { + } finally { + this.holders.clear(); + this.holders.addAll(backup); } } 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 2a9418b..ec5f852 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,11 +1,13 @@ package org.smartboot.flow.core.manager; +import org.smartboot.flow.core.attribute.AttributeHolder; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.smartboot.flow.core.visitor.ComponentVisitor; import org.smartboot.flow.core.visitor.PipelineVisitor; +import java.util.List; import java.util.Set; /** @@ -66,4 +68,9 @@ public class RegisteredComponentVisitor extends ComponentVisitor { this.model.addComponent(model); return new RegisteredComponentVisitor(model, visited, allocator); } + + @Override + public void visitAttributes(List attributes) { + this.model.setHolders(attributes); + } } 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 7a3f899..a78492c 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 @@ -149,6 +149,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { this.collect(ed.getPipeline(), (pipelineComponent::setPipeline)); } pipelineComponent.setAttributeMap(ed.getAttributeMap()); + pipelineComponent.setAttributes(ed.getAttributes()); this.namedComponents.put(engineName, pipelineComponent); } @@ -192,6 +193,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { .withResolver(valueResolver) .apply(ed.getAttributes()) .build(); + component.setAttributes(ed.getAttributes()); component.setAttributeMap(ed.getAttributeMap()); namedComponents.put(ed.getIdentifier(), component); } @@ -252,6 +254,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { Component build = Builders.newIf().test(condition).withResolver(valueResolver) .apply(ed.getAttributes()).then(then).otherwise(elseBranch).build(); build.setAttributeMap(ed.getAttributeMap()); + build.setAttributes(ed.getAttributes()); this.namedComponents.put(ed.getIdentifier(), build); } @@ -310,6 +313,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { ChooseComponent build = chooseBuilder.build(); build.setAllBranchWasString(true); build.setAttributeMap(ed.getAttributeMap()); + build.setAttributes(ed.getAttributes()); this.namedComponents.put(ed.getIdentifier(), build); } @@ -331,6 +335,7 @@ public class BuilderDefinitionVisitor implements DefinitionVisitor { AdapterComponent adapterComponent = adapterBuilder.build(); adapterComponent.setAttributeMap(ed.getAttributeMap()); + adapterComponent.setAttributes(ed.getAttributes()); this.namedComponents.put(ed.getIdentifier(), adapterComponent); } diff --git a/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeValueResolver.java b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeValueResolver.java new file mode 100644 index 0000000..9e3f615 --- /dev/null +++ b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/mock/FakeValueResolver.java @@ -0,0 +1,39 @@ +package org.smartboot.flow.helper.mock; + +import org.smartboot.flow.core.attribute.AttributeValueResolver; +import org.smartboot.flow.core.attribute.Attributes; + +/** + * Fake value resolver + * + * @author qinluo + * @date 2023/1/27 12:35 + * @since 1.1.3 + */ +public class FakeValueResolver extends AttributeValueResolver { + + public FakeValueResolver() { + this.setObjectCreator(new FakeObjectCreator()); + } + + @Override + public Object resolve(Attributes attribute, Object value) { + try { + return super.resolve(attribute, value); + } catch (Exception ignored) { + + } + + // Miss parsed, as default value. + Class accepted = attribute.getAccept(); + if (accepted == String.class) { + return String.valueOf(value); + } else if (accepted == Long.class) { + return 0L; + } else if (accepted == Boolean.class) { + return false; + } else { + return null; + } + } +} diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-spring-extension/pom.xml index 2c3a55b..7b2df02 100644 --- a/smart-flow-spring-extension/pom.xml +++ b/smart-flow-spring-extension/pom.xml @@ -15,6 +15,7 @@ 8 8 5.3.23 + UTF-8 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 1b30515..39dfc06 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -1,7 +1,6 @@ package org.smartboot.flow.spring.extension; import org.smartboot.flow.core.attribute.AttributeHolder; -import org.smartboot.flow.core.attribute.AttributeValueResolver; import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.executable.DecorateExecutable; import org.smartboot.flow.core.parser.DefinitionVisitor; @@ -167,23 +166,15 @@ public class BeanDefinitionVisitor implements DefinitionVisitor, BeanFactoryAwar private void appendAttributes(ComponentDefinition ed, RootBeanDefinition definition) { List attributes = ed.getAttributes(); - AttributeValueResolver resolver = AttributeValueResolver.getInstance(); for (AttributeHolder holder : attributes) { Attributes attribute = holder.getAttribute(); - - try { - Object resolved = resolver.resolve(attribute, holder.getValue()); - holder.setValue(resolved); - } catch (Exception ignored) { - - } - if (attribute == Attributes.NAME || attribute == Attributes.DEGRADE_CALLBACK || !attribute.isVisible()) { continue; } + PropertyValue value = new PropertyValue(attribute.getName(), holder.getValue()); definition.getPropertyValues().addPropertyValue(value); } -- Gitee From 199d04401384ac6c20226c8ee1d80f642ff62466 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 8 Aug 2023 18:04:06 +0800 Subject: [PATCH 08/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20reloader?= =?UTF-8?q?=E7=BB=84=E8=A3=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- .../manager/reload/MemoryXmlSelector.java | 35 +++++++++++++++++++ .../flow/manager/reload/XmlParseReloader.java | 18 ++++++++++ .../SmartFlowBeanFactoryRegistry.java | 19 ++++++++++ .../spring/extension/SmartFlowRegistrar.java | 17 +++++++++ .../extension/FlowReloadConfiguration.java | 10 ------ 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/MemoryXmlSelector.java diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/MemoryXmlSelector.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/MemoryXmlSelector.java new file mode 100644 index 0000000..b509c64 --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/MemoryXmlSelector.java @@ -0,0 +1,35 @@ +package org.smartboot.flow.manager.reload; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author qinluo + * @date 2022-12-21 16:36:25 + * @since 1.1.3 + */ +public class MemoryXmlSelector implements XmlSelector { + + private static final Map contentMap = new ConcurrentHashMap<>(); + static XmlSelector INSTANCE = new MemoryXmlSelector(); + + private MemoryXmlSelector() { + + } + + @Override + public String select(String engineName) { + return contentMap.get(engineName); + } + + /* + Static methods. + */ + public static void updateContent(String engine, String content) { + contentMap.put(engine, content); + } + + public static String remove(String engine) { + return contentMap.remove(engine); + } +} diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java index b04a404..935f44d 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java @@ -7,6 +7,7 @@ import org.smartboot.flow.core.parser.DefaultParser; import org.smartboot.flow.core.parser.DefinitionVisitor; import org.smartboot.flow.core.parser.ObjectCreator; import org.smartboot.flow.core.parser.ParserContext; +import org.smartboot.flow.core.util.AssertUtil; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -24,6 +25,8 @@ public class XmlParseReloader extends AbstractReloader { protected boolean assemble; protected DefinitionVisitor visitor; private XmlSelector xmlSelector; + private boolean useMemory = true; + private final XmlSelector memoryXmlSelector = MemoryXmlSelector.INSTANCE; public void setXmlSelector(XmlSelector xmlSelector) { this.xmlSelector = xmlSelector; @@ -41,8 +44,23 @@ public class XmlParseReloader extends AbstractReloader { this.visitor = visitor; } + public boolean getUseMemory() { + return useMemory; + } + + public void setUseMemory(boolean useMemory) { + this.useMemory = useMemory; + } + @Override public void doReload(String engineName) { + XmlSelector selector = xmlSelector; + if (selector == null && useMemory) { + selector = memoryXmlSelector; + } + + AssertUtil.notNull(selector, "selector must not be null!"); + // select config. String xml = xmlSelector.select(engineName); if (xml == null || xml.trim().length() == 0) { diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java index 559dfd8..d4a68e7 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java @@ -1,11 +1,18 @@ package org.smartboot.flow.spring.extension; import org.smartboot.flow.core.parser.ParserContext; +import org.smartboot.flow.core.util.AuxiliaryUtils; +import org.smartboot.flow.manager.reload.XmlParseReloader; import org.springframework.beans.BeansException; +import org.springframework.beans.PropertyValue; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; +import java.util.Iterator; + /** * @author qinluo * @date 2023/3/12 12:41 @@ -22,6 +29,18 @@ public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostP @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + Iterator beanNamesIterator = beanFactory.getBeanNamesIterator(); + beanNamesIterator.forEachRemaining(p -> { + BeanDefinition beanDefinition = beanFactory.getBeanDefinition(p); + Class type = AuxiliaryUtils.asClass(beanDefinition.getBeanClassName()); + if (type != null && XmlParseReloader.class.isAssignableFrom(type)) { + PropertyValue visitor = beanDefinition.getPropertyValues().getPropertyValue("visitor"); + if (visitor == null) { + beanDefinition.getPropertyValues().addPropertyValue("visitor", new RuntimeBeanReference(SmartFlowRegistrar.SPRING_VISITOR)); + } + } + }); + try { // Touch visit all parsed elements after all bean definition loaded. ParserContext ctx = ProxyParser.getInstance().getContext(); diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java index abadd1f..2b2638e 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java @@ -1,5 +1,7 @@ package org.smartboot.flow.spring.extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -15,6 +17,8 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { private static final String NOTIFIER_PROCESS = "smart-flow-notifer-processor"; private static final String REGISTRY_NAME = "smart-flow-registry-processor"; + public static final String SPRING_VISITOR = "smart-flow-spring-visitor"; + private static final Logger LOGGER = LoggerFactory.getLogger(SmartFlowRegistrar.class); @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) { @@ -24,6 +28,7 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { public static void registerAll(BeanDefinitionRegistry registry) { registerNotifier(registry); registerRegistry(registry); + registryVisitor(registry); } private static void registerNotifier(BeanDefinitionRegistry registry) { @@ -33,6 +38,7 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { RootBeanDefinition definition = new RootBeanDefinition(); definition.setBeanClass(NotifierProcessor.class); registry.registerBeanDefinition(NOTIFIER_PROCESS, definition); + LOGGER.info("register {}", NOTIFIER_PROCESS); } private static void registerRegistry(BeanDefinitionRegistry registry) { @@ -42,5 +48,16 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { RootBeanDefinition definition = new RootBeanDefinition(); definition.setBeanClass(SmartFlowBeanFactoryRegistry.class); registry.registerBeanDefinition(REGISTRY_NAME, definition); + LOGGER.info("register {}", REGISTRY_NAME); + } + + private static void registryVisitor(BeanDefinitionRegistry registry) { + if (registry.containsBeanDefinition(SPRING_VISITOR)) { + return; + } + RootBeanDefinition definition = new RootBeanDefinition(); + definition.setBeanClass(BeanDefinitionVisitor.class); + registry.registerBeanDefinition(SPRING_VISITOR, definition); + LOGGER.info("register {}", SPRING_VISITOR); } } diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java index fad3f1a..8fd1635 100644 --- a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java +++ b/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java @@ -7,7 +7,6 @@ import org.smartboot.flow.manager.reload.XmlParseReloader; import org.smartboot.flow.manager.reload.XmlSelector; import org.smartboot.flow.spring.extension.BeanDefinitionVisitor; import org.smartboot.flow.spring.extension.SpringObjectCreator; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -93,14 +92,6 @@ public class FlowReloadConfiguration { return soc; } - @ConditionalOnMissingBean(BeanDefinitionVisitor.class) - @Bean("beanDefVisitor") - public BeanDefinitionVisitor getVisitor(ApplicationContext ctx) { - BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(); - visitor.setBeanFactory(ctx); - return visitor; - } - @ConditionalOnProperty(name = "smart.flow.manage.reload.datasource.url") @Bean("xmlSelector") public XmlSelector getXmlSelector() { @@ -117,7 +108,6 @@ public class FlowReloadConfiguration { } @Bean - @ConditionalOnBean(XmlSelector.class) public Reloader getReloader(ApplicationContext ctx) { XmlParseReloader reloader = new XmlParseReloader(); reloader.setAssemble(assemble); -- Gitee From e70da708fceaa04c888c7462bd017e8658720fcf Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Tue, 8 Aug 2023 18:16:27 +0800 Subject: [PATCH 09/20] qinluo: - fix registry Signed-off-by: qinluo <1558642210@qq.com> --- .../flow/spring/extension/SmartFlowBeanFactoryRegistry.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java index d4a68e7..3e22465 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java +++ b/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java @@ -11,7 +11,7 @@ import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import java.util.Iterator; +import java.util.stream.Stream; /** * @author qinluo @@ -29,8 +29,8 @@ public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostP @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - Iterator beanNamesIterator = beanFactory.getBeanNamesIterator(); - beanNamesIterator.forEachRemaining(p -> { + String[] beanNames = beanFactory.getBeanDefinitionNames(); + Stream.of(beanNames).forEach(p -> { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(p); Class type = AuxiliaryUtils.asClass(beanDefinition.getBeanClassName()); if (type != null && XmlParseReloader.class.isAssignableFrom(type)) { -- Gitee From 0d4a8769bec801881caeaffee4bdee4b8364603c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 9 Aug 2023 18:13:38 +0800 Subject: [PATCH 10/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0nacos=E9=80=9A=E7=9F=A5=E9=80=82=E9=85=8D=20=20=20=20?= =?UTF-8?q?=20=20-=20spring=E9=9B=86=E6=88=90=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- pom.xml | 3 +- .../flow/core/manager/EngineManager.java | 18 +++ .../flow/core/parser/ThreadPoolCreator.java | 2 +- .../smartboot/flow/core/util/BeanContext.java | 27 +++++ .../smartboot/flow/core/util/BeanUtils.java | 31 +++++ smart-flow-integration/pom.xml | 25 ++++ .../smart-flow-integration-nacos/pom.xml | 40 +++++++ .../flow/integration/nacos/NacosFlowUtil.java | 51 ++++++++ .../flow/integration/nacos/NacosWatcher.java | 112 ++++++++++++++++++ .../smart-flow-spring-extension}/pom.xml | 2 +- .../extension/BeanDefinitionRegister.java | 0 .../extension/BeanDefinitionVisitor.java | 0 .../flow/spring/extension/EasySmartFlow.java | 2 +- .../spring/extension/EngineInitializer.java | 0 .../spring/extension/NameAwareCondition.java | 0 .../extension/NamedAbstractExecutable.java | 0 .../spring/extension/NotifierProcessor.java | 0 .../flow/spring/extension/ProxyParser.java | 0 .../spring/extension/ReflectionNotifier.java | 0 .../flow/spring/extension/ReloadNotify.java | 0 .../SmartFlowBeanFactoryRegistry.java | 5 + .../spring/extension/SmartFlowRegistrar.java | 62 ++++------ .../extension/SpringBeanContextAdapter.java | 47 ++++++++ .../extension/SpringIdentifierManager.java | 0 .../extension/SpringNamespaceHandler.java | 0 .../spring/extension/SpringObjectCreator.java | 0 .../main/resources/META-INF/spring.handlers | 0 .../main/resources/META-INF/spring.schemas | 0 .../smart-flow-springboot-starter}/pom.xml | 2 +- .../FlowHttpManageConfiguration.java | 0 .../FlowHttpReportConfiguration.java | 0 .../FlowInitializerConfiguration.java | 0 .../extension/FlowReloadConfiguration.java | 46 ------- .../main/resources/META-INF/spring.factories | 0 .../flow/manager/reload/XmlParseReloader.java | 17 +-- 35 files changed, 392 insertions(+), 100 deletions(-) create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java create mode 100644 smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java create mode 100644 smart-flow-integration/pom.xml create mode 100644 smart-flow-integration/smart-flow-integration-nacos/pom.xml create mode 100644 smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosFlowUtil.java create mode 100644 smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/pom.xml (96%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java (100%) rename smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EnableReloadNotify.java => smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EasySmartFlow.java (92%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/ReloadNotify.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java (88%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java (34%) create mode 100644 smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/SpringIdentifierManager.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/resources/META-INF/spring.handlers (100%) rename {smart-flow-spring-extension => smart-flow-integration/smart-flow-spring-extension}/src/main/resources/META-INF/spring.schemas (100%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/pom.xml (95%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java (100%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java (100%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java (100%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java (61%) rename {smart-flow-springboot-starter => smart-flow-integration/smart-flow-springboot-starter}/src/main/resources/META-INF/spring.factories (100%) diff --git a/pom.xml b/pom.xml index 1fc11b8..c46befd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,13 +13,12 @@ smart-flow-core - smart-flow-spring-extension smart-flow-manager smart-flow-script - smart-flow-springboot-starter smart-flow-helper smart-flow-admin smart-flow-plugin + smart-flow-integration 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 ec449bf..bd826c0 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 @@ -83,4 +83,22 @@ public interface EngineManager { static EngineManager defaultManager() { return DefaultEngineManager.getInstance(); } + + /* Static delegate methods */ + + /** + * @since 1.1.3 + * + * @param name engine name. + * @param request generic type + * @param response generic type + * @return engine + */ + static FlowEngine getEngine(String name) { + EngineModel model = DefaultEngineManager.getInstance().getEngineModel(name); + if (model != null) { + return model.getSource(); + } + return null; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ThreadPoolCreator.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ThreadPoolCreator.java index 078d97b..3ac153f 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ThreadPoolCreator.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ThreadPoolCreator.java @@ -43,7 +43,7 @@ public class ThreadPoolCreator { executor.setThreadFactory(new NamedThreadFactory(attr.getValue())); break; case "prestartAllCoreThreads": - prestartAllCoreThreads = true; + prestartAllCoreThreads = Boolean.parseBoolean(attr.getValue()); break; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java new file mode 100644 index 0000000..84f616f --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java @@ -0,0 +1,27 @@ +package org.smartboot.flow.core.util; + +import java.util.List; + +/** + * @author qinluo + * @date 2023-08-09 11:39:16 + * @since 1.1.3 + */ +public interface BeanContext { + + default T getBean(String name) { + throw new UnsupportedOperationException(); + } + + default T getBean(String name, Class type) { + throw new UnsupportedOperationException(); + } + + default List getBean(Class type) { + throw new UnsupportedOperationException(); + } + + default void init() { + BeanUtils.init(this); + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java new file mode 100644 index 0000000..0b8b6a9 --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java @@ -0,0 +1,31 @@ +package org.smartboot.flow.core.util; + +import java.util.List; + +/** + * @author qinluo + * @date 2023-08-09 11:36:35 + * @since 1.1.3 + */ +public class BeanUtils { + + private static BeanContext instance = null; + + public static T getBean(String name) { + return instance.getBean(name); + } + + public static T getBean(String name, Class type) { + return instance.getBean(name, type); + } + + public static T getBean(Class type) { + List beans = instance.getBean(type); + return beans != null && beans.size() > 0 ? beans.get(0) : null; + } + + static void init(BeanContext ctx) { + instance = ctx; + } + +} diff --git a/smart-flow-integration/pom.xml b/smart-flow-integration/pom.xml new file mode 100644 index 0000000..ce45ea1 --- /dev/null +++ b/smart-flow-integration/pom.xml @@ -0,0 +1,25 @@ + + + + smart-flow-parent + org.smartboot.flow + 1.1.3-SNAPSHOT + + 4.0.0 + + smart-flow-integration + pom + + smart-flow-integration-nacos + smart-flow-spring-extension + smart-flow-springboot-starter + + + + 8 + 8 + + + \ No newline at end of file diff --git a/smart-flow-integration/smart-flow-integration-nacos/pom.xml b/smart-flow-integration/smart-flow-integration-nacos/pom.xml new file mode 100644 index 0000000..755a726 --- /dev/null +++ b/smart-flow-integration/smart-flow-integration-nacos/pom.xml @@ -0,0 +1,40 @@ + + + + smart-flow-integration + org.smartboot.flow + 1.1.3-SNAPSHOT + + 4.0.0 + + smart-flow-integration-nacos + + + 8 + 8 + + + + + org.smartboot.flow + smart-flow-manager + ${smart-flow.version} + + + + com.alibaba.nacos + nacos-client + 2.1.1 + + + + com.alibaba.nacos + nacos-spring-context + 1.1.1 + provided + + + + \ No newline at end of file diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosFlowUtil.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosFlowUtil.java new file mode 100644 index 0000000..d79610d --- /dev/null +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosFlowUtil.java @@ -0,0 +1,51 @@ +package org.smartboot.flow.integration.nacos; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.spring.beans.factory.annotation.ConfigServiceBeanBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.util.BeanUtils; + +import java.util.Map; +import java.util.Properties; + +/** + * @author qinluo + * @date 2023-08-09 14:09:03 + * @since 1.1.3 + */ +class NacosFlowUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(NacosFlowUtil.class); + + static ConfigService createCfgService(Map properties) { + // 检查从bean上下文中是否能获取到configServiceFactory. + ConfigService cfgService = createWithBeanCtx(properties); + + try { + if (cfgService == null) { + Properties prop = new Properties(); + prop.putAll(properties); + return NacosFactory.createConfigService(prop); + } + } catch (Exception e) { + LOGGER.error("create nacos config service failed, properties = {}", properties, e); + } + + return cfgService; + } + + + private static ConfigService createWithBeanCtx(Map properties) { + + try { + ConfigServiceBeanBuilder beanBuilder = BeanUtils.getBean(ConfigServiceBeanBuilder.BEAN_NAME); + return beanBuilder.build(properties); + } catch (Throwable ignored) { + + } + + return null; + } +} diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java new file mode 100644 index 0000000..db2f598 --- /dev/null +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java @@ -0,0 +1,112 @@ +package org.smartboot.flow.integration.nacos; + +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.AbstractListener; +import com.alibaba.nacos.api.exception.NacosException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.core.util.BeanUtils; +import org.smartboot.flow.manager.reload.MemoryXmlSelector; +import org.smartboot.flow.manager.reload.Reloader; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +/** + * @author qinluo + * @date 2023-08-09 10:44:55 + * @since 1.1.3 + */ +public class NacosWatcher { + + private static final Logger LOGGER = LoggerFactory.getLogger(NacosWatcher.class); + + private ConfigService configService; + + private Reloader reloader; + + private String dataId; + private String engine; + private String groupId = "DEFAULT_GROUP"; + private Map nacosProperties = new HashMap<>(); + + private void init() { + if (configService == null) { + configService = NacosFlowUtil.createCfgService(nacosProperties); + AssertUtil.notNull(configService, "nacos config service must not be null!"); + } + + if (reloader == null) { + reloader = BeanUtils.getBean(Reloader.class); + AssertUtil.notNull(reloader, "nacos reloader must not be null!"); + } + } + + @PostConstruct + public void start() { + init(); + + try { + configService.addListener(dataId, groupId, new AbstractListener() { + @Override + public void receiveConfigInfo(String configInfo) { + MemoryXmlSelector.updateContent(engine, configInfo); + reloader.reload(engine); + } + }); + } catch (NacosException e) { + LOGGER.error("add nacos watcher failed, groupId = {}, dataId = {}, engine = {}", groupId, dataId, engine, e); + } + + } + + public String getDataId() { + return dataId; + } + + public void setDataId(String dataId) { + this.dataId = dataId; + } + + public String getEngine() { + return engine; + } + + public void setEngine(String engine) { + this.engine = engine; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public Map getNacosProperties() { + return nacosProperties; + } + + public void setNacosProperties(Map nacosProperties) { + this.nacosProperties = nacosProperties; + } + + public ConfigService getConfigService() { + return configService; + } + + public void setConfigService(ConfigService configService) { + this.configService = configService; + } + + public Reloader getReloader() { + return reloader; + } + + public void setReloader(Reloader reloader) { + this.reloader = reloader; + } +} diff --git a/smart-flow-spring-extension/pom.xml b/smart-flow-integration/smart-flow-spring-extension/pom.xml similarity index 96% rename from smart-flow-spring-extension/pom.xml rename to smart-flow-integration/smart-flow-spring-extension/pom.xml index 7b2df02..7a8bf03 100644 --- a/smart-flow-spring-extension/pom.xml +++ b/smart-flow-integration/smart-flow-spring-extension/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - smart-flow-parent + smart-flow-integration org.smartboot.flow 1.1.3-SNAPSHOT diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionRegister.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EnableReloadNotify.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EasySmartFlow.java similarity index 92% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EnableReloadNotify.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EasySmartFlow.java index 1b8ea79..f2b47a6 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EnableReloadNotify.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EasySmartFlow.java @@ -17,5 +17,5 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Import(SmartFlowRegistrar.class) -public @interface EnableReloadNotify { +public @interface EasySmartFlow { } diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NameAwareCondition.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NamedAbstractExecutable.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ProxyParser.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReloadNotify.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReloadNotify.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReloadNotify.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReloadNotify.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java similarity index 88% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java index 3e22465..f1faeea 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java @@ -38,6 +38,11 @@ public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostP if (visitor == null) { beanDefinition.getPropertyValues().addPropertyValue("visitor", new RuntimeBeanReference(SmartFlowRegistrar.SPRING_VISITOR)); } + + PropertyValue creator = beanDefinition.getPropertyValues().getPropertyValue("objectCreator"); + if (creator == null) { + beanDefinition.getPropertyValues().addPropertyValue("objectCreator", new RuntimeBeanReference("smart-flow-default-object-creator")); + } } }); diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java similarity index 34% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java index 2b2638e..9b3c965 100644 --- a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java @@ -2,12 +2,15 @@ package org.smartboot.flow.spring.extension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.smartboot.flow.manager.reload.XmlParseReloader; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; +import java.util.HashMap; +import java.util.Map; + /** * @author qinluo * @date 2023/1/31 22:15 @@ -15,49 +18,34 @@ import org.springframework.core.type.AnnotationMetadata; */ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { - private static final String NOTIFIER_PROCESS = "smart-flow-notifer-processor"; - private static final String REGISTRY_NAME = "smart-flow-registry-processor"; public static final String SPRING_VISITOR = "smart-flow-spring-visitor"; private static final Logger LOGGER = LoggerFactory.getLogger(SmartFlowRegistrar.class); - @Override - public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) { - registerAll(registry); - } - - public static void registerAll(BeanDefinitionRegistry registry) { - registerNotifier(registry); - registerRegistry(registry); - registryVisitor(registry); - } + private static final Map> registeredClasses = new HashMap<>(); - private static void registerNotifier(BeanDefinitionRegistry registry) { - if (registry.containsBeanDefinition(NOTIFIER_PROCESS)) { - return; - } - RootBeanDefinition definition = new RootBeanDefinition(); - definition.setBeanClass(NotifierProcessor.class); - registry.registerBeanDefinition(NOTIFIER_PROCESS, definition); - LOGGER.info("register {}", NOTIFIER_PROCESS); + static { + registeredClasses.put("smart-flow-notifer-processor", NotifierProcessor.class); + registeredClasses.put("smart-flow-registry", SmartFlowBeanFactoryRegistry.class); + registeredClasses.put(SPRING_VISITOR, BeanDefinitionVisitor.class); + registeredClasses.put("smart-flow-default-object-creator", SpringObjectCreator.class); + registeredClasses.put("smart-flow-spring-bean-container", SpringBeanContextAdapter.class); + registeredClasses.put("smart-flow-spring-default-reloader", XmlParseReloader.class); } - private static void registerRegistry(BeanDefinitionRegistry registry) { - if (registry.containsBeanDefinition(REGISTRY_NAME)) { - return; - } - RootBeanDefinition definition = new RootBeanDefinition(); - definition.setBeanClass(SmartFlowBeanFactoryRegistry.class); - registry.registerBeanDefinition(REGISTRY_NAME, definition); - LOGGER.info("register {}", REGISTRY_NAME); + @Override + public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + registerAll(registry); } - private static void registryVisitor(BeanDefinitionRegistry registry) { - if (registry.containsBeanDefinition(SPRING_VISITOR)) { - return; - } - RootBeanDefinition definition = new RootBeanDefinition(); - definition.setBeanClass(BeanDefinitionVisitor.class); - registry.registerBeanDefinition(SPRING_VISITOR, definition); - LOGGER.info("register {}", SPRING_VISITOR); + public static void registerAll(BeanDefinitionRegistry registry) { + registeredClasses.forEach((k, v) -> { + if (registry.containsBeanDefinition(k)) { + return; + } + RootBeanDefinition definition = new RootBeanDefinition(); + definition.setBeanClass(v); + registry.registerBeanDefinition(k, definition); + LOGGER.info("register to spring container [{}]", k); + }); } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java new file mode 100644 index 0000000..ec4cc5d --- /dev/null +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java @@ -0,0 +1,47 @@ +package org.smartboot.flow.spring.extension; + +import org.smartboot.flow.core.util.BeanContext; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author qinluo + * @date 2022-12-21 14:22:23 + * @since 1.1.3 + */ +public class SpringBeanContextAdapter implements BeanContext, ApplicationContextAware, BeanPostProcessor { + + private ApplicationContext ctx; + + @Override + public T getBean(String name) { + return (T)ctx.getBean(name); + } + + @Override + public T getBean(String name, Class type) { + return ctx.getBean(name, type); + } + + @Override + public List getBean(Class type) { + String[] beanNamesForType = ctx.getBeanNamesForType(type); + List objects = new ArrayList<>(); + for (String name : beanNamesForType) { + objects.add(ctx.getBean(name, type)); + } + + return objects; + } + + @Override + public void setApplicationContext(ApplicationContext ctx) throws BeansException { + this.ctx = ctx; + this.init(); + } +} diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringIdentifierManager.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringIdentifierManager.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringIdentifierManager.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringIdentifierManager.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringNamespaceHandler.java diff --git a/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java similarity index 100% rename from smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java rename to smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java diff --git a/smart-flow-spring-extension/src/main/resources/META-INF/spring.handlers b/smart-flow-integration/smart-flow-spring-extension/src/main/resources/META-INF/spring.handlers similarity index 100% rename from smart-flow-spring-extension/src/main/resources/META-INF/spring.handlers rename to smart-flow-integration/smart-flow-spring-extension/src/main/resources/META-INF/spring.handlers diff --git a/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas b/smart-flow-integration/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas similarity index 100% rename from smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas rename to smart-flow-integration/smart-flow-spring-extension/src/main/resources/META-INF/spring.schemas diff --git a/smart-flow-springboot-starter/pom.xml b/smart-flow-integration/smart-flow-springboot-starter/pom.xml similarity index 95% rename from smart-flow-springboot-starter/pom.xml rename to smart-flow-integration/smart-flow-springboot-starter/pom.xml index 867d88b..c66a838 100644 --- a/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-integration/smart-flow-springboot-starter/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - smart-flow-parent + smart-flow-integration org.smartboot.flow 1.1.3-SNAPSHOT diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java similarity index 100% rename from smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java rename to smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java similarity index 100% rename from smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java rename to smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java similarity index 100% rename from smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java rename to smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java diff --git a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java similarity index 61% rename from smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java rename to smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java index 8fd1635..1d14eb2 100644 --- a/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java @@ -1,16 +1,9 @@ package org.smartboot.flow.springboot.extension; -import org.smartboot.flow.core.parser.ObjectCreator; -import org.smartboot.flow.manager.reload.Reloader; import org.smartboot.flow.manager.reload.SqlXmlSelector; -import org.smartboot.flow.manager.reload.XmlParseReloader; import org.smartboot.flow.manager.reload.XmlSelector; -import org.smartboot.flow.spring.extension.BeanDefinitionVisitor; -import org.smartboot.flow.spring.extension.SpringObjectCreator; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -82,16 +75,6 @@ public class FlowReloadConfiguration { } } - - @ConditionalOnProperty(name = "smart.flow.manage.reload.spring-object-creator", havingValue = "true") - @ConditionalOnMissingBean(ObjectCreator.class) - @Bean("springObjectCreator") - public ObjectCreator getSpringObjectCreator(ApplicationContext ctx) { - SpringObjectCreator soc = new SpringObjectCreator(); - soc.setApplicationContext(ctx); - return soc; - } - @ConditionalOnProperty(name = "smart.flow.manage.reload.datasource.url") @Bean("xmlSelector") public XmlSelector getXmlSelector() { @@ -107,35 +90,6 @@ public class FlowReloadConfiguration { return selector; } - @Bean - public Reloader getReloader(ApplicationContext ctx) { - XmlParseReloader reloader = new XmlParseReloader(); - reloader.setAssemble(assemble); - - try { - ObjectCreator creator = ctx.getBean(ObjectCreator.class); - reloader.setObjectCreator(creator); - } catch (Exception ignored) { - - } - - try { - XmlSelector selector = ctx.getBean(XmlSelector.class); - reloader.setXmlSelector(selector); - } catch (Exception ignored) { - - } - - try { - BeanDefinitionVisitor visitor = ctx.getBean(BeanDefinitionVisitor.class); - reloader.setVisitor(visitor); - } catch (Exception ignored) { - - } - - return reloader; - } - public void setAssemble(boolean assemble) { this.assemble = assemble; } diff --git a/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories similarity index 100% rename from smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories rename to smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java index 935f44d..44a7503 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/XmlParseReloader.java @@ -25,7 +25,6 @@ public class XmlParseReloader extends AbstractReloader { protected boolean assemble; protected DefinitionVisitor visitor; private XmlSelector xmlSelector; - private boolean useMemory = true; private final XmlSelector memoryXmlSelector = MemoryXmlSelector.INSTANCE; public void setXmlSelector(XmlSelector xmlSelector) { @@ -44,25 +43,21 @@ public class XmlParseReloader extends AbstractReloader { this.visitor = visitor; } - public boolean getUseMemory() { - return useMemory; - } - - public void setUseMemory(boolean useMemory) { - this.useMemory = useMemory; - } - @Override public void doReload(String engineName) { XmlSelector selector = xmlSelector; - if (selector == null && useMemory) { + if (selector == null) { selector = memoryXmlSelector; } AssertUtil.notNull(selector, "selector must not be null!"); // select config. - String xml = xmlSelector.select(engineName); + String xml = selector.select(engineName); + if (xml == null || xml.trim().length() == 0) { + xml = memoryXmlSelector.select(engineName); + } + if (xml == null || xml.trim().length() == 0) { throw new FlowException("load config " + engineName + " is empty"); } -- Gitee From 4090de475bbbd7800fe86dc833874672d8c96895 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 9 Aug 2023 19:00:18 +0800 Subject: [PATCH 11/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- .../flow/integration/nacos/NacosWatcher.java | 3 ++- .../flow/spring/extension/ReflectionNotifier.java | 10 ++-------- .../smartboot/flow/manager/reload/ReloadWatcher.java | 11 +++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/ReloadWatcher.java diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java index db2f598..ddd6176 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.core.util.BeanUtils; import org.smartboot.flow.manager.reload.MemoryXmlSelector; +import org.smartboot.flow.manager.reload.ReloadWatcher; import org.smartboot.flow.manager.reload.Reloader; import javax.annotation.PostConstruct; @@ -19,7 +20,7 @@ import java.util.Map; * @date 2023-08-09 10:44:55 * @since 1.1.3 */ -public class NacosWatcher { +public class NacosWatcher implements ReloadWatcher { private static final Logger LOGGER = LoggerFactory.getLogger(NacosWatcher.class); diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java index 4af2547..526ca49 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java @@ -2,7 +2,6 @@ package org.smartboot.flow.spring.extension; import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.manager.EngineManager; -import org.smartboot.flow.core.manager.EngineModel; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.smartboot.flow.manager.reload.ReloadListener; import org.springframework.beans.factory.BeanFactory; @@ -41,22 +40,17 @@ public class ReflectionNotifier implements ReloadListener { FlowEngine engineInstance = null; FlowEngine springEngine = null; - FlowEngine managerEngine = null; + FlowEngine managerEngine = EngineManager.getEngine(engineName); try { springEngine = (FlowEngine)factory.getBean(engineName); } catch (Exception ex) { // do-nothing } - EngineModel engineModel = EngineManager.defaultManager().getEngineModel(engineName); - if (engineModel != null) { - managerEngine = engineModel.getSource(); - } - if (springEngine == null ^ managerEngine == null) { engineInstance = AuxiliaryUtils.or(springEngine, managerEngine); } else if (springEngine != null) { - if (springEngine.getStartedAt() > managerEngine.getStartedAt()) { + if (springEngine.getStartedAt() >= managerEngine.getStartedAt()) { engineInstance = springEngine; } else if(springEngine.getStartedAt() < managerEngine.getStartedAt()){ engineInstance = managerEngine; diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/ReloadWatcher.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/ReloadWatcher.java new file mode 100644 index 0000000..3e9a47f --- /dev/null +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/reload/ReloadWatcher.java @@ -0,0 +1,11 @@ +package org.smartboot.flow.manager.reload; + +/** + * ReloadWatcher Mark interface. + * + * @author qinluo + * @date 2023-08-09 18:17:34 + * @since 1.1.3 + */ +public interface ReloadWatcher { +} -- Gitee From 18b24be6c8134f11f0a9680897ef475fc01fcb91 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Wed, 9 Aug 2023 22:59:39 +0800 Subject: [PATCH 12/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20spring?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowHttpManageConfiguration.java | 19 -- .../FlowInitializerConfiguration.java | 92 ++++---- .../extension/FlowReloadConfiguration.java | 200 +++++++++--------- .../main/resources/META-INF/spring.factories | 4 +- 4 files changed, 147 insertions(+), 168 deletions(-) diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java index c0198cd..17b637a 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java @@ -1,9 +1,6 @@ package org.smartboot.flow.springboot.extension; import org.smartboot.flow.manager.change.HttpManager; -import org.smartboot.flow.manager.reload.Reloader; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -42,7 +39,6 @@ public class FlowHttpManageConfiguration { * Configuration http manager without reloader. */ @Bean(value = "smart-flow-http-manager", initMethod = "start") - @ConditionalOnMissingBean(Reloader.class) public HttpManager getHttpManager(){ HttpManager httpManager = new HttpManager(); httpManager.setTimeout(timeout); @@ -52,21 +48,6 @@ public class FlowHttpManageConfiguration { return httpManager; } - /** - * Configuration http manager with reloader. - */ - @Bean(value = "smart-flow-http-manager", initMethod = "start") - @ConditionalOnBean(Reloader.class) - public HttpManager getHttpManager(Reloader reloader){ - HttpManager httpManager = new HttpManager(); - httpManager.setTimeout(timeout); - httpManager.setUrl(url); - httpManager.setIdle(idle); - httpManager.setDelayAtFirst(delayAtFirst); - httpManager.setReloader(reloader); - return httpManager; - } - public void setTimeout(long timeout) { this.timeout = timeout; diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java index 1f31f65..10c439a 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java @@ -1,46 +1,46 @@ -package org.smartboot.flow.springboot.extension; - -import org.smartboot.flow.spring.extension.EngineInitializer; -import org.smartboot.flow.manager.reload.Reloader; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Arrays; - -/** - * smart flow EngineInitializer auto config - * - * @author huqiang - * @since 2022/12/15 16:32 - */ -@Configuration -@ConfigurationProperties(prefix = "smart.flow.initialize") -@ConditionalOnProperty(name = "smart.flow.initialize.engines") -@AutoConfigureAfter(FlowReloadConfiguration.class) -public class FlowInitializerConfiguration { - - /** - * Initializer engines, multiple engine name split with , - */ - private String engines; - - @Bean(value = "springboot-engine-initializer", initMethod = "start") - @ConditionalOnBean(Reloader.class) - @ConditionalOnMissingBean(EngineInitializer.class) - public EngineInitializer getInitializer(Reloader reloader) { - EngineInitializer initializer = new EngineInitializer(); - initializer.setReloader(reloader); - initializer.setEngines(Arrays.asList(engines.split(","))); - return initializer; - } - - - public void setEngines(String engines) { - this.engines = engines; - } -} +//package org.smartboot.flow.springboot.extension; +// +//import org.smartboot.flow.spring.extension.EngineInitializer; +//import org.smartboot.flow.manager.reload.Reloader; +//import org.springframework.boot.autoconfigure.AutoConfigureAfter; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +//import org.springframework.boot.context.properties.ConfigurationProperties; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//import java.util.Arrays; +// +///** +// * smart flow EngineInitializer auto config +// * +// * @author huqiang +// * @since 2022/12/15 16:32 +// */ +//@Configuration +//@ConfigurationProperties(prefix = "smart.flow.initialize") +//@ConditionalOnProperty(name = "smart.flow.initialize.engines") +//@AutoConfigureAfter(FlowReloadConfiguration.class) +//public class FlowInitializerConfiguration { +// +// /** +// * Initializer engines, multiple engine name split with , +// */ +// private String engines; +// +// @Bean(value = "springboot-engine-initializer", initMethod = "start") +// @ConditionalOnBean(Reloader.class) +// @ConditionalOnMissingBean(EngineInitializer.class) +// public EngineInitializer getInitializer(Reloader reloader) { +// EngineInitializer initializer = new EngineInitializer(); +// initializer.setReloader(reloader); +// initializer.setEngines(Arrays.asList(engines.split(","))); +// return initializer; +// } +// +// +// public void setEngines(String engines) { +// this.engines = engines; +// } +//} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java index 1d14eb2..fa36214 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java @@ -1,100 +1,100 @@ -package org.smartboot.flow.springboot.extension; - -import org.smartboot.flow.manager.reload.SqlXmlSelector; -import org.smartboot.flow.manager.reload.XmlSelector; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * smart flow reload auto config - * - * @author huqiang - * @since 2022/12/15 16:32 - */ -@Configuration -@ConfigurationProperties(prefix = "smart.flow.manage.reload") -@ConditionalOnProperty(name = "smart.flow.manage.reload.enable", havingValue = "true") -public class FlowReloadConfiguration { - - - /** - * Assemble engine after reload. - */ - private boolean assemble; - - /** - * Selector datasource config. - */ - private DataSource datasource; - - /** - * Selector datasource. - */ - public static class DataSource { - private String url; - - /** - * Ensure driver lib in classpath. - */ - private String driver; - private String username; - private String password; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getDriver() { - return driver; - } - - public void setDriver(String driver) { - this.driver = driver; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - } - - @ConditionalOnProperty(name = "smart.flow.manage.reload.datasource.url") - @Bean("xmlSelector") - public XmlSelector getXmlSelector() { - SqlXmlSelector selector = new SqlXmlSelector(); - - if (this.datasource.getDriver() != null) { - selector.setDriver(datasource.getDriver()); - } - - selector.setUrl(datasource.getUrl()); - selector.setUsername(datasource.getUsername()); - selector.setPassword(datasource.getPassword()); - return selector; - } - - public void setAssemble(boolean assemble) { - this.assemble = assemble; - } - - public void setDatasource(DataSource dataSource) { - this.datasource = dataSource; - } -} +//package org.smartboot.flow.springboot.extension; +// +//import org.smartboot.flow.manager.reload.SqlXmlSelector; +//import org.smartboot.flow.manager.reload.XmlSelector; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +//import org.springframework.boot.context.properties.ConfigurationProperties; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +///** +// * smart flow reload auto config +// * +// * @author huqiang +// * @since 2022/12/15 16:32 +// */ +//@Configuration +//@ConfigurationProperties(prefix = "smart.flow.manage.reload") +//@ConditionalOnProperty(name = "smart.flow.manage.reload.enable", havingValue = "true") +//public class FlowReloadConfiguration { +// +// +// /** +// * Assemble engine after reload. +// */ +// private boolean assemble; +// +// /** +// * Selector datasource config. +// */ +// private DataSource datasource; +// +// /** +// * Selector datasource. +// */ +// public static class DataSource { +// private String url; +// +// /** +// * Ensure driver lib in classpath. +// */ +// private String driver; +// private String username; +// private String password; +// +// public String getUrl() { +// return url; +// } +// +// public void setUrl(String url) { +// this.url = url; +// } +// +// public String getDriver() { +// return driver; +// } +// +// public void setDriver(String driver) { +// this.driver = driver; +// } +// +// public String getUsername() { +// return username; +// } +// +// public void setUsername(String username) { +// this.username = username; +// } +// +// public String getPassword() { +// return password; +// } +// +// public void setPassword(String password) { +// this.password = password; +// } +// } +// +// @ConditionalOnProperty(name = "smart.flow.manage.reload.datasource.url") +// @Bean("xmlSelector") +// public XmlSelector getXmlSelector() { +// SqlXmlSelector selector = new SqlXmlSelector(); +// +// if (this.datasource.getDriver() != null) { +// selector.setDriver(datasource.getDriver()); +// } +// +// selector.setUrl(datasource.getUrl()); +// selector.setUsername(datasource.getUsername()); +// selector.setPassword(datasource.getPassword()); +// return selector; +// } +// +// public void setAssemble(boolean assemble) { +// this.assemble = assemble; +// } +// +// public void setDatasource(DataSource dataSource) { +// this.datasource = dataSource; +// } +//} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories index 0fe6437..cd6d66e 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories @@ -1,5 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,\ - org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration,\ - org.smartboot.flow.springboot.extension.FlowReloadConfiguration,\ - org.smartboot.flow.springboot.extension.FlowInitializerConfiguration \ No newline at end of file + org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration \ No newline at end of file -- Gitee From 0c212468b1971c696a959b8969bfd39adfb29144 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Thu, 10 Aug 2023 19:09:55 +0800 Subject: [PATCH 13/20] qinluo: - with default reloader. Signed-off-by: qinluo <1558642210@qq.com> --- .../smartboot/flow/integration/nacos/NacosWatcher.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java index ddd6176..1d6734c 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java @@ -10,6 +10,7 @@ import org.smartboot.flow.core.util.BeanUtils; import org.smartboot.flow.manager.reload.MemoryXmlSelector; import org.smartboot.flow.manager.reload.ReloadWatcher; import org.smartboot.flow.manager.reload.Reloader; +import org.smartboot.flow.manager.reload.XmlParseReloader; import javax.annotation.PostConstruct; import java.util.HashMap; @@ -26,7 +27,7 @@ public class NacosWatcher implements ReloadWatcher { private ConfigService configService; - private Reloader reloader; + private Reloader reloader = new XmlParseReloader(); private String dataId; private String engine; @@ -41,7 +42,12 @@ public class NacosWatcher implements ReloadWatcher { if (reloader == null) { reloader = BeanUtils.getBean(Reloader.class); - AssertUtil.notNull(reloader, "nacos reloader must not be null!"); + } + + if (reloader == null) { + XmlParseReloader r = new XmlParseReloader(); + r.setAssemble(true); + reloader = r; } } -- Gitee From e45d3ccb2820015d667b496f6933a5a11f5ba7f0 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Fri, 11 Aug 2023 19:20:04 +0800 Subject: [PATCH 14/20] =?UTF-8?q?qinluo:=20-=20=E4=BB=A3=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- smart-flow-admin/pom.xml | 1 + .../flow/core/EngineContextHelper.java | 8 +- .../core/executable/AbstractExecutable.java | 19 ----- .../flow/core/executable/Executable.java | 20 +++++ smart-flow-integration/pom.xml | 1 + .../smart-flow-integration-nacos/pom.xml | 1 + .../integration/nacos/NacosConfiguration.java | 61 +++++++++++++++ .../flow/integration/nacos/NacosWatcher.java | 63 ++++----------- .../integration/nacos/NacosXmlSelector.java | 77 +++++++++++++++++++ .../extension/BeanDefinitionVisitor.java | 2 + .../spring/extension/EngineInitializer.java | 2 + .../spring/extension/NotifierProcessor.java | 10 +-- .../spring/extension/ReflectionNotifier.java | 19 +++++ .../SmartFlowBeanFactoryRegistry.java | 11 ++- .../spring/extension/SmartFlowRegistrar.java | 22 +++--- .../extension/SpringBeanContextAdapter.java | 10 ++- .../spring/extension/SpringObjectCreator.java | 2 + .../smart-flow-springboot-starter/pom.xml | 1 + smart-flow-script/pom.xml | 1 + .../smart-flow-script-groovy/pom.xml | 1 + .../smart-flow-script-ognl/pom.xml | 1 + .../smart-flow-script-qlexpress/pom.xml | 1 + 22 files changed, 245 insertions(+), 89 deletions(-) create mode 100644 smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosConfiguration.java create mode 100644 smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java diff --git a/smart-flow-admin/pom.xml b/smart-flow-admin/pom.xml index f1c8545..718e957 100644 --- a/smart-flow-admin/pom.xml +++ b/smart-flow-admin/pom.xml @@ -15,6 +15,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java index 86341b2..fb3864b 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/EngineContextHelper.java @@ -22,17 +22,17 @@ public class EngineContextHelper { HOLDER.remove(); } - public static void broken(boolean broken) { + public static void broken() { EngineContext ctx = get(); if (ctx != null) { - ctx.broken(broken); + ctx.broken(true); } } - public static void brokenAll(boolean broken) { + public static void brokenAll() { EngineContext ctx = get(); if (ctx != null) { - ctx.brokenAll(broken); + ctx.brokenAll(true); } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java index b4c7e31..12c6915 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/AbstractExecutable.java @@ -2,7 +2,6 @@ package org.smartboot.flow.core.executable; import org.smartboot.flow.core.EngineContext; -import org.smartboot.flow.core.EngineContextHelper; /** * 调用层,与业务相关 @@ -30,22 +29,4 @@ public abstract class AbstractExecutable implements Executable { public void rollback(T t, S s) { } - - /** - * Broken current subprocess. - * - * @since 1.1.3 - */ - protected void broken() { - EngineContextHelper.broken(true); - } - - /** - * Broken whole process. - * - * @since 1.1.3 - */ - protected void brokenAll() { - EngineContextHelper.brokenAll(true); - } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/Executable.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/Executable.java index 0b7cffd..02384ac 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/Executable.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/Executable.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core.executable; import org.smartboot.flow.core.Describable; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.EngineContextHelper; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.visitor.ExecutableVisitor; @@ -30,4 +31,23 @@ public interface Executable extends Rollback, Describable { default void visit(ExecutableVisitor visitor) { visitor.visitSource(this); } + + + /** + * Broken current subprocess. + * + * @since 1.1.3 + */ + default void broken() { + EngineContextHelper.broken(); + } + + /** + * Broken whole process. + * + * @since 1.1.3 + */ + default void brokenAll() { + EngineContextHelper.brokenAll(); + } } diff --git a/smart-flow-integration/pom.xml b/smart-flow-integration/pom.xml index ce45ea1..d11546c 100644 --- a/smart-flow-integration/pom.xml +++ b/smart-flow-integration/pom.xml @@ -20,6 +20,7 @@ 8 8 + UTF-8 \ No newline at end of file diff --git a/smart-flow-integration/smart-flow-integration-nacos/pom.xml b/smart-flow-integration/smart-flow-integration-nacos/pom.xml index 755a726..d21fcf4 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/pom.xml +++ b/smart-flow-integration/smart-flow-integration-nacos/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosConfiguration.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosConfiguration.java new file mode 100644 index 0000000..c8a4b27 --- /dev/null +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosConfiguration.java @@ -0,0 +1,61 @@ +package org.smartboot.flow.integration.nacos; + +import com.alibaba.nacos.api.config.ConfigService; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author qinluo + * @date 2023-08-09 10:44:55 + * @since 1.1.3 + */ +public class NacosConfiguration { + + protected ConfigService configService; + + protected String dataId; + protected String engine; + protected String groupId = "DEFAULT_GROUP"; + protected Map nacosProperties = new HashMap<>(); + + public String getDataId() { + return dataId; + } + + public void setDataId(String dataId) { + this.dataId = dataId; + } + + public String getEngine() { + return engine; + } + + public void setEngine(String engine) { + this.engine = engine; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public Map getNacosProperties() { + return nacosProperties; + } + + public void setNacosProperties(Map nacosProperties) { + this.nacosProperties = nacosProperties; + } + + public ConfigService getConfigService() { + return configService; + } + + public void setConfigService(ConfigService configService) { + this.configService = configService; + } +} diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java index 1d6734c..4e77379 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java @@ -13,15 +13,13 @@ import org.smartboot.flow.manager.reload.Reloader; import org.smartboot.flow.manager.reload.XmlParseReloader; import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.Map; /** * @author qinluo * @date 2023-08-09 10:44:55 * @since 1.1.3 */ -public class NacosWatcher implements ReloadWatcher { +public class NacosWatcher extends NacosConfiguration implements ReloadWatcher { private static final Logger LOGGER = LoggerFactory.getLogger(NacosWatcher.class); @@ -29,10 +27,17 @@ public class NacosWatcher implements ReloadWatcher { private Reloader reloader = new XmlParseReloader(); - private String dataId; - private String engine; - private String groupId = "DEFAULT_GROUP"; - private Map nacosProperties = new HashMap<>(); + private NacosXmlSelector notifier; + + /** + * For reflection. + */ + public NacosWatcher() { + } + + public NacosWatcher(NacosXmlSelector notifier) { + this.notifier = notifier; + } private void init() { if (configService == null) { @@ -59,6 +64,10 @@ public class NacosWatcher implements ReloadWatcher { configService.addListener(dataId, groupId, new AbstractListener() { @Override public void receiveConfigInfo(String configInfo) { + if (notifier != null) { + notifier.notifyContentReceived(); + } + MemoryXmlSelector.updateContent(engine, configInfo); reloader.reload(engine); } @@ -69,46 +78,6 @@ public class NacosWatcher implements ReloadWatcher { } - public String getDataId() { - return dataId; - } - - public void setDataId(String dataId) { - this.dataId = dataId; - } - - public String getEngine() { - return engine; - } - - public void setEngine(String engine) { - this.engine = engine; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public Map getNacosProperties() { - return nacosProperties; - } - - public void setNacosProperties(Map nacosProperties) { - this.nacosProperties = nacosProperties; - } - - public ConfigService getConfigService() { - return configService; - } - - public void setConfigService(ConfigService configService) { - this.configService = configService; - } - public Reloader getReloader() { return reloader; } diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java new file mode 100644 index 0000000..4d940cf --- /dev/null +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java @@ -0,0 +1,77 @@ +package org.smartboot.flow.integration.nacos; + +import com.alibaba.nacos.api.config.ConfigService; +import org.smartboot.flow.core.util.AssertUtil; +import org.smartboot.flow.manager.reload.ReloadWatcher; +import org.smartboot.flow.manager.reload.XmlSelector; + +import javax.annotation.PostConstruct; + +/** + * @author qinluo + * @date 2023-08-09 10:44:55 + * @since 1.1.3 + */ +public class NacosXmlSelector extends NacosConfiguration implements XmlSelector, ReloadWatcher { + + private ConfigService configService; + + private boolean enableWatcher; + private boolean fetch = true; + private volatile boolean initialized = false; + private final NacosWatcher watcher = new NacosWatcher(this); + private volatile boolean enabledWatcher = false; + + @PostConstruct + public synchronized void init() { + if (initialized) { + return; + } + + if (configService == null) { + configService = NacosFlowUtil.createCfgService(nacosProperties); + AssertUtil.notNull(configService, "nacos config service must not be null!"); + } + + watcher.setConfigService(configService); + watcher.setEngine(engine); + watcher.setGroupId(groupId); + watcher.setNacosProperties(nacosProperties); + watcher.setDataId(dataId); + + initialized = true; + } + + @Override + public String select(String engineName) { + init(); + + String content = null; + + try { + if (fetch) { + content = configService.getConfig(dataId, groupId, 1000); + } + + if (enableWatcher && !enabledWatcher) { + watcher.start(); + enabledWatcher = true; + } + } catch (Exception ignored) { + + } + return content; + } + + public boolean getEnableWatcher() { + return enableWatcher; + } + + public void setEnableWatcher(boolean enableWatcher) { + this.enableWatcher = enableWatcher; + } + + void notifyContentReceived() { + this.fetch = false; + } +} diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index 39dfc06..f1d9b80 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -46,6 +46,8 @@ import java.util.stream.Collectors; */ public class BeanDefinitionVisitor implements DefinitionVisitor, BeanFactoryAware { + public static final String NAME = BeanDefinitionVisitor.class.getName(); + private ParserContext context; /** diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java index 1cc239b..a10dbeb 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/EngineInitializer.java @@ -6,6 +6,7 @@ import org.smartboot.flow.manager.NullReloader; import org.smartboot.flow.manager.reload.Reloader; import org.springframework.beans.factory.config.BeanPostProcessor; +import javax.annotation.PostConstruct; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -27,6 +28,7 @@ public class EngineInitializer implements BeanPostProcessor { */ private Reloader defaultReloader = NullReloader.NULL; + @PostConstruct public void start() { for (Map.Entry entry : engines.entrySet()) { Reloader reloader = entry.getValue(); diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java index bbd464e..0904b2d 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/NotifierProcessor.java @@ -8,7 +8,6 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.util.ReflectionUtils; import java.util.Arrays; @@ -23,6 +22,7 @@ import java.util.Map; public class NotifierProcessor implements BeanPostProcessor, BeanFactoryAware { private static final Logger LOGGER = LoggerFactory.getLogger(NotifierProcessor.class); + public static final String NAME = SmartFlowBeanFactoryRegistry.class.getName(); private ReflectionNotifier notifier; @@ -53,11 +53,7 @@ public class NotifierProcessor implements BeanPostProcessor, BeanFactoryAware { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof DefaultListableBeanFactory) { - ((DefaultListableBeanFactory)beanFactory).setAllowBeanDefinitionOverriding(true); - notifier = new ReflectionNotifier(beanFactory); - notifier.register(); - } - + notifier = new ReflectionNotifier(beanFactory); + notifier.register(); } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java index 526ca49..4e45289 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/ReflectionNotifier.java @@ -1,5 +1,7 @@ package org.smartboot.flow.spring.extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.smartboot.flow.core.FlowEngine; import org.smartboot.flow.core.manager.EngineManager; import org.smartboot.flow.core.util.AuxiliaryUtils; @@ -20,6 +22,8 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class ReflectionNotifier implements ReloadListener { + private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionNotifier.class); + private final BeanFactory factory; private final List notifiers = new CopyOnWriteArrayList<>(); @@ -92,6 +96,8 @@ public class ReflectionNotifier implements ReloadListener { if (FlowEngine.class.isAssignableFrom(f.getType())) { ReflectionUtils.setField(f, bean, engineInstance); + LOGGER.info("reload-notify engine {}({}) to field {}#{}", + engineName, engineInstance.getStartedAt(), f.getDeclaringClass().getSimpleName(), f.getName()); } else if ((Map.class.isAssignableFrom(f.getType()))) { Map engines = (Map)ReflectionUtils.getField(f, bean); if (engines == null) { @@ -101,6 +107,9 @@ public class ReflectionNotifier implements ReloadListener { Object o = engines.get(engineName); if (o instanceof FlowEngine) { engines.put(engineName, engineInstance); + + LOGGER.info("reload-notify engine {}({}) to field {}#{}", + engineName, engineInstance.getStartedAt(), f.getDeclaringClass().getSimpleName(), f.getName()); } } @@ -108,4 +117,14 @@ public class ReflectionNotifier implements ReloadListener { } } + + @Override + public boolean equals(Object obj) { + return obj instanceof ReflectionNotifier; + } + + @Override + public int hashCode() { + return ReflectionNotifier.class.hashCode(); + } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java index f1faeea..2ab733f 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowBeanFactoryRegistry.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; import java.util.stream.Stream; @@ -21,10 +22,12 @@ import java.util.stream.Stream; public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostProcessor { private BeanDefinitionRegistry registry; + public static final String NAME = SmartFlowBeanFactoryRegistry.class.getName(); @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { this.registry = registry; + SmartFlowRegistrar.registerAll(registry, NAME); } @Override @@ -36,12 +39,12 @@ public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostP if (type != null && XmlParseReloader.class.isAssignableFrom(type)) { PropertyValue visitor = beanDefinition.getPropertyValues().getPropertyValue("visitor"); if (visitor == null) { - beanDefinition.getPropertyValues().addPropertyValue("visitor", new RuntimeBeanReference(SmartFlowRegistrar.SPRING_VISITOR)); + beanDefinition.getPropertyValues().addPropertyValue("visitor", new RuntimeBeanReference(BeanDefinitionVisitor.NAME)); } PropertyValue creator = beanDefinition.getPropertyValues().getPropertyValue("objectCreator"); if (creator == null) { - beanDefinition.getPropertyValues().addPropertyValue("objectCreator", new RuntimeBeanReference("smart-flow-default-object-creator")); + beanDefinition.getPropertyValues().addPropertyValue("objectCreator", new RuntimeBeanReference(SpringObjectCreator.NAME)); } } }); @@ -58,5 +61,9 @@ public class SmartFlowBeanFactoryRegistry implements BeanDefinitionRegistryPostP } finally { ProxyParser.getInstance().reset(); } + + if (beanFactory instanceof DefaultListableBeanFactory) { + ((DefaultListableBeanFactory)beanFactory).setAllowBeanDefinitionOverriding(true); + } } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java index 9b3c965..58d1724 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java @@ -8,7 +8,10 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -18,18 +21,17 @@ import java.util.Map; */ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { - public static final String SPRING_VISITOR = "smart-flow-spring-visitor"; private static final Logger LOGGER = LoggerFactory.getLogger(SmartFlowRegistrar.class); private static final Map> registeredClasses = new HashMap<>(); static { - registeredClasses.put("smart-flow-notifer-processor", NotifierProcessor.class); - registeredClasses.put("smart-flow-registry", SmartFlowBeanFactoryRegistry.class); - registeredClasses.put(SPRING_VISITOR, BeanDefinitionVisitor.class); - registeredClasses.put("smart-flow-default-object-creator", SpringObjectCreator.class); - registeredClasses.put("smart-flow-spring-bean-container", SpringBeanContextAdapter.class); - registeredClasses.put("smart-flow-spring-default-reloader", XmlParseReloader.class); + registeredClasses.put(NotifierProcessor.NAME, NotifierProcessor.class); + registeredClasses.put(SmartFlowBeanFactoryRegistry.NAME, SmartFlowBeanFactoryRegistry.class); + registeredClasses.put(BeanDefinitionVisitor.NAME, BeanDefinitionVisitor.class); + registeredClasses.put(SpringObjectCreator.NAME, SpringObjectCreator.class); + registeredClasses.put(SpringBeanContextAdapter.NAME, SpringBeanContextAdapter.class); + registeredClasses.put(XmlParseReloader.class.getName(), XmlParseReloader.class); } @Override @@ -37,9 +39,11 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { registerAll(registry); } - public static void registerAll(BeanDefinitionRegistry registry) { + public static void registerAll(BeanDefinitionRegistry registry, String ...excludes) { + List excludeBeans = excludes != null ? Arrays.asList(excludes) : Collections.emptyList(); + registeredClasses.forEach((k, v) -> { - if (registry.containsBeanDefinition(k)) { + if (registry.containsBeanDefinition(k) || excludeBeans.contains(k)) { return; } RootBeanDefinition definition = new RootBeanDefinition(); diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java index ec4cc5d..43526eb 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringBeanContextAdapter.java @@ -5,6 +5,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.core.Ordered; import java.util.ArrayList; import java.util.List; @@ -14,7 +15,9 @@ import java.util.List; * @date 2022-12-21 14:22:23 * @since 1.1.3 */ -public class SpringBeanContextAdapter implements BeanContext, ApplicationContextAware, BeanPostProcessor { +public class SpringBeanContextAdapter implements BeanContext, ApplicationContextAware, BeanPostProcessor, Ordered { + + public static final String NAME = SpringBeanContextAdapter.class.getName(); private ApplicationContext ctx; @@ -44,4 +47,9 @@ public class SpringBeanContextAdapter implements BeanContext, ApplicationContext this.ctx = ctx; this.init(); } + + @Override + public int getOrder() { + return 0; + } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java index 242e1e3..ac0d3e0 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringObjectCreator.java @@ -13,6 +13,8 @@ import org.springframework.context.ApplicationContextAware; */ public class SpringObjectCreator implements ObjectCreator, ApplicationContextAware { + public static final String NAME = SpringObjectCreator.class.getName(); + private ApplicationContext ctx; @Override diff --git a/smart-flow-integration/smart-flow-springboot-starter/pom.xml b/smart-flow-integration/smart-flow-springboot-starter/pom.xml index c66a838..d58748e 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-integration/smart-flow-springboot-starter/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-script/pom.xml b/smart-flow-script/pom.xml index 4d9da06..426c0cf 100644 --- a/smart-flow-script/pom.xml +++ b/smart-flow-script/pom.xml @@ -21,6 +21,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-script/smart-flow-script-groovy/pom.xml b/smart-flow-script/smart-flow-script-groovy/pom.xml index 28b6190..c13e1d2 100644 --- a/smart-flow-script/smart-flow-script-groovy/pom.xml +++ b/smart-flow-script/smart-flow-script-groovy/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-script/smart-flow-script-ognl/pom.xml b/smart-flow-script/smart-flow-script-ognl/pom.xml index cd755ce..d82013b 100644 --- a/smart-flow-script/smart-flow-script-ognl/pom.xml +++ b/smart-flow-script/smart-flow-script-ognl/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 diff --git a/smart-flow-script/smart-flow-script-qlexpress/pom.xml b/smart-flow-script/smart-flow-script-qlexpress/pom.xml index bc54432..a0a23ec 100644 --- a/smart-flow-script/smart-flow-script-qlexpress/pom.xml +++ b/smart-flow-script/smart-flow-script-qlexpress/pom.xml @@ -14,6 +14,7 @@ 8 8 + UTF-8 -- Gitee From d1c8fe3a2dd127444afca7f6942f0b961cab4788 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 12 Aug 2023 20:06:36 +0800 Subject: [PATCH 15/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/manager/trace/DefaultTraceCollector.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java index e0b87bc..d33eed9 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/trace/DefaultTraceCollector.java @@ -8,7 +8,6 @@ import org.smartboot.flow.manager.NamedThreadFactory; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -32,7 +31,6 @@ public class DefaultTraceCollector implements TraceCollector { private TraceSampleStrategy sampleStrategy; private ManagerExecutionListener executionListener; - private Map headers; private final BlockingQueue traceQueue = new ArrayBlockingQueue<>(20000); private final List reporters = new ArrayList<>(8); @@ -102,14 +100,6 @@ public class DefaultTraceCollector implements TraceCollector { traceQueue.offer(item); } - public Map getHeaders() { - return headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - public Double getRadio() { return radio; } -- Gitee From 5690298bec92442ede51e1615c2385c0d6b09e27 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 12 Aug 2023 20:38:25 +0800 Subject: [PATCH 16/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/smartboot/flow/integration/nacos/NacosWatcher.java | 3 --- .../org/smartboot/flow/integration/nacos/NacosXmlSelector.java | 3 --- 2 files changed, 6 deletions(-) diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java index 4e77379..a7d5228 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosWatcher.java @@ -1,6 +1,5 @@ package org.smartboot.flow.integration.nacos; -import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.listener.AbstractListener; import com.alibaba.nacos.api.exception.NacosException; import org.slf4j.Logger; @@ -23,8 +22,6 @@ public class NacosWatcher extends NacosConfiguration implements ReloadWatcher { private static final Logger LOGGER = LoggerFactory.getLogger(NacosWatcher.class); - private ConfigService configService; - private Reloader reloader = new XmlParseReloader(); private NacosXmlSelector notifier; diff --git a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java index 4d940cf..e253295 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java +++ b/smart-flow-integration/smart-flow-integration-nacos/src/main/java/org/smartboot/flow/integration/nacos/NacosXmlSelector.java @@ -1,6 +1,5 @@ package org.smartboot.flow.integration.nacos; -import com.alibaba.nacos.api.config.ConfigService; import org.smartboot.flow.core.util.AssertUtil; import org.smartboot.flow.manager.reload.ReloadWatcher; import org.smartboot.flow.manager.reload.XmlSelector; @@ -14,8 +13,6 @@ import javax.annotation.PostConstruct; */ public class NacosXmlSelector extends NacosConfiguration implements XmlSelector, ReloadWatcher { - private ConfigService configService; - private boolean enableWatcher; private boolean fetch = true; private volatile boolean initialized = false; -- Gitee From ad974e386287a534096e69e799f2792fea06f72c Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 12 Aug 2023 21:42:48 +0800 Subject: [PATCH 17/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20springboot?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowDatabaseXmlSelectorConfiguration.java | 89 ++++++++ .../FlowHttpManageConfiguration.java | 67 ------ .../FlowHttpManagerConfiguration.java | 201 ++++++++++++++++++ .../FlowHttpReportConfiguration.java | 55 ----- .../FlowInitializerConfiguration.java | 130 +++++++---- .../extension/FlowReloadConfiguration.java | 100 --------- .../main/resources/META-INF/spring.factories | 5 +- 7 files changed, 377 insertions(+), 270 deletions(-) create mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowDatabaseXmlSelectorConfiguration.java delete mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java create mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java delete mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java delete mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowDatabaseXmlSelectorConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowDatabaseXmlSelectorConfiguration.java new file mode 100644 index 0000000..459710e --- /dev/null +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowDatabaseXmlSelectorConfiguration.java @@ -0,0 +1,89 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.manager.reload.SqlXmlSelector; +import org.smartboot.flow.manager.reload.XmlSelector; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * smart flow reload auto config + * + * @author huqiang + * @since 2022/12/15 16:32 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.selector") +@ConditionalOnProperty(name = "smart.flow.selector.datasource.url") +public class FlowDatabaseXmlSelectorConfiguration { + + /** + * Selector datasource config. + */ + private DataSource datasource; + + /** + * Selector datasource. + */ + public static class DataSource { + private String url; + + /** + * Ensure driver lib in classpath. + */ + private String driver; + private String username; + private String password; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDriver() { + return driver; + } + + public void setDriver(String driver) { + this.driver = driver; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + } + + @Bean("databaseXmlSelector") + public XmlSelector getXmlSelector() { + SqlXmlSelector selector = new SqlXmlSelector(); + + if (this.datasource.getDriver() != null) { + selector.setDriver(datasource.getDriver()); + } + + selector.setUrl(datasource.getUrl()); + selector.setUsername(datasource.getUsername()); + selector.setPassword(datasource.getPassword()); + return selector; + } + + public void setDatasource(DataSource dataSource) { + this.datasource = dataSource; + } +} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java deleted file mode 100644 index 17b637a..0000000 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManageConfiguration.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.smartboot.flow.springboot.extension; - -import org.smartboot.flow.manager.change.HttpManager; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author huqiang - * @since 2022/12/14 19:15 - */ -@Configuration -@ConfigurationProperties(prefix = "smart.flow.manage.http") -@ConditionalOnProperty(name = "smart.flow.manage.http.url") -public class FlowHttpManageConfiguration { - - /** - * Connect timeout in microseconds. - */ - private long timeout; - - /** - * Manage request url. - */ - private String url; - - /** - * request idle in microseconds. - */ - private long idle; - - /** - * First delay in microseconds. - */ - private long delayAtFirst; - - /** - * Configuration http manager without reloader. - */ - @Bean(value = "smart-flow-http-manager", initMethod = "start") - public HttpManager getHttpManager(){ - HttpManager httpManager = new HttpManager(); - httpManager.setTimeout(timeout); - httpManager.setUrl(url); - httpManager.setIdle(idle); - httpManager.setDelayAtFirst(delayAtFirst); - return httpManager; - } - - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - public void setUrl(String url) { - this.url = url; - } - - public void setIdle(long idle) { - this.idle = idle; - } - - public void setDelayAtFirst(long delayAtFirst) { - this.delayAtFirst = delayAtFirst; - } -} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java new file mode 100644 index 0000000..cd35932 --- /dev/null +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java @@ -0,0 +1,201 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.core.parser.DefaultObjectCreator; +import org.smartboot.flow.core.util.AuxiliaryUtils; +import org.smartboot.flow.manager.change.HttpManager; +import org.smartboot.flow.manager.reload.Reloader; +import org.smartboot.flow.manager.reload.XmlParseReloader; +import org.smartboot.flow.manager.report.HttpReporter; +import org.smartboot.flow.manager.trace.DefaultTraceCollector; +import org.smartboot.flow.manager.trace.HttpTraceReporter; +import org.smartboot.flow.manager.trace.LogTraceReporter; +import org.smartboot.flow.manager.trace.TraceReporter; +import org.smartboot.flow.manager.trace.TraceSampleStrategy; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; +import java.util.stream.Stream; + +/** + * @author huqiang + * @since 2022/12/14 19:15 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.manager") +@ConditionalOnProperty(name = "smart.flow.manage.server") +public class FlowHttpManagerConfiguration { + + /* Common Server Configuration start */ + /** + * Connect timeout in microseconds. + */ + private long timeout; + + /** + * manager server address. + */ + private String server; + + /** + * request idle in microseconds. + */ + private long idle = 5000L; + + /** + * First delay in microseconds. + */ + private long delayAtFirst; + + private Map headers; + + /* Common Server Configuration end */ + + /* Trace Collector and Reporter */ + + /** + * Trace radio. + */ + private double radio; + + /** + * sampleStrategy bean name. + */ + private String sampleStrategy; + + /** + * sampleStrategy class name. + */ + private String sampleStrategyClass; + + + /* Management Configuration */ + + /** + * Management reloader's bean name. + */ + private String reloader; + + /* Manager bean definition start */ + + /** + * Configuration httpReporter. + * + * @return httpReporter definition. + */ + @ConditionalOnProperty(value = "smart.flow.manager.statistic.report", havingValue = "true") + @Bean(value = "smart-flow-http-reporter", initMethod = "start") + public HttpReporter getHttpReporter() { + HttpReporter reporter = new HttpReporter(); + reporter.setTimeout(this.timeout); + reporter.setServerAddress(this.server); + reporter.setIdle(this.idle); + reporter.setHeaders(headers); + return reporter; + } + + /** + * Configuration http manager。 + */ + @ConditionalOnProperty(value = "smart.flow.manager.management.enabled", havingValue = "true") + @Bean(value = "smart-flow-http-manager", initMethod = "start") + public HttpManager getHttpManager(ApplicationContext ctx){ + HttpManager httpManager = new HttpManager(); + httpManager.setTimeout(timeout); + httpManager.setUrl(server); + httpManager.setIdle(idle); + httpManager.setDelayAtFirst(delayAtFirst); + httpManager.setHeaders(headers); + + if (AuxiliaryUtils.isBlank(reloader)) { + // not configured, use default reloader. + reloader = XmlParseReloader.class.getName(); + } + + Reloader reloaderBean = ctx.getBean(reloader, Reloader.class); + httpManager.setReloader(reloaderBean); + return httpManager; + } + + /** + * Configuration httpTraceReporter. + */ + @ConditionalOnProperty(value = "smart.flow.manager.trace.http-report", havingValue = "true") + @Bean(value = "httpTraceReporter", initMethod = "init") + public HttpTraceReporter getHttpTraceReporter() { + HttpTraceReporter reporter = new HttpTraceReporter(); + reporter.setTimeout(this.timeout); + reporter.setServerAddress(this.server); + reporter.setHeaders(headers); + return reporter; + } + + @ConditionalOnProperty(value = "smart.flow.manager.trace.log-report", havingValue = "true") + @Bean(value = "logTraceReporter") + public LogTraceReporter getLogTraceReporter() { + return new LogTraceReporter(); + } + + @ConditionalOnProperty(value = "smart.flow.manager.trace.enabled", havingValue = "true") + @Bean(value = "defaultTraceCollector", initMethod = "start") + public DefaultTraceCollector getTraceCollector(ApplicationContext ctx){ + DefaultTraceCollector collector = new DefaultTraceCollector(); + collector.setIdle(idle); + collector.setRadio(radio); + + String[] traceReporterNames = ctx.getBeanNamesForType(TraceReporter.class); + Stream.of(traceReporterNames).forEach(p -> collector.addReporter(ctx.getBean(p, TraceReporter.class))); + + if (AuxiliaryUtils.isNotBlank(sampleStrategy)) { + collector.setSampleStrategy(ctx.getBean(sampleStrategy, TraceSampleStrategy.class)); + } + // Create strategy with classname. + else if (AuxiliaryUtils.asClass(sampleStrategyClass) != null) { + TraceSampleStrategy strategy = DefaultObjectCreator.getInstance().create(sampleStrategyClass, TraceSampleStrategy.class, false); + collector.setSampleStrategy(strategy); + } + + return collector; + } + + /* Manager bean definition end */ + + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public void setServer(String server) { + this.server = server; + } + + public void setIdle(long idle) { + this.idle = idle; + } + + public void setDelayAtFirst(long delayAtFirst) { + this.delayAtFirst = delayAtFirst; + } + + public void setRadio(double radio) { + this.radio = radio; + } + + public void setSampleStrategy(String sampleStrategy) { + this.sampleStrategy = sampleStrategy; + } + + public void setSampleStrategyClass(String sampleStrategyClass) { + this.sampleStrategyClass = sampleStrategyClass; + } + + public void setReloader(String reloader) { + this.reloader = reloader; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } +} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java deleted file mode 100644 index 4bc582c..0000000 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpReportConfiguration.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.smartboot.flow.springboot.extension; - -import org.smartboot.flow.manager.report.HttpReporter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * smart flow httReport auto config - * - * @author huqiang - * @since 2022/12/15 16:32 - */ -@Configuration -@ConfigurationProperties(prefix = "smart.flow.report.http") -@ConditionalOnProperty(name = "smart.flow.report.http.url") -public class FlowHttpReportConfiguration { - - /** - * Connect timeout in microseconds. - */ - private long timeout; - - /** - * Report url. - */ - private String url; - - /** - * Default idle in microseconds. - */ - private long idle = 5000L; - - @Bean(value = "smart-flow-http-reporter", initMethod = "start") - public HttpReporter getHttpReporter() { - HttpReporter reporter = new HttpReporter(); - reporter.setTimeout(this.timeout); - reporter.setServerAddress(this.url); - reporter.setIdle(this.idle); - return reporter; - } - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - public void setUrl(String url) { - this.url = url; - } - - public void setIdle(long idle) { - this.idle = idle; - } -} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java index 10c439a..9b45dfa 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java @@ -1,46 +1,84 @@ -//package org.smartboot.flow.springboot.extension; -// -//import org.smartboot.flow.spring.extension.EngineInitializer; -//import org.smartboot.flow.manager.reload.Reloader; -//import org.springframework.boot.autoconfigure.AutoConfigureAfter; -//import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -//import org.springframework.boot.context.properties.ConfigurationProperties; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -//import java.util.Arrays; -// -///** -// * smart flow EngineInitializer auto config -// * -// * @author huqiang -// * @since 2022/12/15 16:32 -// */ -//@Configuration -//@ConfigurationProperties(prefix = "smart.flow.initialize") -//@ConditionalOnProperty(name = "smart.flow.initialize.engines") -//@AutoConfigureAfter(FlowReloadConfiguration.class) -//public class FlowInitializerConfiguration { -// -// /** -// * Initializer engines, multiple engine name split with , -// */ -// private String engines; -// -// @Bean(value = "springboot-engine-initializer", initMethod = "start") -// @ConditionalOnBean(Reloader.class) -// @ConditionalOnMissingBean(EngineInitializer.class) -// public EngineInitializer getInitializer(Reloader reloader) { -// EngineInitializer initializer = new EngineInitializer(); -// initializer.setReloader(reloader); -// initializer.setEngines(Arrays.asList(engines.split(","))); -// return initializer; -// } -// -// -// public void setEngines(String engines) { -// this.engines = engines; -// } -//} +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.core.util.AuxiliaryUtils; +import org.smartboot.flow.manager.reload.XmlParseReloader; +import org.smartboot.flow.manager.reload.XmlSelector; +import org.smartboot.flow.spring.extension.EngineInitializer; +import org.smartboot.flow.manager.reload.Reloader; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; + +/** + * smart flow EngineInitializer auto config + * + * @author huqiang + * @since 2022/12/15 16:32 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.initialize") +@ConditionalOnProperty(name = "smart.flow.initialize.engines") +public class FlowInitializerConfiguration { + + /** + * Initializer engines, multiple engine name split with , + */ + private String engines; + private String xmlSelector; + private String reloader; + + @Bean(value = "springboot-engine-initializer", initMethod = "start") + @ConditionalOnBean(Reloader.class) + @ConditionalOnMissingBean(EngineInitializer.class) + public EngineInitializer getInitializer(ApplicationContext ctx) { + boolean withSelector = false; + if (AuxiliaryUtils.isBlank(reloader)) { + // not configured, use default reloader. + reloader = XmlParseReloader.class.getName(); + withSelector = true; + } + + Reloader reloaderBean = ctx.getBean(reloader, Reloader.class); + + if (withSelector) { + XmlSelector selector = null; + + if (AuxiliaryUtils.isNotBlank(xmlSelector)) { + selector = ctx.getBean(xmlSelector, XmlSelector.class); + } + // DatabaseXmlSelector has configured + else if (ctx.containsBean("databaseXmlSelector")) { + selector = ctx.getBean("databaseXmlSelector", XmlSelector.class); + } + + if (selector != null) { + ((XmlParseReloader)reloaderBean).setXmlSelector(selector); + } + } + + + EngineInitializer initializer = new EngineInitializer(); + initializer.setReloader(reloaderBean); + initializer.setEngines(Arrays.asList(engines.split(","))); + return initializer; + } + + + public void setEngines(String engines) { + this.engines = engines; + } + + public void setXmlSelector(String xmlSelector) { + this.xmlSelector = xmlSelector; + } + + public void setReloader(String reloader) { + this.reloader = reloader; + } +} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java deleted file mode 100644 index fa36214..0000000 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowReloadConfiguration.java +++ /dev/null @@ -1,100 +0,0 @@ -//package org.smartboot.flow.springboot.extension; -// -//import org.smartboot.flow.manager.reload.SqlXmlSelector; -//import org.smartboot.flow.manager.reload.XmlSelector; -//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -//import org.springframework.boot.context.properties.ConfigurationProperties; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -///** -// * smart flow reload auto config -// * -// * @author huqiang -// * @since 2022/12/15 16:32 -// */ -//@Configuration -//@ConfigurationProperties(prefix = "smart.flow.manage.reload") -//@ConditionalOnProperty(name = "smart.flow.manage.reload.enable", havingValue = "true") -//public class FlowReloadConfiguration { -// -// -// /** -// * Assemble engine after reload. -// */ -// private boolean assemble; -// -// /** -// * Selector datasource config. -// */ -// private DataSource datasource; -// -// /** -// * Selector datasource. -// */ -// public static class DataSource { -// private String url; -// -// /** -// * Ensure driver lib in classpath. -// */ -// private String driver; -// private String username; -// private String password; -// -// public String getUrl() { -// return url; -// } -// -// public void setUrl(String url) { -// this.url = url; -// } -// -// public String getDriver() { -// return driver; -// } -// -// public void setDriver(String driver) { -// this.driver = driver; -// } -// -// public String getUsername() { -// return username; -// } -// -// public void setUsername(String username) { -// this.username = username; -// } -// -// public String getPassword() { -// return password; -// } -// -// public void setPassword(String password) { -// this.password = password; -// } -// } -// -// @ConditionalOnProperty(name = "smart.flow.manage.reload.datasource.url") -// @Bean("xmlSelector") -// public XmlSelector getXmlSelector() { -// SqlXmlSelector selector = new SqlXmlSelector(); -// -// if (this.datasource.getDriver() != null) { -// selector.setDriver(datasource.getDriver()); -// } -// -// selector.setUrl(datasource.getUrl()); -// selector.setUsername(datasource.getUsername()); -// selector.setPassword(datasource.getPassword()); -// return selector; -// } -// -// public void setAssemble(boolean assemble) { -// this.assemble = assemble; -// } -// -// public void setDatasource(DataSource dataSource) { -// this.datasource = dataSource; -// } -//} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories index cd6d66e..91a8af3 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - org.smartboot.flow.springboot.extension.FlowHttpManageConfiguration,\ - org.smartboot.flow.springboot.extension.FlowHttpReportConfiguration \ No newline at end of file + org.smartboot.flow.springboot.extension.FlowHttpManagerConfiguration,\ + org.smartboot.flow.springboot.extension.FlowDatabaseXmlSelectorConfiguration,\ + org.smartboot.flow.springboot.extension.FlowInitializerConfiguration \ No newline at end of file -- Gitee From de7d62dfb12d7a326be3b8eeec613acaa84ba107 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 12 Aug 2023 21:48:56 +0800 Subject: [PATCH 18/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20springboot?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowHttpManagerConfiguration.java | 34 ------- .../extension/FlowTraceConfiguration.java | 94 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + 3 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowTraceConfiguration.java diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java index cd35932..c968ba1 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java @@ -1,16 +1,11 @@ package org.smartboot.flow.springboot.extension; -import org.smartboot.flow.core.parser.DefaultObjectCreator; import org.smartboot.flow.core.util.AuxiliaryUtils; import org.smartboot.flow.manager.change.HttpManager; import org.smartboot.flow.manager.reload.Reloader; import org.smartboot.flow.manager.reload.XmlParseReloader; import org.smartboot.flow.manager.report.HttpReporter; -import org.smartboot.flow.manager.trace.DefaultTraceCollector; import org.smartboot.flow.manager.trace.HttpTraceReporter; -import org.smartboot.flow.manager.trace.LogTraceReporter; -import org.smartboot.flow.manager.trace.TraceReporter; -import org.smartboot.flow.manager.trace.TraceSampleStrategy; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.ApplicationContext; @@ -18,7 +13,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.Map; -import java.util.stream.Stream; /** * @author huqiang @@ -133,34 +127,6 @@ public class FlowHttpManagerConfiguration { return reporter; } - @ConditionalOnProperty(value = "smart.flow.manager.trace.log-report", havingValue = "true") - @Bean(value = "logTraceReporter") - public LogTraceReporter getLogTraceReporter() { - return new LogTraceReporter(); - } - - @ConditionalOnProperty(value = "smart.flow.manager.trace.enabled", havingValue = "true") - @Bean(value = "defaultTraceCollector", initMethod = "start") - public DefaultTraceCollector getTraceCollector(ApplicationContext ctx){ - DefaultTraceCollector collector = new DefaultTraceCollector(); - collector.setIdle(idle); - collector.setRadio(radio); - - String[] traceReporterNames = ctx.getBeanNamesForType(TraceReporter.class); - Stream.of(traceReporterNames).forEach(p -> collector.addReporter(ctx.getBean(p, TraceReporter.class))); - - if (AuxiliaryUtils.isNotBlank(sampleStrategy)) { - collector.setSampleStrategy(ctx.getBean(sampleStrategy, TraceSampleStrategy.class)); - } - // Create strategy with classname. - else if (AuxiliaryUtils.asClass(sampleStrategyClass) != null) { - TraceSampleStrategy strategy = DefaultObjectCreator.getInstance().create(sampleStrategyClass, TraceSampleStrategy.class, false); - collector.setSampleStrategy(strategy); - } - - return collector; - } - /* Manager bean definition end */ public void setTimeout(long timeout) { diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowTraceConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowTraceConfiguration.java new file mode 100644 index 0000000..27b83b0 --- /dev/null +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowTraceConfiguration.java @@ -0,0 +1,94 @@ +package org.smartboot.flow.springboot.extension; + +import org.smartboot.flow.core.parser.DefaultObjectCreator; +import org.smartboot.flow.core.util.AuxiliaryUtils; +import org.smartboot.flow.manager.trace.DefaultTraceCollector; +import org.smartboot.flow.manager.trace.LogTraceReporter; +import org.smartboot.flow.manager.trace.TraceReporter; +import org.smartboot.flow.manager.trace.TraceSampleStrategy; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.stream.Stream; + +/** + * @author huqiang + * @since 2022/12/14 19:15 + */ +@Configuration +@ConfigurationProperties(prefix = "smart.flow.manager.trace") +@ConditionalOnProperty(value = "smart.flow.manager.trace.enabled", havingValue = "true") +public class FlowTraceConfiguration { + + /** + * request idle in microseconds. + */ + private long idle = 5000L; + + /* Trace Collector and Reporter */ + + /** + * Trace radio. + */ + private double radio; + + /** + * sampleStrategy bean name. + */ + private String sampleStrategy; + + /** + * sampleStrategy class name. + */ + private String sampleStrategyClass; + + + @ConditionalOnProperty(value = "smart.flow.manager.trace.log-report", havingValue = "true") + @Bean(value = "logTraceReporter") + public LogTraceReporter getLogTraceReporter() { + return new LogTraceReporter(); + } + + @ConditionalOnProperty(value = "smart.flow.manager.trace.enabled", havingValue = "true") + @Bean(value = "defaultTraceCollector", initMethod = "start") + public DefaultTraceCollector getTraceCollector(ApplicationContext ctx){ + DefaultTraceCollector collector = new DefaultTraceCollector(); + collector.setIdle(idle); + collector.setRadio(radio); + + String[] traceReporterNames = ctx.getBeanNamesForType(TraceReporter.class); + Stream.of(traceReporterNames).forEach(p -> collector.addReporter(ctx.getBean(p, TraceReporter.class))); + + if (AuxiliaryUtils.isNotBlank(sampleStrategy)) { + collector.setSampleStrategy(ctx.getBean(sampleStrategy, TraceSampleStrategy.class)); + } + // Create strategy with classname. + else if (AuxiliaryUtils.asClass(sampleStrategyClass) != null) { + TraceSampleStrategy strategy = DefaultObjectCreator.getInstance().create(sampleStrategyClass, TraceSampleStrategy.class, false); + collector.setSampleStrategy(strategy); + } + + return collector; + } + + /* Manager bean definition end */ + + public void setIdle(long idle) { + this.idle = idle; + } + + public void setRadio(double radio) { + this.radio = radio; + } + + public void setSampleStrategy(String sampleStrategy) { + this.sampleStrategy = sampleStrategy; + } + + public void setSampleStrategyClass(String sampleStrategyClass) { + this.sampleStrategyClass = sampleStrategyClass; + } +} diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories index 91a8af3..3ffcb6d 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/resources/META-INF/spring.factories @@ -1,4 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.smartboot.flow.springboot.extension.FlowHttpManagerConfiguration,\ org.smartboot.flow.springboot.extension.FlowDatabaseXmlSelectorConfiguration,\ + org.smartboot.flow.springboot.extension.FlowTraceConfiguration,\ org.smartboot.flow.springboot.extension.FlowInitializerConfiguration \ No newline at end of file -- Gitee From 75cdc04bf2e5c570a7e96cf4a982cf10ada7da37 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Sat, 12 Aug 2023 22:26:09 +0800 Subject: [PATCH 19/20] =?UTF-8?q?qinluo:=20=20=20=20=20=20-=20springboot?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowHttpManagerConfiguration.java | 31 +------------------ .../FlowInitializerConfiguration.java | 4 +-- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java index c968ba1..b5a1a4e 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowHttpManagerConfiguration.java @@ -20,7 +20,7 @@ import java.util.Map; */ @Configuration @ConfigurationProperties(prefix = "smart.flow.manager") -@ConditionalOnProperty(name = "smart.flow.manage.server") +@ConditionalOnProperty(name = "smart.flow.manager.server") public class FlowHttpManagerConfiguration { /* Common Server Configuration start */ @@ -48,23 +48,6 @@ public class FlowHttpManagerConfiguration { /* Common Server Configuration end */ - /* Trace Collector and Reporter */ - - /** - * Trace radio. - */ - private double radio; - - /** - * sampleStrategy bean name. - */ - private String sampleStrategy; - - /** - * sampleStrategy class name. - */ - private String sampleStrategyClass; - /* Management Configuration */ @@ -145,18 +128,6 @@ public class FlowHttpManagerConfiguration { this.delayAtFirst = delayAtFirst; } - public void setRadio(double radio) { - this.radio = radio; - } - - public void setSampleStrategy(String sampleStrategy) { - this.sampleStrategy = sampleStrategy; - } - - public void setSampleStrategyClass(String sampleStrategyClass) { - this.sampleStrategyClass = sampleStrategyClass; - } - public void setReloader(String reloader) { this.reloader = reloader; } diff --git a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java index 9b45dfa..bc51bfb 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java +++ b/smart-flow-integration/smart-flow-springboot-starter/src/main/java/org/smartboot/flow/springboot/extension/FlowInitializerConfiguration.java @@ -22,8 +22,8 @@ import java.util.Arrays; * @since 2022/12/15 16:32 */ @Configuration -@ConfigurationProperties(prefix = "smart.flow.initialize") -@ConditionalOnProperty(name = "smart.flow.initialize.engines") +@ConfigurationProperties(prefix = "smart.flow.initializer") +@ConditionalOnProperty(name = "smart.flow.initializer.engines") public class FlowInitializerConfiguration { /** -- Gitee From cbb737e7248b7f422096f6a59126de42474b9762 Mon Sep 17 00:00:00 2001 From: qinluo <1558642210@qq.com> Date: Mon, 14 Aug 2023 12:14:59 +0800 Subject: [PATCH 20/20] =?UTF-8?q?qinluo:=20-=20=E5=8D=87=E7=BA=A7=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinluo <1558642210@qq.com> --- pom.xml | 4 ++-- smart-flow-admin/pom.xml | 4 ++-- smart-flow-core/pom.xml | 2 +- smart-flow-helper/pom.xml | 2 +- smart-flow-integration/pom.xml | 2 +- smart-flow-integration/smart-flow-integration-nacos/pom.xml | 2 +- smart-flow-integration/smart-flow-spring-extension/pom.xml | 2 +- smart-flow-integration/smart-flow-springboot-starter/pom.xml | 2 +- smart-flow-manager/pom.xml | 2 +- smart-flow-plugin/pom.xml | 2 +- smart-flow-plugin/smart-flow-bootstrap/pom.xml | 2 +- smart-flow-plugin/smart-flow-enhance-plugin/pom.xml | 2 +- smart-flow-script/pom.xml | 2 +- smart-flow-script/smart-flow-script-groovy/pom.xml | 2 +- smart-flow-script/smart-flow-script-ognl/pom.xml | 2 +- smart-flow-script/smart-flow-script-qlexpress/pom.xml | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index c46befd..6290330 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 pom smart-flow @@ -22,7 +22,7 @@ - 1.1.3-SNAPSHOT + 1.1.3 https://gitee.com/smartboot/smart-flow diff --git a/smart-flow-admin/pom.xml b/smart-flow-admin/pom.xml index 718e957..023f141 100644 --- a/smart-flow-admin/pom.xml +++ b/smart-flow-admin/pom.xml @@ -5,10 +5,10 @@ smart-flow-parent org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 - 1.1.3-SNAPSHOT + 1.1.3 smart-flow-admin diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index a3d80cf..f7cf831 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-helper/pom.xml b/smart-flow-helper/pom.xml index ef9dfb3..23c8f4e 100644 --- a/smart-flow-helper/pom.xml +++ b/smart-flow-helper/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-integration/pom.xml b/smart-flow-integration/pom.xml index d11546c..4b1f46d 100644 --- a/smart-flow-integration/pom.xml +++ b/smart-flow-integration/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-integration/smart-flow-integration-nacos/pom.xml b/smart-flow-integration/smart-flow-integration-nacos/pom.xml index d21fcf4..aca2642 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/pom.xml +++ b/smart-flow-integration/smart-flow-integration-nacos/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-integration/smart-flow-spring-extension/pom.xml b/smart-flow-integration/smart-flow-spring-extension/pom.xml index 7a8bf03..fb1a35e 100644 --- a/smart-flow-integration/smart-flow-spring-extension/pom.xml +++ b/smart-flow-integration/smart-flow-spring-extension/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-integration/smart-flow-springboot-starter/pom.xml b/smart-flow-integration/smart-flow-springboot-starter/pom.xml index d58748e..767f59a 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-integration/smart-flow-springboot-starter/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index fd293d7..1247b5d 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-plugin/pom.xml b/smart-flow-plugin/pom.xml index 97772a1..b76abb4 100644 --- a/smart-flow-plugin/pom.xml +++ b/smart-flow-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3-SNAPSHOT + 1.1.3 smart-flow-plugin diff --git a/smart-flow-plugin/smart-flow-bootstrap/pom.xml b/smart-flow-plugin/smart-flow-bootstrap/pom.xml index 8a9691e..9ffc1b6 100644 --- a/smart-flow-plugin/smart-flow-bootstrap/pom.xml +++ b/smart-flow-plugin/smart-flow-bootstrap/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.3-SNAPSHOT + 1.1.3 smart-flow-bootstrap diff --git a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml index 82e0741..2221700 100644 --- a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml +++ b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.3-SNAPSHOT + 1.1.3 smart-flow-enhance-plugin diff --git a/smart-flow-script/pom.xml b/smart-flow-script/pom.xml index 426c0cf..af5a19d 100644 --- a/smart-flow-script/pom.xml +++ b/smart-flow-script/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 pom diff --git a/smart-flow-script/smart-flow-script-groovy/pom.xml b/smart-flow-script/smart-flow-script-groovy/pom.xml index c13e1d2..8febee5 100644 --- a/smart-flow-script/smart-flow-script-groovy/pom.xml +++ b/smart-flow-script/smart-flow-script-groovy/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-script/smart-flow-script-ognl/pom.xml b/smart-flow-script/smart-flow-script-ognl/pom.xml index d82013b..efd7c16 100644 --- a/smart-flow-script/smart-flow-script-ognl/pom.xml +++ b/smart-flow-script/smart-flow-script-ognl/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 diff --git a/smart-flow-script/smart-flow-script-qlexpress/pom.xml b/smart-flow-script/smart-flow-script-qlexpress/pom.xml index a0a23ec..13519f0 100644 --- a/smart-flow-script/smart-flow-script-qlexpress/pom.xml +++ b/smart-flow-script/smart-flow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3-SNAPSHOT + 1.1.3 4.0.0 -- Gitee