Modify the way of obtaining the ID of the web thread pool.

pull/1133/head
yanrongzhen 2 years ago
parent 22b4d0a984
commit c0b1bb6dce

@ -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);
}

@ -22,6 +22,11 @@ package cn.hippo4j.config.springboot.starter.config;
*/
public interface IExecutorProperties {
/**
* Thread pool id
*/
String getThreadPoolId();
/**
* Core pool size
*/

@ -25,6 +25,11 @@ import lombok.Data;
@Data
public class WebExecutorProperties implements IExecutorProperties {
/**
* Thread pool id
*/
private String threadPoolId;
/**
* Core pool size
*/

@ -62,15 +62,17 @@ public class ConfigModeNotifyConfigBuilder implements NotifyConfigBuilder {
return resultMap;
}
for (ExecutorProperties executorProperties : executors) {
Map<String, List<NotifyConfigDTO>> buildSingleNotifyConfig =
buildSingleNotifyConfig(executorProperties.getThreadPoolId(), executorProperties);
Map<String, List<NotifyConfigDTO>> 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<String, List<NotifyConfigDTO>> 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<String, List<NotifyConfigDTO>> buildSingleNotifyConfig(String threadPoolId, IExecutorProperties executorProperties) {
public Map<String, List<NotifyConfigDTO>> buildSingleNotifyConfig(IExecutorProperties executorProperties) {
String threadPoolId = executorProperties.getThreadPoolId();
Map<String, List<NotifyConfigDTO>> resultMap = new HashMap<>();
String alarmBuildKey = threadPoolId + "+ALARM";
List<NotifyConfigDTO> alarmNotifyConfigs = new ArrayList<>();

@ -168,7 +168,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
boolean checkNotifyAlarm = false;
List<String> changeKeys = new ArrayList<>();
Map<String, List<NotifyConfigDTO>> newDynamicThreadPoolNotifyMap =
configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties.getThreadPoolId(), executorProperties);
configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties);
Map<String, List<NotifyConfigDTO>> notifyConfigs = hippo4jBaseSendMessageService.getNotifyConfigs();
if (CollectionUtil.isNotEmpty(notifyConfigs)) {
for (Map.Entry<String, List<NotifyConfigDTO>> each : newDynamicThreadPoolNotifyMap.entrySet()) {

@ -48,7 +48,7 @@ public class PlatformsRefreshListener extends AbstractRefreshListener<ExecutorPr
if (wrapper != null && !wrapper.isInitFlag()) {
Hippo4jBaseSendMessageService sendMessageService = ApplicationContextHolder.getBean(Hippo4jBaseSendMessageService.class);
ConfigModeNotifyConfigBuilder configBuilder = ApplicationContextHolder.getBean(ConfigModeNotifyConfigBuilder.class);
Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(threadPoolId, executorProperties);
Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(executorProperties);
sendMessageService.putPlatform(notifyConfig);
wrapper.setInitFlag(Boolean.TRUE);
}

Loading…
Cancel
Save