diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/api/ThreadPoolCheckAlarm.java b/hippo4j-common/src/main/java/cn/hippo4j/common/api/ThreadPoolCheckAlarm.java index 6d4b0768..4b3a3f2a 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/api/ThreadPoolCheckAlarm.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/api/ThreadPoolCheckAlarm.java @@ -17,6 +17,9 @@ package cn.hippo4j.common.api; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; import java.util.concurrent.ThreadPoolExecutor; @@ -29,6 +32,16 @@ import java.util.concurrent.ThreadPoolExecutor; */ public interface ThreadPoolCheckAlarm extends CommandLineRunner { + /** + * Get a none thread pool check alarm. + * + * @return {@link ThreadPoolCheckAlarm} + * @see NoneThreadPoolCheckAlarm + */ + static ThreadPoolCheckAlarm none() { + return NoneThreadPoolCheckAlarm.INSTANCE; + } + /** * Check pool capacity alarm. * @@ -61,4 +74,69 @@ public interface ThreadPoolCheckAlarm extends CommandLineRunner { * @param threadPoolExecutor thread-pool executor */ void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor); + + /** + * None implementation of {@link ThreadPoolCheckAlarm}. + * + * @see #none() + */ + @Slf4j + @NoArgsConstructor(access = AccessLevel.PRIVATE) + class NoneThreadPoolCheckAlarm implements ThreadPoolCheckAlarm { + + /** + * Default singleton. + */ + private static final NoneThreadPoolCheckAlarm INSTANCE = new NoneThreadPoolCheckAlarm(); + + /** + * Check pool capacity alarm. + * + * @param threadPoolId thread-pool id + * @param threadPoolExecutor thread-pool executor + */ + @Override + public void checkPoolCapacityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) { + log.info("Ignore check pool capacity alarm for ExecuteService '{}'", threadPoolId); + } + + /** + * Check pool activity alarm. + * + * @param threadPoolId thread-pool id + * @param threadPoolExecutor thread-pool executor + */ + @Override + public void checkPoolActivityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) { + log.info("Ignore check pool activity alarm for ExecuteService '{}'", threadPoolId); + } + + /** + * Async send rejected alarm. + * + * @param threadPoolId thread-pool id + */ + @Override + public void asyncSendRejectedAlarm(String threadPoolId) { + log.info("Ignore async send rejected alarm for ExecuteService '{}'", threadPoolId); + } + + /** + * Async send execute time-out alarm. + * + * @param threadPoolId thread-pool id + * @param executeTime execute time + * @param executeTimeOut execute time-out + * @param threadPoolExecutor thread-pool executor + */ + @Override + public void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor) { + log.info("Ignore async send execute time out alarm for ExecuteService '{}'", threadPoolId); + } + + @Override + public void run(String... args) throws Exception { + // do nothing + } + } }