diff --git a/hippo4j-core/.gitignore b/hippo4j-core/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/hippo4j-core/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/hippo4j-core/pom.xml b/hippo4j-core/pom.xml new file mode 100644 index 00000000..7b146444 --- /dev/null +++ b/hippo4j-core/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-all + ${revision} + + + hippo4j-core + ${project.artifactId} + ${project.artifactId} + + + + org.projectlombok + lombok + + + + cn.hippo4j + hippo4j-common + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java similarity index 69% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java index 12ad39f2..ccd24306 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java @@ -1,13 +1,14 @@ -package cn.hippo4j.starter.core; +package cn.hippo4j.core.executor; +import cn.hippo4j.core.executor.support.AbstractDynamicExecutorSupport; +import cn.hippo4j.core.proxy.RejectedProxyUtil; import lombok.Getter; import lombok.NonNull; import lombok.Setter; import org.springframework.core.task.TaskDecorator; -import java.lang.reflect.Proxy; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; /** * Dynamic threadPool wrap. @@ -15,16 +16,21 @@ import java.util.concurrent.atomic.AtomicInteger; * @author chen.ma * @date 2021/7/8 21:47 */ -public class DynamicThreadPoolExecutor extends DynamicExecutorConfigurationSupport { +public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport { @Getter @Setter private TaskDecorator taskDecorator; + @Getter + @Setter + private RejectedExecutionHandler redundancyHandler; + @Getter private final String threadPoolId; - private final AtomicInteger rejectCount = new AtomicInteger(); + @Getter + private final AtomicLong rejectCount = new AtomicLong(); public DynamicThreadPoolExecutor(int corePoolSize, int maximumPoolSize, @@ -39,12 +45,12 @@ public class DynamicThreadPoolExecutor extends DynamicExecutorConfigurationSuppo super(corePoolSize, maximumPoolSize, keepAliveTime, unit, waitForTasksToCompleteOnShutdown, awaitTerminationMillis, workQueue, threadPoolId, threadFactory, handler); this.threadPoolId = threadPoolId; - RejectedExecutionHandler rejectedProxy = (RejectedExecutionHandler) Proxy - .newProxyInstance( - handler.getClass().getClassLoader(), - new Class[]{RejectedExecutionHandler.class}, - new RejectedProxyInvocationHandler(handler, rejectCount)); + // Number of dynamic proxy denial policies. + RejectedExecutionHandler rejectedProxy = RejectedProxyUtil.createProxy(handler, rejectCount); setRejectedExecutionHandler(rejectedProxy); + + // Redundant fields to avoid reflecting the acquired fields when sending change information. + redundancyHandler = handler; } @Override @@ -66,7 +72,7 @@ public class DynamicThreadPoolExecutor extends DynamicExecutorConfigurationSuppo * * @return */ - public Integer getRejectCount() { + public Long getRejectCountNum() { return rejectCount.get(); } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/wrapper/DynamicThreadPoolWrapper.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java similarity index 83% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/wrapper/DynamicThreadPoolWrapper.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java index 438e6829..df4a23ab 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/wrapper/DynamicThreadPoolWrapper.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java @@ -1,7 +1,7 @@ -package cn.hippo4j.starter.wrapper; +package cn.hippo4j.core.executor; -import cn.hippo4j.starter.common.CommonDynamicThreadPool; -import cn.hippo4j.starter.core.DynamicExecutorConfigurationSupport; +import cn.hippo4j.core.executor.support.AbstractDynamicExecutorSupport; +import cn.hippo4j.core.executor.support.CommonDynamicThreadPool; import lombok.Data; import org.springframework.beans.factory.DisposableBean; @@ -40,7 +40,7 @@ public class DynamicThreadPoolWrapper implements DisposableBean { /** * executor - * {@link cn.hippo4j.starter.core.DynamicThreadPoolExecutor} + * {@link DynamicThreadPoolExecutor} */ private ThreadPoolExecutor executor; @@ -96,8 +96,8 @@ public class DynamicThreadPoolWrapper implements DisposableBean { @Override public void destroy() throws Exception { - if (executor != null && executor instanceof DynamicExecutorConfigurationSupport) { - ((DynamicExecutorConfigurationSupport) executor).destroy(); + if (executor != null && executor instanceof AbstractDynamicExecutorSupport) { + ((AbstractDynamicExecutorSupport) executor).destroy(); } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/GlobalThreadPoolManage.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java similarity index 96% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/GlobalThreadPoolManage.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java index 5b8c728e..f14cd514 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/GlobalThreadPoolManage.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java @@ -1,7 +1,7 @@ -package cn.hippo4j.starter.core; +package cn.hippo4j.core.executor.manage; import cn.hippo4j.common.model.PoolParameter; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import com.google.common.collect.Lists; import java.util.List; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/AbstractBuildThreadPoolTemplate.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java similarity index 98% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/AbstractBuildThreadPoolTemplate.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java index 5751e47d..ceb712c8 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/AbstractBuildThreadPoolTemplate.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java @@ -1,7 +1,7 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import cn.hippo4j.common.toolkit.Assert; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import lombok.Data; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; @@ -210,3 +210,4 @@ public class AbstractBuildThreadPoolTemplate { } } + diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractDynamicExecutorSupport.java similarity index 82% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractDynamicExecutorSupport.java index a80ba92c..2c265bda 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractDynamicExecutorSupport.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.core; +package cn.hippo4j.core.executor.support; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.DisposableBean; @@ -13,27 +13,27 @@ import java.util.concurrent.*; * @date 2021/11/28 12:17 */ @Slf4j -public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExecutor +public abstract class AbstractDynamicExecutorSupport extends ThreadPoolExecutor implements InitializingBean, DisposableBean { private String threadPoolId; private ExecutorService executor; - protected long awaitTerminationMillis; + public long awaitTerminationMillis; - protected boolean waitForTasksToCompleteOnShutdown; + public boolean waitForTasksToCompleteOnShutdown; - public DynamicExecutorConfigurationSupport(int corePoolSize, - int maximumPoolSize, - long keepAliveTime, - TimeUnit unit, - boolean waitForTasksToCompleteOnShutdown, - long awaitTerminationMillis, - BlockingQueue workQueue, - String threadPoolId, - ThreadFactory threadFactory, - RejectedExecutionHandler handler) { + public AbstractDynamicExecutorSupport(int corePoolSize, + int maximumPoolSize, + long keepAliveTime, + TimeUnit unit, + boolean waitForTasksToCompleteOnShutdown, + long awaitTerminationMillis, + BlockingQueue workQueue, + String threadPoolId, + ThreadFactory threadFactory, + RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); this.threadPoolId = threadPoolId; this.waitForTasksToCompleteOnShutdown = waitForTasksToCompleteOnShutdown; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/common/CommonDynamicThreadPool.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/CommonDynamicThreadPool.java similarity index 76% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/common/CommonDynamicThreadPool.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/CommonDynamicThreadPool.java index 6d14b77e..54f6afdd 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/common/CommonDynamicThreadPool.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/CommonDynamicThreadPool.java @@ -1,8 +1,6 @@ -package cn.hippo4j.starter.common; +package cn.hippo4j.core.executor.support; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import java.util.concurrent.TimeUnit; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/FastThreadPoolExecutor.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/FastThreadPoolExecutor.java similarity index 97% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/FastThreadPoolExecutor.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/FastThreadPoolExecutor.java index d898bde5..200769d7 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/FastThreadPoolExecutor.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/FastThreadPoolExecutor.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import lombok.extern.slf4j.Slf4j; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/QueueTypeEnum.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/QueueTypeEnum.java similarity index 87% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/QueueTypeEnum.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/QueueTypeEnum.java index 57717d48..0552ed04 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/QueueTypeEnum.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/QueueTypeEnum.java @@ -1,7 +1,7 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; -import cn.hippo4j.starter.spi.DynamicTpServiceLoader; -import cn.hippo4j.starter.spi.CustomBlockingQueue; +import cn.hippo4j.core.spi.DynamicThreadPoolServiceLoader; +import cn.hippo4j.core.spi.CustomBlockingQueue; import java.util.Arrays; import java.util.Collection; @@ -62,9 +62,16 @@ public enum QueueTypeEnum { } static { - DynamicTpServiceLoader.register(CustomBlockingQueue.class); + DynamicThreadPoolServiceLoader.register(CustomBlockingQueue.class); } + /** + * Create blocking queue. + * + * @param type + * @param capacity + * @return + */ public static BlockingQueue createBlockingQueue(int type, Integer capacity) { BlockingQueue blockingQueue = null; if (Objects.equals(type, ARRAY_BLOCKING_QUEUE.type)) { @@ -83,7 +90,7 @@ public enum QueueTypeEnum { blockingQueue = new ResizableCapacityLinkedBlockIngQueue(capacity); } - Collection customBlockingQueues = DynamicTpServiceLoader + Collection customBlockingQueues = DynamicThreadPoolServiceLoader .getSingletonServiceInstances(CustomBlockingQueue.class); blockingQueue = Optional.ofNullable(blockingQueue).orElseGet(() -> customBlockingQueues.stream() .filter(each -> Objects.equals(type, each.getType())) @@ -94,6 +101,12 @@ public enum QueueTypeEnum { return blockingQueue; } + /** + * Get blocking queue name by type. + * + * @param type + * @return + */ public static String getBlockingQueueNameByType(int type) { Optional queueTypeEnum = Arrays.stream(QueueTypeEnum.values()) .filter(each -> each.type == type) diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedPolicies.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedPolicies.java similarity index 97% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedPolicies.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedPolicies.java index d98e143b..8ed4c5e8 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedPolicies.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedPolicies.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import lombok.extern.slf4j.Slf4j; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedTypeEnum.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedTypeEnum.java similarity index 85% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedTypeEnum.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedTypeEnum.java index 5ec08a33..66fc0f4f 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/RejectedTypeEnum.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/RejectedTypeEnum.java @@ -1,7 +1,7 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; -import cn.hippo4j.starter.spi.CustomRejectedExecutionHandler; -import cn.hippo4j.starter.spi.DynamicTpServiceLoader; +import cn.hippo4j.core.spi.CustomRejectedExecutionHandler; +import cn.hippo4j.core.spi.DynamicThreadPoolServiceLoader; import java.util.Collection; import java.util.Objects; @@ -64,9 +64,15 @@ public enum RejectedTypeEnum { } static { - DynamicTpServiceLoader.register(CustomRejectedExecutionHandler.class); + DynamicThreadPoolServiceLoader.register(CustomRejectedExecutionHandler.class); } + /** + * Create policy. + * + * @param type + * @return + */ public static RejectedExecutionHandler createPolicy(int type) { Optional rejectedTypeEnum = Stream.of(RejectedTypeEnum.values()) .filter(each -> Objects.equals(type, each.type)) @@ -75,7 +81,7 @@ public enum RejectedTypeEnum { // 使用 SPI 匹配拒绝策略 RejectedExecutionHandler resultRejected = rejectedTypeEnum.orElseGet(() -> { - Collection customRejectedExecutionHandlers = DynamicTpServiceLoader + Collection customRejectedExecutionHandlers = DynamicThreadPoolServiceLoader .getSingletonServiceInstances(CustomRejectedExecutionHandler.class); Optional customRejected = customRejectedExecutionHandlers.stream() .filter(each -> Objects.equals(type, each.getType())) @@ -88,6 +94,12 @@ public enum RejectedTypeEnum { return resultRejected; } + /** + * Get rejected name by type. + * + * @param type + * @return + */ public static String getRejectedNameByType(int type) { return createPolicy(type).getClass().getSimpleName(); } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ResizableCapacityLinkedBlockIngQueue.java similarity index 95% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ResizableCapacityLinkedBlockIngQueue.java index cc5340eb..ff900969 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ResizableCapacityLinkedBlockIngQueue.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import cn.hutool.core.util.ReflectUtil; import lombok.extern.slf4j.Slf4j; @@ -34,7 +34,6 @@ public class ResizableCapacityLinkedBlockIngQueue extends LinkedBlockingQueue ReflectUtil.invoke(this, "signalNotFull"); } } catch (Exception ex) { - // ignore log.error("Dynamic modification of blocking queue size failed.", ex); successFlag = false; } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/TaskQueue.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/TaskQueue.java similarity index 97% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/TaskQueue.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/TaskQueue.java index f1de9ede..7bfd78ad 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/TaskQueue.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/TaskQueue.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadFactoryBuilder.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java similarity index 99% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadFactoryBuilder.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java index ff1d5fea..4a395f77 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadFactoryBuilder.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import cn.hippo4j.common.design.builder.Builder; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolBuilder.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java similarity index 99% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolBuilder.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java index 039caca4..0e228bb4 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolBuilder.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; import cn.hippo4j.common.design.builder.Builder; import cn.hippo4j.common.toolkit.Assert; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolExecutorTemplate.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolExecutorTemplate.java similarity index 95% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolExecutorTemplate.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolExecutorTemplate.java index 2b9ec640..6810b57d 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadPoolExecutorTemplate.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolExecutorTemplate.java @@ -1,6 +1,7 @@ -package cn.hippo4j.starter.toolkit.thread; +package cn.hippo4j.core.executor.support; -import cn.hippo4j.starter.toolkit.ArrayUtil; + +import cn.hippo4j.common.toolkit.ArrayUtil; import java.util.concurrent.*; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/RejectedProxyInvocationHandler.java b/hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyInvocationHandler.java similarity index 84% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/RejectedProxyInvocationHandler.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyInvocationHandler.java index 2db78af8..9f95b3e7 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/RejectedProxyInvocationHandler.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyInvocationHandler.java @@ -1,11 +1,11 @@ -package cn.hippo4j.starter.core; +package cn.hippo4j.core.proxy; import lombok.AllArgsConstructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; /** * Rejected proxy invocation handler. @@ -18,7 +18,7 @@ public class RejectedProxyInvocationHandler implements InvocationHandler { private final Object target; - private final AtomicInteger rejectCount; + private final AtomicLong rejectCount; @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyUtil.java b/hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyUtil.java new file mode 100644 index 00000000..439009fb --- /dev/null +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/proxy/RejectedProxyUtil.java @@ -0,0 +1,33 @@ +package cn.hippo4j.core.proxy; + +import java.lang.reflect.Proxy; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Rejected proxy util. + * + * @author chen.ma + * @date 2022/2/22 21:56 + */ +public class RejectedProxyUtil { + + /** + * Proxy rejected execution. + * + * @param rejectedExecutionHandler + * @param rejectedNum + * @return + */ + public static RejectedExecutionHandler createProxy(RejectedExecutionHandler rejectedExecutionHandler, AtomicLong rejectedNum) { + RejectedExecutionHandler rejectedProxy = (RejectedExecutionHandler) Proxy + .newProxyInstance( + rejectedExecutionHandler.getClass().getClassLoader(), + new Class[]{RejectedExecutionHandler.class}, + new RejectedProxyInvocationHandler(rejectedExecutionHandler, rejectedNum) + ); + + return rejectedProxy; + } + +} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ThreadPoolDynamicRefresh.java b/hippo4j-core/src/main/java/cn/hippo4j/core/refresh/ThreadPoolDynamicRefresh.java similarity index 63% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ThreadPoolDynamicRefresh.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/refresh/ThreadPoolDynamicRefresh.java index 55d4c368..b8d0f1f6 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ThreadPoolDynamicRefresh.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/refresh/ThreadPoolDynamicRefresh.java @@ -1,17 +1,22 @@ -package cn.hippo4j.starter.core; +package cn.hippo4j.core.refresh; import cn.hippo4j.common.enums.EnableEnum; import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.common.toolkit.JSONUtil; -import cn.hippo4j.starter.alarm.ThreadPoolAlarmManage; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.RejectedTypeEnum; -import cn.hippo4j.starter.toolkit.thread.ResizableCapacityLinkedBlockIngQueue; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.AbstractDynamicExecutorSupport; +import cn.hippo4j.core.executor.support.QueueTypeEnum; +import cn.hippo4j.core.executor.support.RejectedTypeEnum; +import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue; +import cn.hippo4j.core.proxy.RejectedProxyUtil; import lombok.extern.slf4j.Slf4j; import java.util.Objects; +import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; /** * ThreadPool dynamic refresh. @@ -24,7 +29,8 @@ public class ThreadPoolDynamicRefresh { public static void refreshDynamicPool(String content) { PoolParameterInfo parameter = JSONUtil.parseObject(content, PoolParameterInfo.class); - ThreadPoolAlarmManage.sendPoolConfigChange(parameter); + // TODO 抽象报警通知模块 + // ThreadPoolAlarmManage.sendPoolConfigChange(parameter); ThreadPoolDynamicRefresh.refreshDynamicPool(parameter); } @@ -37,14 +43,28 @@ public class ThreadPoolDynamicRefresh { String originalQuery = executor.getQueue().getClass().getSimpleName(); int originalCapacity = executor.getQueue().remainingCapacity() + executor.getQueue().size(); long originalKeepAliveTime = executor.getKeepAliveTime(TimeUnit.SECONDS); - String originalRejected = executor.getRejectedExecutionHandler().getClass().getSimpleName(); boolean originalAllowCoreThreadTimeOut = executor.allowsCoreThreadTimeOut(); + String originalRejected; + RejectedExecutionHandler rejectedExecutionHandler = executor.getRejectedExecutionHandler(); + if (executor instanceof AbstractDynamicExecutorSupport) { + DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) executor; + rejectedExecutionHandler = dynamicExecutor.getRedundancyHandler(); + } + originalRejected = rejectedExecutionHandler.getClass().getSimpleName(); + changePoolInfo(executor, parameter); ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); log.info( - "[🔥 {}] Changed thread pool. \ncoreSize :: [{}], maxSize :: [{}], queueType :: [{}], capacity :: [{}], keepAliveTime :: [{}], rejectedType :: [{}], allowCoreThreadTimeOut :: [{}]", + "[🔥 {}] Changed thread pool. " + + "\n coreSize :: [{}]" + + "\n maxSize :: [{}]" + + "\n queueType :: [{}]" + + "\n capacity :: [{}]" + + "\n keepAliveTime :: [{}]" + + "\n rejectedType :: [{}]" + + "\n allowCoreThreadTimeOut :: [{}]", threadPoolId.toUpperCase(), String.format("%s => %s", originalCoreSize, afterExecutor.getCorePoolSize()), String.format("%s => %s", originalMaximumPoolSize, afterExecutor.getMaximumPoolSize()), @@ -81,7 +101,15 @@ public class ThreadPoolDynamicRefresh { } if (parameter.getRejectedType() != null) { - executor.setRejectedExecutionHandler(RejectedTypeEnum.createPolicy(parameter.getRejectedType())); + RejectedExecutionHandler rejectedExecutionHandler = RejectedTypeEnum.createPolicy(parameter.getRejectedType()); + if (executor instanceof AbstractDynamicExecutorSupport) { + DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) executor; + dynamicExecutor.setRedundancyHandler(rejectedExecutionHandler); + AtomicLong rejectCount = dynamicExecutor.getRejectCount(); + rejectedExecutionHandler = RejectedProxyUtil.createProxy(rejectedExecutionHandler, rejectCount); + } + + executor.setRejectedExecutionHandler(rejectedExecutionHandler); } if (parameter.getAllowCoreThreadTimeOut() != null) { diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomBlockingQueue.java b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomBlockingQueue.java similarity index 92% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomBlockingQueue.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomBlockingQueue.java index b62795ca..37f665f0 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomBlockingQueue.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomBlockingQueue.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.spi; +package cn.hippo4j.core.spi; import java.util.concurrent.BlockingQueue; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomRejectedExecutionHandler.java b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomRejectedExecutionHandler.java similarity index 92% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomRejectedExecutionHandler.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomRejectedExecutionHandler.java index c3f6ade8..1e466781 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/CustomRejectedExecutionHandler.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/CustomRejectedExecutionHandler.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.spi; +package cn.hippo4j.core.spi; import java.util.concurrent.RejectedExecutionHandler; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/DynamicTpServiceLoader.java b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoader.java similarity index 73% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/DynamicTpServiceLoader.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoader.java index f9e8e40f..c9d6ab86 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/DynamicTpServiceLoader.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoader.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.spi; +package cn.hippo4j.core.spi; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -10,16 +10,28 @@ import java.util.stream.Collectors; * @author chen.ma * @date 2021/7/10 23:45 */ -public class DynamicTpServiceLoader { +public class DynamicThreadPoolServiceLoader { private static final Map, Collection> SERVICES = new ConcurrentHashMap(); + /** + * Register. + * + * @param serviceInterface + */ public static void register(final Class serviceInterface) { if (!SERVICES.containsKey(serviceInterface)) { SERVICES.put(serviceInterface, load(serviceInterface)); } } + /** + * Load. + * + * @param serviceInterface + * @param + * @return + */ private static Collection load(final Class serviceInterface) { Collection result = new LinkedList<>(); for (T each : ServiceLoader.load(serviceInterface)) { @@ -28,14 +40,34 @@ public class DynamicTpServiceLoader { return result; } + /** + * Get singleton service instances. + * + * @param service + * @param + * @return + */ public static Collection getSingletonServiceInstances(final Class service) { return (Collection) SERVICES.getOrDefault(service, Collections.emptyList()); } + /** + * New service instances. + * + * @param service + * @param + * @return + */ public static Collection newServiceInstances(final Class service) { return SERVICES.containsKey(service) ? SERVICES.get(service).stream().map(each -> (T) newServiceInstance(each.getClass())).collect(Collectors.toList()) : Collections.emptyList(); } + /** + * New service instance. + * + * @param clazz + * @return + */ private static Object newServiceInstance(final Class clazz) { try { return clazz.newInstance(); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/ServiceLoaderInstantiationException.java b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/ServiceLoaderInstantiationException.java similarity index 92% rename from hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/ServiceLoaderInstantiationException.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/spi/ServiceLoaderInstantiationException.java index a0116a3c..9d50d42c 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/spi/ServiceLoaderInstantiationException.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/spi/ServiceLoaderInstantiationException.java @@ -1,4 +1,4 @@ -package cn.hippo4j.starter.spi; +package cn.hippo4j.core.spi; /** * Service loader instantiation exception. diff --git a/hippo4j-core/src/main/resources/application.properties b/hippo4j-core/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/hippo4j-core/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java index f6688686..49985622 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java @@ -2,12 +2,15 @@ package cn.hippo4j.starter.alarm; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.model.PoolParameterInfo; +import cn.hippo4j.common.notify.AlarmControlDTO; +import cn.hippo4j.common.notify.AlarmControlHandler; +import cn.hippo4j.common.notify.NotifyTypeEnum; import cn.hippo4j.common.toolkit.GroupKey; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.web.base.Result; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.starter.config.BootstrapProperties; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.starter.remote.HttpAgent; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; @@ -49,7 +52,7 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ private final Map sendMessageHandlers = Maps.newHashMap(); @Override - public void sendAlarmMessage(MessageTypeEnum typeEnum, DynamicThreadPoolExecutor executor) { + public void sendAlarmMessage(NotifyTypeEnum typeEnum, DynamicThreadPoolExecutor executor) { String threadPoolId = executor.getThreadPoolId(); String buildKey = StrUtil.builder(executor.getThreadPoolId(), "+", "ALARM").toString(); List notifyList = ALARM_NOTIFY_CONFIG.get(buildKey); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java index 93a514cc..cc16407f 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java @@ -1,5 +1,6 @@ package cn.hippo4j.starter.alarm; +import cn.hippo4j.common.notify.NotifyTypeEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -56,6 +57,6 @@ public class NotifyDTO { /** * 报警类型 */ - private MessageTypeEnum typeEnum; + private NotifyTypeEnum typeEnum; } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java index ca26ff86..85aea2af 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java @@ -1,7 +1,7 @@ package cn.hippo4j.starter.alarm; import cn.hippo4j.common.model.PoolParameterInfo; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; /** * Send message handler. diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java index 66930beb..ec304466 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java @@ -1,7 +1,8 @@ package cn.hippo4j.starter.alarm; import cn.hippo4j.common.model.PoolParameterInfo; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; +import cn.hippo4j.common.notify.NotifyTypeEnum; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; /** * Send msg. @@ -17,7 +18,7 @@ public interface SendMessageService { * @param typeEnum * @param threadPoolExecutor */ - void sendAlarmMessage(MessageTypeEnum typeEnum, DynamicThreadPoolExecutor threadPoolExecutor); + void sendAlarmMessage(NotifyTypeEnum typeEnum, DynamicThreadPoolExecutor threadPoolExecutor); /** * Send change message. diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java index 7bd1a6a1..9172d0a3 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java @@ -2,8 +2,9 @@ package cn.hippo4j.starter.alarm; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.model.PoolParameterInfo; +import cn.hippo4j.common.notify.NotifyTypeEnum; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.starter.config.MessageAlarmConfiguration; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; import cn.hippo4j.starter.toolkit.CalculateUtil; import lombok.extern.slf4j.Slf4j; @@ -54,7 +55,7 @@ public class ThreadPoolAlarmManage { && divide > threadPoolAlarm.getCapacityAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.CAPACITY); if (isSend) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.CAPACITY, threadPoolExecutor); + SEND_MESSAGE_SERVICE.sendAlarmMessage(NotifyTypeEnum.CAPACITY, threadPoolExecutor); } } @@ -81,7 +82,7 @@ public class ThreadPoolAlarmManage { && divide > threadPoolAlarm.getLivenessAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.LIVENESS); if (isSend) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.LIVENESS, threadPoolExecutor); + SEND_MESSAGE_SERVICE.sendAlarmMessage(NotifyTypeEnum.ACTIVITY, threadPoolExecutor); } } @@ -101,7 +102,7 @@ public class ThreadPoolAlarmManage { */ ThreadPoolAlarm threadPoolAlarm = new ThreadPoolAlarm(null, 80, 80); if (threadPoolAlarm.getIsAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.REJECT)) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.REJECT, threadPoolExecutor); + SEND_MESSAGE_SERVICE.sendAlarmMessage(NotifyTypeEnum.REJECT, threadPoolExecutor); } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ding/DingSendMessageHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ding/DingSendMessageHandler.java index 965583c5..f43c93de 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ding/DingSendMessageHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ding/DingSendMessageHandler.java @@ -4,13 +4,13 @@ import cn.hippo4j.common.enums.EnableEnum; import cn.hippo4j.common.model.InstanceInfo; import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.starter.alarm.NotifyDTO; -import cn.hippo4j.starter.alarm.NotifyPlatformEnum; +import cn.hippo4j.common.notify.NotifyPlatformEnum; import cn.hippo4j.starter.alarm.SendMessageHandler; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.RejectedTypeEnum; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.QueueTypeEnum; +import cn.hippo4j.core.executor.support.RejectedTypeEnum; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hutool.core.date.DateUtil; import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; @@ -98,7 +98,7 @@ public class DingSendMessageHandler implements SendMessageHandler { // 拒绝策略名称 pool.getRejectedExecutionHandler().getClass().getSimpleName(), // 拒绝策略次数 - pool.getRejectCount(), + pool.getRejectCountNum(), // 告警手机号 afterReceives, // 报警频率 diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/lark/LarkSendMessageHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/lark/LarkSendMessageHandler.java index 20cae30d..5b34ae2f 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/lark/LarkSendMessageHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/lark/LarkSendMessageHandler.java @@ -5,13 +5,13 @@ import cn.hippo4j.common.model.InstanceInfo; import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.starter.alarm.NotifyDTO; -import cn.hippo4j.starter.alarm.NotifyPlatformEnum; +import cn.hippo4j.common.notify.NotifyPlatformEnum; import cn.hippo4j.starter.alarm.SendMessageHandler; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.RejectedTypeEnum; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.QueueTypeEnum; +import cn.hippo4j.core.executor.support.RejectedTypeEnum; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; @@ -105,7 +105,7 @@ public class LarkSendMessageHandler implements SendMessageHandler { // 拒绝策略名称 pool.getRejectedExecutionHandler().getClass().getSimpleName(), // 拒绝策略次数 - pool.getRejectCount(), + pool.getRejectCountNum(), // 告警姓名 afterReceives, // 当前时间 diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/wechat/WeChatSendMessageHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/wechat/WeChatSendMessageHandler.java index 02619b75..a0a9730c 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/wechat/WeChatSendMessageHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/wechat/WeChatSendMessageHandler.java @@ -5,13 +5,13 @@ import cn.hippo4j.common.model.InstanceInfo; import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.starter.alarm.NotifyDTO; -import cn.hippo4j.starter.alarm.NotifyPlatformEnum; +import cn.hippo4j.common.notify.NotifyPlatformEnum; import cn.hippo4j.starter.alarm.SendMessageHandler; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.RejectedTypeEnum; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.QueueTypeEnum; +import cn.hippo4j.core.executor.support.RejectedTypeEnum; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hutool.core.date.DateUtil; import cn.hutool.http.HttpRequest; import com.google.common.base.Joiner; @@ -86,7 +86,7 @@ public class WeChatSendMessageHandler implements SendMessageHandler { // 拒绝策略名称 pool.getRejectedExecutionHandler().getClass().getSimpleName(), // 拒绝策略次数 - pool.getRejectCount(), + pool.getRejectCountNum(), // 告警手机号 afterReceives, // 报警频率 diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfiguration.java index f10d2efd..827b17a8 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfiguration.java @@ -1,7 +1,7 @@ package cn.hippo4j.starter.config; import cn.hippo4j.common.model.InstanceInfo; -import cn.hippo4j.starter.alarm.AlarmControlHandler; +import cn.hippo4j.common.notify.AlarmControlHandler; import cn.hippo4j.starter.alarm.BaseSendMessageService; import cn.hippo4j.starter.alarm.SendMessageHandler; import cn.hippo4j.starter.alarm.SendMessageService; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/CacheData.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/CacheData.java index c6a82052..3ec96337 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/CacheData.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/CacheData.java @@ -1,5 +1,6 @@ package cn.hippo4j.starter.core; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.starter.wrapper.ManagerListenerWrapper; import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.Md5Util; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ClientWorker.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ClientWorker.java index b4a90ece..70f8016a 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ClientWorker.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ClientWorker.java @@ -7,7 +7,7 @@ import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.web.base.Result; import cn.hippo4j.starter.remote.HttpAgent; import cn.hippo4j.starter.remote.ServerHealthCheck; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import cn.hutool.core.util.IdUtil; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ConfigAdapter.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ConfigAdapter.java index 99d4adad..3b6e3ae9 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ConfigAdapter.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/ConfigAdapter.java @@ -1,5 +1,7 @@ package cn.hippo4j.starter.core; +import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh; + /** * Config adapter. * diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DiscoveryClient.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DiscoveryClient.java index eb42b97f..ed8e965f 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DiscoveryClient.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DiscoveryClient.java @@ -7,7 +7,7 @@ import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Results; import cn.hippo4j.common.web.exception.ErrorCodeEnum; import cn.hippo4j.starter.remote.HttpAgent; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import cn.hutool.core.text.StrBuilder; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolPostProcessor.java index fe8d3602..8df80b30 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolPostProcessor.java @@ -6,14 +6,14 @@ import cn.hippo4j.common.enums.EnableEnum; import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.web.base.Result; -import cn.hippo4j.starter.common.CommonDynamicThreadPool; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.*; import cn.hippo4j.starter.config.BootstrapProperties; import cn.hippo4j.starter.remote.HttpAgent; import cn.hippo4j.starter.toolkit.DynamicThreadPoolAnnotationUtil; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.RejectedTypeEnum; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; @@ -142,7 +142,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { .build(); // 设置动态线程池增强参数 - if (dynamicThreadPoolWrap.getExecutor() instanceof DynamicExecutorConfigurationSupport) { + if (dynamicThreadPoolWrap.getExecutor() instanceof AbstractDynamicExecutorSupport) { TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).getTaskDecorator(); ((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setTaskDecorator(taskDecorator); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/MonitorEventExecutor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/MonitorEventExecutor.java index a7995bcf..2648cec4 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/MonitorEventExecutor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/MonitorEventExecutor.java @@ -1,8 +1,8 @@ package cn.hippo4j.starter.event; import cn.hippo4j.common.function.NoArgsConsumer; -import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; +import cn.hippo4j.core.executor.support.QueueTypeEnum; +import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.ExecutorService; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/AbstractThreadPoolRuntime.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/AbstractThreadPoolRuntime.java index 924ef2c5..017fe064 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/AbstractThreadPoolRuntime.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/AbstractThreadPoolRuntime.java @@ -2,10 +2,10 @@ package cn.hippo4j.starter.handler; import cn.hippo4j.common.model.PoolBaseInfo; import cn.hippo4j.common.model.PoolRunStateInfo; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.starter.toolkit.CalculateUtil; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hutool.core.date.DateUtil; import java.util.Date; @@ -103,9 +103,9 @@ public abstract class AbstractThreadPoolRuntime { stateInfo.setLargestPoolSize(largestPoolSize); stateInfo.setCompletedTaskCount(completedTaskCount); - int rejectCount = pool instanceof DynamicThreadPoolExecutor - ? ((DynamicThreadPoolExecutor) pool).getRejectCount() - : -1; + long rejectCount = pool instanceof DynamicThreadPoolExecutor + ? ((DynamicThreadPoolExecutor) pool).getRejectCountNum() + : -1L; stateInfo.setRejectCount(rejectCount); stateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date())); stateInfo.setTimestamp(System.currentTimeMillis()); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/BaseThreadDetailStateHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/BaseThreadDetailStateHandler.java index 176c9d5f..acaa676d 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/BaseThreadDetailStateHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/BaseThreadDetailStateHandler.java @@ -4,8 +4,8 @@ import cn.hippo4j.common.api.ThreadDetailState; import cn.hippo4j.common.model.ThreadDetailStateInfo; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.ReflectUtil; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/ThreadPoolRunStateHandler.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/ThreadPoolRunStateHandler.java index 2d765862..24a9f419 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/ThreadPoolRunStateHandler.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/handler/ThreadPoolRunStateHandler.java @@ -2,10 +2,12 @@ package cn.hippo4j.starter.handler; import cn.hippo4j.common.model.ManyPoolRunStateInfo; import cn.hippo4j.common.model.PoolRunStateInfo; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.support.AbstractDynamicExecutorSupport; import cn.hippo4j.starter.toolkit.ByteConvertUtil; import cn.hippo4j.starter.toolkit.inet.InetUtils; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.system.RuntimeInfo; @@ -53,7 +55,13 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime { String threadPoolId = poolRunStateInfo.getTpId(); DynamicThreadPoolWrapper executorService = GlobalThreadPoolManage.getExecutorService(threadPoolId); ThreadPoolExecutor pool = executorService.getExecutor(); - String rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName(); + + String rejectedName; + if (pool instanceof AbstractDynamicExecutorSupport) { + rejectedName = ((DynamicThreadPoolExecutor) pool).getRedundancyHandler().getClass().getSimpleName(); + } else { + rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName(); + } poolRunStateInfo.setRejectedName(rejectedName); ManyPoolRunStateInfo manyPoolRunStateInfo = BeanUtil.toBean(poolRunStateInfo, ManyPoolRunStateInfo.class); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/ReportingEventExecutor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/ReportingEventExecutor.java index f02a68c0..b46895d6 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/ReportingEventExecutor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/ReportingEventExecutor.java @@ -6,8 +6,8 @@ import cn.hippo4j.starter.config.BootstrapProperties; import cn.hippo4j.starter.monitor.collect.Collector; import cn.hippo4j.starter.monitor.send.MessageSender; import cn.hippo4j.starter.remote.ServerHealthCheck; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; -import cn.hippo4j.starter.toolkit.thread.ThreadUtil; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; +import cn.hippo4j.common.toolkit.ThreadUtil; import cn.hutool.core.collection.CollUtil; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -23,7 +23,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import static cn.hippo4j.starter.core.GlobalThreadPoolManage.getThreadPoolNum; +import static cn.hippo4j.core.executor.manage.GlobalThreadPoolManage.getThreadPoolNum; /** * 动态线程池采集上报事件执行器. diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/collect/RunTimeInfoCollector.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/collect/RunTimeInfoCollector.java index c7b8680d..f5ea6058 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/collect/RunTimeInfoCollector.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/monitor/collect/RunTimeInfoCollector.java @@ -6,7 +6,7 @@ import cn.hippo4j.common.monitor.Message; import cn.hippo4j.common.monitor.MessageTypeEnum; import cn.hippo4j.common.monitor.RuntimeMessage; import cn.hippo4j.starter.config.BootstrapProperties; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.starter.handler.AbstractThreadPoolRuntime; import cn.hutool.core.bean.BeanUtil; import com.google.common.collect.Lists; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/AbstractHealthCheck.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/AbstractHealthCheck.java index f40d8e07..c6453d35 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/AbstractHealthCheck.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/AbstractHealthCheck.java @@ -2,7 +2,7 @@ package cn.hippo4j.starter.remote; import cn.hippo4j.starter.core.ShutdownExecuteException; import cn.hippo4j.starter.event.ApplicationCompleteEvent; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/ServerHttpAgent.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/ServerHttpAgent.java index a0b258a5..fa83be85 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/ServerHttpAgent.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/remote/ServerHttpAgent.java @@ -6,7 +6,7 @@ import cn.hippo4j.common.web.base.Result; import cn.hippo4j.starter.config.BootstrapProperties; import cn.hippo4j.starter.security.SecurityProxy; import cn.hippo4j.starter.toolkit.HttpClientUtil; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Maps; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/ArrayUtil.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/ArrayUtil.java deleted file mode 100644 index e1e0652d..00000000 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/ArrayUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.hippo4j.starter.toolkit; - -import java.lang.reflect.Array; - -/** - * Array util. - * - * @author chen.ma - * @date 2021/7/5 21:54 - */ -public class ArrayUtil { - - public static T[] addAll(final T[] array1, @SuppressWarnings("unchecked") final T... array2) { - if (array1 == null) { - return clone(array2); - } else if (array2 == null) { - return clone(array1); - } - final Class type1 = array1.getClass().getComponentType(); - @SuppressWarnings("unchecked") final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length); - System.arraycopy(array1, 0, joinedArray, 0, array1.length); - try { - System.arraycopy(array2, 0, joinedArray, array1.length, array2.length); - } catch (final ArrayStoreException ase) { - final Class type2 = array2.getClass().getComponentType(); - if (!type1.isAssignableFrom(type2)) { - throw new IllegalArgumentException("Cannot store " + type2.getName() + " in an array of " - + type1.getName(), ase); - } - throw ase; - } - return joinedArray; - } - - public static T[] clone(final T[] array) { - if (array == null) { - return null; - } - return array.clone(); - } - -} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/inet/InetUtils.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/inet/InetUtils.java index 2844c1b8..5b27d84a 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/inet/InetUtils.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/inet/InetUtils.java @@ -1,6 +1,6 @@ package cn.hippo4j.starter.toolkit.inet; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; +import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadUtil.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadUtil.java deleted file mode 100644 index aa2124e4..00000000 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/toolkit/thread/ThreadUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.hippo4j.starter.toolkit.thread; - -/** - * Thread util. - * - * @author chen.ma - * @date 2021/12/6 23:34 - */ -public class ThreadUtil { - - /** - * 创建新线程. - * - * @param runnable {@link Runnable} - * @param name 线程名 - * @param isDaemon 是否守护线程 - * @return {@link Thread} - */ - public static Thread newThread(Runnable runnable, String name, boolean isDaemon) { - Thread t = new Thread(null, runnable, name); - t.setDaemon(isDaemon); - return t; - } - - /** - * 挂起当前线程. - * - * @param millis 毫秒 - * @return - */ - public static boolean sleep(long millis) { - if (millis > 0) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - return false; - } - } - - return true; - } - -} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/MonitorPerformanceTest.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/MonitorPerformanceTest.java index 19086a73..a4b18134 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/MonitorPerformanceTest.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/MonitorPerformanceTest.java @@ -2,13 +2,13 @@ package cn.hippo4j.starter.test; import cn.hippo4j.common.model.PoolRunStateInfo; import cn.hippo4j.common.toolkit.JSONUtil; -import cn.hippo4j.starter.core.GlobalThreadPoolManage; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.starter.monitor.collect.RunTimeInfoCollector; -import cn.hippo4j.starter.toolkit.thread.ResizableCapacityLinkedBlockIngQueue; -import cn.hippo4j.starter.toolkit.thread.ThreadFactoryBuilder; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; -import cn.hippo4j.starter.toolkit.thread.ThreadUtil; -import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue; +import cn.hippo4j.core.executor.support.ThreadFactoryBuilder; +import cn.hippo4j.core.executor.support.ThreadPoolBuilder; +import cn.hippo4j.common.toolkit.ThreadUtil; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.ScheduledThreadPoolExecutor; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/RejectedExecutionHandlerProxyTest.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/RejectedExecutionHandlerProxyTest.java index 7016f70d..ce54ece6 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/RejectedExecutionHandlerProxyTest.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/RejectedExecutionHandlerProxyTest.java @@ -1,8 +1,8 @@ package cn.hippo4j.starter.test; -import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; -import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; -import cn.hippo4j.starter.toolkit.thread.ThreadUtil; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.support.ThreadPoolBuilder; +import cn.hippo4j.common.toolkit.ThreadUtil; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.LinkedBlockingQueue; @@ -44,7 +44,7 @@ public class RejectedExecutionHandlerProxyTest { ThreadUtil.sleep(1000); DynamicThreadPoolExecutor dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) executor; - Integer rejectCount = dynamicThreadPoolExecutor.getRejectCount(); + long rejectCount = dynamicThreadPoolExecutor.getRejectCountNum(); log.info("ThreadPool name :: {}, Reject count :: {}", Thread.currentThread().getName(), rejectCount); } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/ResizableCapacityLinkedBlockIngQueueTest.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/ResizableCapacityLinkedBlockIngQueueTest.java index 90744039..466c2259 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/ResizableCapacityLinkedBlockIngQueueTest.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/test/java/cn/hippo4j/starter/test/ResizableCapacityLinkedBlockIngQueueTest.java @@ -1,6 +1,6 @@ package cn.hippo4j.starter.test; -import cn.hippo4j.starter.toolkit.thread.ResizableCapacityLinkedBlockIngQueue; +import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.LinkedBlockingQueue;