From a477d015dca161e267ba0c06b2dd3585c58cd2ef Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Tue, 20 Jul 2021 08:52:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=BA=BF=E7=A8=8B=E6=B1=A0=20Starter=20=E5=8C=85?= =?UTF-8?q?=E7=BA=A7=E7=9B=AE=E5=BD=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{config => common}/CommonThreadPool.java | 2 +- .../controller/PoolRunStateController.java | 2 +- .../{listener => core}/ClientWorker.java | 3 +- .../starter/core/ConfigService.java | 2 -- .../core/{registry => }/DiscoveryClient.java | 2 +- .../core/{registry => }/DynamicTpClient.java | 2 +- .../core/{registry => }/InstanceInfo.java | 2 +- .../starter/{listener => core}/Listener.java | 2 +- .../starter/core/ThreadPoolConfigService.java | 2 -- .../starter/core/ThreadPoolOperation.java | 1 - .../ThreadPoolRunListener.java | 8 ++--- .../ThreadPoolBannerHandler.java} | 33 ++++++++++++++----- .../ThreadPoolRunStateHandler.java | 3 +- .../starter/wrap/DynamicThreadPoolWrap.java | 2 +- .../starter/wrap/ManagerListenerWrap.java | 2 +- 15 files changed, 37 insertions(+), 31 deletions(-) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{config => common}/CommonThreadPool.java (95%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{listener => core}/ClientWorker.java (99%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/{registry => }/DiscoveryClient.java (92%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/{registry => }/DynamicTpClient.java (68%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/{registry => }/InstanceInfo.java (71%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{listener => core}/Listener.java (87%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{listener => core}/ThreadPoolRunListener.java (91%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{config/DynamicThreadPoolBanner.java => handler/ThreadPoolBannerHandler.java} (58%) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{core => handler}/ThreadPoolRunStateHandler.java (96%) diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/CommonThreadPool.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java similarity index 95% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/CommonThreadPool.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java index 287f3892..4b3608f1 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/CommonThreadPool.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.config; +package io.dynamic.threadpool.starter.common; import io.dynamic.threadpool.starter.toolkit.thread.QueueTypeEnum; import io.dynamic.threadpool.starter.toolkit.thread.ThreadPoolBuilder; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/controller/PoolRunStateController.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/controller/PoolRunStateController.java index 957b4f19..667b8d9a 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/controller/PoolRunStateController.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/controller/PoolRunStateController.java @@ -3,7 +3,7 @@ package io.dynamic.threadpool.starter.controller; import io.dynamic.threadpool.common.model.PoolRunStateInfo; import io.dynamic.threadpool.common.web.base.Result; import io.dynamic.threadpool.common.web.base.Results; -import io.dynamic.threadpool.starter.core.ThreadPoolRunStateHandler; +import io.dynamic.threadpool.starter.handler.ThreadPoolRunStateHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ClientWorker.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ClientWorker.java similarity index 99% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ClientWorker.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ClientWorker.java index 46868d34..1897dee9 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ClientWorker.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ClientWorker.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.listener; +package io.dynamic.threadpool.starter.core; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; @@ -7,7 +7,6 @@ import io.dynamic.threadpool.common.model.PoolParameterInfo; import io.dynamic.threadpool.common.toolkit.ContentUtil; import io.dynamic.threadpool.common.toolkit.GroupKey; import io.dynamic.threadpool.common.web.base.Result; -import io.dynamic.threadpool.starter.core.CacheData; import io.dynamic.threadpool.starter.remote.HttpAgent; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ConfigService.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ConfigService.java index 5edab0a4..00c75c07 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ConfigService.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ConfigService.java @@ -1,7 +1,5 @@ package io.dynamic.threadpool.starter.core; -import io.dynamic.threadpool.starter.listener.Listener; - /** * 配置服务 * diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DiscoveryClient.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DiscoveryClient.java similarity index 92% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DiscoveryClient.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DiscoveryClient.java index 5becae72..303503a6 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DiscoveryClient.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DiscoveryClient.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.core.registry; +package io.dynamic.threadpool.starter.core; /** * Discovery Client. diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DynamicTpClient.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DynamicTpClient.java similarity index 68% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DynamicTpClient.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DynamicTpClient.java index e1a30b11..7d70be2e 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/DynamicTpClient.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/DynamicTpClient.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.core.registry; +package io.dynamic.threadpool.starter.core; /** * Dynamic Tp Client. diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/InstanceInfo.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/InstanceInfo.java similarity index 71% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/InstanceInfo.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/InstanceInfo.java index 9ec7a05a..90d44de8 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/registry/InstanceInfo.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/InstanceInfo.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.core.registry; +package io.dynamic.threadpool.starter.core; /** * Instance Info. diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/Listener.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/Listener.java similarity index 87% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/Listener.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/Listener.java index eca04a1d..922f5504 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/Listener.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/Listener.java @@ -1,4 +1,4 @@ -package io.dynamic.threadpool.starter.listener; +package io.dynamic.threadpool.starter.core; import java.util.concurrent.Executor; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolConfigService.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolConfigService.java index fe878b64..a269ace0 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolConfigService.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolConfigService.java @@ -3,8 +3,6 @@ package io.dynamic.threadpool.starter.core; import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import io.dynamic.threadpool.starter.remote.HttpAgent; import io.dynamic.threadpool.starter.remote.ServerHttpAgent; -import io.dynamic.threadpool.starter.listener.ClientWorker; -import io.dynamic.threadpool.starter.listener.Listener; import java.util.Arrays; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolOperation.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolOperation.java index 3c122599..3a0ed269 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolOperation.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolOperation.java @@ -1,7 +1,6 @@ package io.dynamic.threadpool.starter.core; import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; -import io.dynamic.threadpool.starter.listener.Listener; import org.springframework.beans.factory.annotation.Autowired; import java.util.concurrent.Executor; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ThreadPoolRunListener.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunListener.java similarity index 91% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ThreadPoolRunListener.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunListener.java index 746fc663..721c38e0 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/listener/ThreadPoolRunListener.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunListener.java @@ -1,14 +1,12 @@ -package io.dynamic.threadpool.starter.listener; +package io.dynamic.threadpool.starter.core; import com.alibaba.fastjson.JSON; import io.dynamic.threadpool.common.config.ApplicationContextHolder; import io.dynamic.threadpool.common.constant.Constants; import io.dynamic.threadpool.common.model.PoolParameterInfo; import io.dynamic.threadpool.common.web.base.Result; -import io.dynamic.threadpool.starter.config.CommonThreadPool; -import io.dynamic.threadpool.starter.config.DynamicThreadPoolBanner; +import io.dynamic.threadpool.starter.common.CommonThreadPool; import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; -import io.dynamic.threadpool.starter.core.GlobalThreadPoolManage; import io.dynamic.threadpool.starter.remote.HttpAgent; import io.dynamic.threadpool.starter.remote.ServerHttpAgent; import io.dynamic.threadpool.starter.toolkit.thread.QueueTypeEnum; @@ -44,8 +42,6 @@ public class ThreadPoolRunListener { @PostConstruct @Order(Ordered.LOWEST_PRECEDENCE - 1024) public void run() { - DynamicThreadPoolBanner.printBanner(properties.isBanner()); - Map executorMap = ApplicationContextHolder.getBeansOfType(DynamicThreadPoolWrap.class); executorMap.forEach((key, val) -> { String tpId = val.getTpId(); diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/DynamicThreadPoolBanner.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolBannerHandler.java similarity index 58% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/DynamicThreadPoolBanner.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolBannerHandler.java index 8f73d752..e2e194dc 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/config/DynamicThreadPoolBanner.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolBannerHandler.java @@ -1,29 +1,44 @@ -package io.dynamic.threadpool.starter.config; +package io.dynamic.threadpool.starter.handler; +import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.ansi.AnsiColor; import org.springframework.boot.ansi.AnsiOutput; import org.springframework.boot.ansi.AnsiStyle; /** - * 动态线程池 Banner + * 动态线程池打印 Banner. * * @author chen.ma - * @date 2021/7/4 15:58 + * @date 2021/6/20 16:34 */ -public class DynamicThreadPoolBanner { +@Slf4j +@RequiredArgsConstructor +public class ThreadPoolBannerHandler implements InitializingBean { - private static final String DYNAMIC_THREAD_POOL = " :: Dynamic ThreadPool :: "; + @NonNull + private final DynamicThreadPoolProperties properties; - private static final int STRAP_LINE_SIZE = 50; + private final String DYNAMIC_THREAD_POOL = " :: Dynamic ThreadPool :: "; - public static void printBanner(boolean isBanner) { + private final int STRAP_LINE_SIZE = 50; + + @Override + public void afterPropertiesSet() { + printBanner(); + } + + private void printBanner() { String banner = "\n___ _ _____ ___ \n" + "| \\ _ _ _ _ __ _ _ __ (_)__ |_ _| _ \\\n" + "| |) | || | ' \\/ _` | ' \\| / _| | | | _/\n" + "|___/ \\_, |_||_\\__,_|_|_|_|_\\__| |_| |_| \n" + " |__/ \n"; - if (isBanner) { + if (properties.isBanner()) { String version = getVersion(); version = (version != null) ? " (v" + version + ")" : "no version."; @@ -38,7 +53,7 @@ public class DynamicThreadPoolBanner { } public static String getVersion() { - final Package pkg = DynamicThreadPoolBanner.class.getPackage(); + final Package pkg = ThreadPoolBannerHandler.class.getPackage(); return pkg != null ? pkg.getImplementationVersion() : ""; } diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunStateHandler.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolRunStateHandler.java similarity index 96% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunStateHandler.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolRunStateHandler.java index 55b54e57..cd453a54 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/core/ThreadPoolRunStateHandler.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/handler/ThreadPoolRunStateHandler.java @@ -1,6 +1,7 @@ -package io.dynamic.threadpool.starter.core; +package io.dynamic.threadpool.starter.handler; import io.dynamic.threadpool.common.model.PoolRunStateInfo; +import io.dynamic.threadpool.starter.core.GlobalThreadPoolManage; import io.dynamic.threadpool.starter.toolkit.thread.CustomThreadPoolExecutor; import io.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/DynamicThreadPoolWrap.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/DynamicThreadPoolWrap.java index df516a11..1955d899 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/DynamicThreadPoolWrap.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/DynamicThreadPoolWrap.java @@ -1,6 +1,6 @@ package io.dynamic.threadpool.starter.wrap; -import io.dynamic.threadpool.starter.config.CommonThreadPool; +import io.dynamic.threadpool.starter.common.CommonThreadPool; import lombok.Data; import java.util.concurrent.Callable; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/ManagerListenerWrap.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/ManagerListenerWrap.java index 27f19505..4611b762 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/ManagerListenerWrap.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/wrap/ManagerListenerWrap.java @@ -1,6 +1,6 @@ package io.dynamic.threadpool.starter.wrap; -import io.dynamic.threadpool.starter.listener.Listener; +import io.dynamic.threadpool.starter.core.Listener; import lombok.Getter; import lombok.Setter;