From c0b1bb6dceca931e4a0ef799a416b3b4fa0fdffa Mon Sep 17 00:00:00 2001 From: yanrongzhen Date: Mon, 10 Apr 2023 18:41:30 +0800 Subject: [PATCH] Modify the way of obtaining the ID of the web thread pool. --- .../config/DynamicThreadPoolAutoConfiguration.java | 10 +++++++++- .../starter/config/IExecutorProperties.java | 5 +++++ .../starter/config/WebExecutorProperties.java | 5 +++++ .../starter/notify/ConfigModeNotifyConfigBuilder.java | 11 +++++++---- .../event/DynamicThreadPoolRefreshListener.java | 2 +- .../refresher/event/PlatformsRefreshListener.java | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index de2f7313..f277f6c4 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -21,6 +21,7 @@ import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.common.api.ThreadPoolCheckAlarm; import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.config.ApplicationContextHolder; +import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.refresher.event.AdapterExecutorsRefreshListener; @@ -51,6 +52,8 @@ import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; +import java.util.Optional; + /** * Dynamic thread-pool auto-configuration. * @@ -97,7 +100,12 @@ public class DynamicThreadPoolAutoConfiguration { @Bean @ConditionalOnMissingBean - public WebThreadPoolConfigChangeHandler webThreadPoolConfigChangeHandler(Hippo4jSendMessageService hippo4jSendMessageService) { + public WebThreadPoolConfigChangeHandler webThreadPoolConfigChangeHandler(BootstrapConfigProperties bootstrapConfigProperties, + WebThreadPoolService webThreadPoolService, + Hippo4jSendMessageService hippo4jSendMessageService) { + if (bootstrapConfigProperties.getWeb() != null && StringUtil.isBlank(bootstrapConfigProperties.getWeb().getThreadPoolId())) { + bootstrapConfigProperties.getWeb().setThreadPoolId(webThreadPoolService.getWebContainerType().name()); + } return new WebThreadPoolConfigChangeHandler(hippo4jSendMessageService); } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/IExecutorProperties.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/IExecutorProperties.java index d13fbee4..7bda01cf 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/IExecutorProperties.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/IExecutorProperties.java @@ -22,6 +22,11 @@ package cn.hippo4j.config.springboot.starter.config; */ public interface IExecutorProperties { + /** + * Thread pool id + */ + String getThreadPoolId(); + /** * Core pool size */ diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebExecutorProperties.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebExecutorProperties.java index 918503a9..01a850b7 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebExecutorProperties.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebExecutorProperties.java @@ -25,6 +25,11 @@ import lombok.Data; @Data public class WebExecutorProperties implements IExecutorProperties { + /** + * Thread pool id + */ + private String threadPoolId; + /** * Core pool size */ diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/notify/ConfigModeNotifyConfigBuilder.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/notify/ConfigModeNotifyConfigBuilder.java index 3531e715..85369aa0 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/notify/ConfigModeNotifyConfigBuilder.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/notify/ConfigModeNotifyConfigBuilder.java @@ -62,15 +62,17 @@ public class ConfigModeNotifyConfigBuilder implements NotifyConfigBuilder { return resultMap; } for (ExecutorProperties executorProperties : executors) { - Map> buildSingleNotifyConfig = - buildSingleNotifyConfig(executorProperties.getThreadPoolId(), executorProperties); + Map> buildSingleNotifyConfig = buildSingleNotifyConfig(executorProperties); initCacheAndLock(buildSingleNotifyConfig); resultMap.putAll(buildSingleNotifyConfig); } // register notify config for web WebExecutorProperties webProperties = configProperties.getWeb(); + if (StringUtil.isBlank(webProperties.getThreadPoolId())) { + webProperties.setThreadPoolId(webThreadPoolService.getWebContainerType().name()); + } Map> webSingleNotifyConfigMap = - buildSingleNotifyConfig(webThreadPoolService.getWebContainerType().name(), webProperties); + buildSingleNotifyConfig(webProperties); initCacheAndLock(webSingleNotifyConfigMap); resultMap.putAll(webSingleNotifyConfigMap); @@ -83,7 +85,8 @@ public class ConfigModeNotifyConfigBuilder implements NotifyConfigBuilder { * @param executorProperties * @return */ - public Map> buildSingleNotifyConfig(String threadPoolId, IExecutorProperties executorProperties) { + public Map> buildSingleNotifyConfig(IExecutorProperties executorProperties) { + String threadPoolId = executorProperties.getThreadPoolId(); Map> resultMap = new HashMap<>(); String alarmBuildKey = threadPoolId + "+ALARM"; List alarmNotifyConfigs = new ArrayList<>(); diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java index 9370cbfb..f802c27b 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java @@ -168,7 +168,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener changeKeys = new ArrayList<>(); Map> newDynamicThreadPoolNotifyMap = - configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties.getThreadPoolId(), executorProperties); + configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties); Map> notifyConfigs = hippo4jBaseSendMessageService.getNotifyConfigs(); if (CollectionUtil.isNotEmpty(notifyConfigs)) { for (Map.Entry> each : newDynamicThreadPoolNotifyMap.entrySet()) { diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/PlatformsRefreshListener.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/PlatformsRefreshListener.java index 2f417953..f117082f 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/PlatformsRefreshListener.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/PlatformsRefreshListener.java @@ -48,7 +48,7 @@ public class PlatformsRefreshListener extends AbstractRefreshListener> notifyConfig = configBuilder.buildSingleNotifyConfig(threadPoolId, executorProperties); + Map> notifyConfig = configBuilder.buildSingleNotifyConfig(executorProperties); sendMessageService.putPlatform(notifyConfig); wrapper.setInitFlag(Boolean.TRUE); }