Merge pull request #479 from mabaiwan/develop

hippo4j-core-spring-boot-starter code naming and log optimization
pull/483/head
小马哥 2 years ago committed by GitHub
commit c8e2243a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,10 @@
package cn.hippo4j.common.model; package cn.hippo4j.common.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
@ -26,6 +29,9 @@ import java.io.Serializable;
* Thread pool parameter info. * Thread pool parameter info.
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class ThreadPoolParameterInfo implements ThreadPoolParameter, Serializable { public class ThreadPoolParameterInfo implements ThreadPoolParameter, Serializable {

@ -18,12 +18,18 @@
package cn.hippo4j.message.request; package cn.hippo4j.message.request;
import cn.hippo4j.message.request.base.BaseNotifyRequest; import cn.hippo4j.message.request.base.BaseNotifyRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* Change parameter notify request. * Change parameter notify request.
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChangeParameterNotifyRequest extends BaseNotifyRequest { public class ChangeParameterNotifyRequest extends BaseNotifyRequest {
private String active; private String active;

@ -19,9 +19,6 @@ package cn.hippo4j.core.springboot.starter.common;
/** /**
* Config file type enum. * Config file type enum.
*
* @author chen.ma
* @date 2022/2/26 18:12
*/ */
public enum ConfigFileTypeEnum { public enum ConfigFileTypeEnum {

@ -27,10 +27,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Bootstrap properties. * Bootstrap core properties.
*
* @author chen.ma
* @date 2022/2/25 00:35
*/ */
@Getter @Getter
@Setter @Setter

@ -48,7 +48,7 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
/** /**
* Dynamic thread-pool core auto-configuration. * Dynamic thread-pool core auto configuration.
*/ */
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor

@ -27,61 +27,58 @@ import java.util.Objects;
/** /**
* Executor properties. * Executor properties.
*
* @author chen.ma
* @date 2022/2/25 00:40
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class ExecutorProperties { public class ExecutorProperties {
/** /**
* threadPoolId * Thread pool id
*/ */
private String threadPoolId; private String threadPoolId;
/** /**
* corePoolSize * Core pool size
*/ */
private Integer corePoolSize; private Integer corePoolSize;
/** /**
* maximumPoolSize * Maximum pool size
*/ */
private Integer maximumPoolSize; private Integer maximumPoolSize;
/** /**
* queueCapacity * Queue capacity
*/ */
private Integer queueCapacity; private Integer queueCapacity;
/** /**
* blockingQueue * Blocking queue
*/ */
private String blockingQueue; private String blockingQueue;
/** /**
* rejectedHandler * Rejected handler
*/ */
private String rejectedHandler; private String rejectedHandler;
/** /**
* keepAliveTime * Keep alive time
*/ */
private Long keepAliveTime; private Long keepAliveTime;
/** /**
* executeTimeOut * Execute timeout
*/ */
private Long executeTimeOut; private Long executeTimeOut;
/** /**
* allowCoreThreadTimeOut * Allow core thread timeout
*/ */
private Boolean allowCoreThreadTimeOut; private Boolean allowCoreThreadTimeOut;
/** /**
* threadNamePrefix * Thread name prefix
*/ */
private String threadNamePrefix; private String threadNamePrefix;

@ -21,32 +21,28 @@ import lombok.Data;
/** /**
* Notify platform properties. * Notify platform properties.
*
* @author chen.ma
* @date 2022/2/25 19:29
*/ */
@Data @Data
public class NotifyPlatformProperties { public class NotifyPlatformProperties {
/** /**
* Platform. * Platform
*/ */
private String platform; private String platform;
/** /**
* Secret key. * Secret key. {@link NotifyPlatformProperties#token}
* {@link NotifyPlatformProperties#token}
*/ */
@Deprecated @Deprecated
private String secretKey; private String secretKey;
/** /**
* Token. * Token
*/ */
private String token; private String token;
/** /**
* Secret. * Secret
*/ */
private String secret; private String secret;
} }

@ -21,9 +21,6 @@ import lombok.Data;
/** /**
* Web thread pool properties. * Web thread pool properties.
*
* @author chen.ma
* @date 2022/3/11 19:23
*/ */
@Data @Data
public class WebThreadPoolProperties { public class WebThreadPoolProperties {

@ -38,9 +38,6 @@ import java.util.concurrent.TimeUnit;
/** /**
* Dynamic thread-pool monitor executor. * Dynamic thread-pool monitor executor.
*
* @author chen.ma
* @date 2022/3/25 19:29
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@ -87,7 +84,7 @@ public class DynamicThreadPoolMonitorExecutor implements ApplicationRunner {
try { try {
each.collect(); each.collect();
} catch (Exception ex) { } catch (Exception ex) {
log.error("Error monitoring the running status of dynamic thread pool. Type :: {}", each.getType(), ex); log.error("Error monitoring the running status of dynamic thread pool. Type: {}", each.getType(), ex);
} }
} }
} }

@ -38,9 +38,6 @@ import java.util.stream.Collectors;
/** /**
* Core notify config builder. * Core notify config builder.
*
* @author chen.ma
* @date 2022/2/25 00:24
*/ */
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
@ -139,7 +136,6 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
receive = receives.get(platformProperties.getPlatform()); receive = receives.get(platformProperties.getPlatform());
} }
} }
return receive; return receive;
} }

@ -18,9 +18,7 @@
package cn.hippo4j.core.springboot.starter.parser; package cn.hippo4j.core.springboot.starter.parser;
/** /**
* @author : wh * Abstract config parser
* @date : 2022/3/1 07:50
* @description:
*/ */
public abstract class AbstractConfigParser implements ConfigParser { public abstract class AbstractConfigParser implements ConfigParser {

@ -20,40 +20,38 @@ package cn.hippo4j.core.springboot.starter.parser;
import lombok.Getter; import lombok.Getter;
/** /**
* @author : wh * Config file type enum
* @date : 2022/3/1 07:47
* @description:
*/ */
@Getter @Getter
public enum ConfigFileTypeEnum { public enum ConfigFileTypeEnum {
/** /**
* properties * PROPERTIES
*/ */
PROPERTIES("properties"), PROPERTIES("properties"),
/** /**
* xml * XML
*/ */
XML("xml"), XML("xml"),
/** /**
* json * JSON
*/ */
JSON("json"), JSON("json"),
/** /**
* yml * YML
*/ */
YML("yml"), YML("yml"),
/** /**
* yaml * YAML
*/ */
YAML("yaml"), YAML("yaml"),
/** /**
* txt * TXT
*/ */
TXT("txt"); TXT("txt");
@ -71,5 +69,4 @@ public enum ConfigFileTypeEnum {
} }
return PROPERTIES; return PROPERTIES;
} }
} }

@ -22,9 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author : wh * Config parser.
* @date : 2022/3/1 07:47
* @description:
*/ */
public interface ConfigParser { public interface ConfigParser {

@ -26,9 +26,7 @@ import java.util.Map;
import java.util.ServiceLoader; import java.util.ServiceLoader;
/** /**
* @author : wh * Config parser handler.
* @date : 2022/3/1 08:02
* @description:
*/ */
public class ConfigParserHandler { public class ConfigParserHandler {
@ -39,7 +37,6 @@ public class ConfigParserHandler {
for (ConfigParser configParser : loader) { for (ConfigParser configParser : loader) {
PARSERS.add(configParser); PARSERS.add(configParser);
} }
PARSERS.add(new PropertiesConfigParser()); PARSERS.add(new PropertiesConfigParser());
PARSERS.add(new YamlConfigParser()); PARSERS.add(new YamlConfigParser());
} }
@ -50,7 +47,6 @@ public class ConfigParserHandler {
return parser.doParse(content); return parser.doParse(content);
} }
} }
return Collections.emptyMap(); return Collections.emptyMap();
} }

@ -26,9 +26,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
* @author : wh * Properties config parser.
* @date : 2022/3/1 07:49
* @description:
*/ */
public class PropertiesConfigParser extends AbstractConfigParser { public class PropertiesConfigParser extends AbstractConfigParser {

@ -27,9 +27,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author : wh * Yaml config parser.
* @date : 2022/3/1 07:57
* @description:
*/ */
public class YamlConfigParser extends AbstractConfigParser { public class YamlConfigParser extends AbstractConfigParser {
@ -38,11 +36,9 @@ public class YamlConfigParser extends AbstractConfigParser {
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
return Maps.newHashMapWithExpectedSize(0); return Maps.newHashMapWithExpectedSize(0);
} }
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); yamlPropertiesFactoryBean.setResources(new ByteArrayResource(content.getBytes()));
bean.setResources(new ByteArrayResource(content.getBytes())); return yamlPropertiesFactoryBean.getObject();
return bean.getObject();
} }
@Override @Override

@ -34,9 +34,6 @@ import java.util.concurrent.ExecutorService;
/** /**
* Abstract core thread-pool dynamic refresh. * Abstract core thread-pool dynamic refresh.
*
* @author chen.ma
* @date 2022/2/26 12:42
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor

@ -32,9 +32,7 @@ import java.util.Map;
import static cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties.PREFIX; import static cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties.PREFIX;
/** /**
* @author : wh * Apollo refresher handler.
* @date : 2022/2/28 21:32
* @description:
*/ */
@Slf4j @Slf4j
public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh { public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
@ -62,6 +60,6 @@ public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh
dynamicRefresh(configFile.getContent(), newChangeValueMap); dynamicRefresh(configFile.getContent(), newChangeValueMap);
}; };
config.addChangeListener(configChangeListener); config.addChangeListener(configChangeListener);
log.info("dynamic-thread-pool refresher, add apollo listener success, namespace: {}", namespace); log.info("Dynamic thread pool refresher, add apollo listener success. namespace: {}", namespace);
} }
} }

@ -40,9 +40,6 @@ import static cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties.
/** /**
* Bootstrap core properties binder adapt. * Bootstrap core properties binder adapt.
*
* @author chen.ma
* @date 2022/3/9 19:04
*/ */
public class BootstrapCorePropertiesBinderAdapt { public class BootstrapCorePropertiesBinderAdapt {

@ -27,9 +27,6 @@ import java.util.concurrent.Executor;
/** /**
* Nacos cloud refresher handler. * Nacos cloud refresher handler.
*
* @author chen.ma
* @date 2022/2/26 11:21
*/ */
@Slf4j @Slf4j
public class NacosCloudRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh { public class NacosCloudRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
@ -56,5 +53,6 @@ public class NacosCloudRefresherHandler extends AbstractCoreThreadPoolDynamicRef
dynamicRefresh(configInfo); dynamicRefresh(configInfo);
} }
}); });
log.info("Dynamic thread pool refresher, add nacos cloud listener success. data-id: {}, group: {}", nacosConfig.get("data-id"), nacosConfig.get("group"));
} }
} }

@ -28,9 +28,6 @@ import java.util.concurrent.Executor;
/** /**
* Nacos refresher handler. * Nacos refresher handler.
*
* @author chen.ma
* @date 2022/2/26 00:10
*/ */
@Slf4j @Slf4j
public class NacosRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh { public class NacosRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
@ -59,5 +56,7 @@ public class NacosRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh
dynamicRefresh(configInfo); dynamicRefresh(configInfo);
} }
}); });
log.info("Dynamic thread pool refresher, add nacos listener success. data-id: {}, group: {}", nacosConfig.get("data-id"), nacosConfig.get("group"));
} }
} }

@ -36,8 +36,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author Redick01 * Zookeeper refresher handler.
* @date 2022/3/14 16:03
*/ */
@Slf4j @Slf4j
public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh { public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
@ -93,15 +92,15 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
String value = ""; String value = "";
try { try {
value = new String(data.watched().forPath(n), Charsets.UTF_8); value = new String(data.watched().forPath(n), Charsets.UTF_8);
} catch (Exception e) { } catch (Exception ex) {
e.printStackTrace(); log.error("Load zookeeper node error", ex);
} }
content.append(nodeName).append("=").append(value).append("\n"); content.append(nodeName).append("=").append(value).append("\n");
}); });
dynamicRefresh(content.toString()); dynamicRefresh(content.toString());
registerNotifyAlarmManage(); registerNotifyAlarmManage();
} catch (Exception e) { } catch (Exception ex) {
log.error("load zk node error, nodePath is {}", nodePath, e); log.error("Load zookeeper node error, nodePath is: {}", nodePath, ex);
} }
} }

@ -98,37 +98,38 @@ public class ExecutorsListener implements ApplicationListener<Hippo4jCoreDynamic
try { try {
threadPoolNotifyAlarmHandler.sendPoolConfigChange(newChangeRequest(beforeProperties, properties)); threadPoolNotifyAlarmHandler.sendPoolConfigChange(newChangeRequest(beforeProperties, properties));
} catch (Throwable ex) { } catch (Throwable ex) {
log.error("Failed to send changSmartApplicationListenere notice. Message :: {}", ex.getMessage()); log.error("Failed to send Chang smart application listener notice. Message: {}", ex.getMessage());
} }
} }
} }
/** /**
* Construct ChangeParameterNotifyRequest instance * Construct change parameter notify request instance.
* *
* @param beforeProperties old properties * @param beforeProperties old properties
* @param properties new properties * @param properties new properties
* @return instance * @return instance
*/ */
private ChangeParameterNotifyRequest newChangeRequest(ExecutorProperties beforeProperties, ExecutorProperties properties) { private ChangeParameterNotifyRequest newChangeRequest(ExecutorProperties beforeProperties, ExecutorProperties properties) {
ChangeParameterNotifyRequest changeRequest = new ChangeParameterNotifyRequest(); ChangeParameterNotifyRequest changeParameterNotifyRequest = ChangeParameterNotifyRequest.builder()
changeRequest.setBeforeCorePoolSize(beforeProperties.getCorePoolSize()); .beforeCorePoolSize(beforeProperties.getCorePoolSize())
changeRequest.setBeforeMaximumPoolSize(beforeProperties.getMaximumPoolSize()); .beforeMaximumPoolSize(beforeProperties.getMaximumPoolSize())
changeRequest.setBeforeAllowsCoreThreadTimeOut(beforeProperties.getAllowCoreThreadTimeOut()); .beforeAllowsCoreThreadTimeOut(beforeProperties.getAllowCoreThreadTimeOut())
changeRequest.setBeforeKeepAliveTime(beforeProperties.getKeepAliveTime()); .beforeKeepAliveTime(beforeProperties.getKeepAliveTime())
changeRequest.setBlockingQueueName(beforeProperties.getBlockingQueue()); .blockingQueueName(beforeProperties.getBlockingQueue())
changeRequest.setBeforeQueueCapacity(beforeProperties.getQueueCapacity()); .beforeQueueCapacity(beforeProperties.getQueueCapacity())
changeRequest.setBeforeRejectedName(beforeProperties.getRejectedHandler()); .beforeRejectedName(beforeProperties.getRejectedHandler())
changeRequest.setBeforeExecuteTimeOut(beforeProperties.getExecuteTimeOut()); .beforeExecuteTimeOut(beforeProperties.getExecuteTimeOut())
changeRequest.setThreadPoolId(beforeProperties.getThreadPoolId()); .nowCorePoolSize(properties.getCorePoolSize())
changeRequest.setNowCorePoolSize(properties.getCorePoolSize()); .nowMaximumPoolSize(properties.getMaximumPoolSize())
changeRequest.setNowMaximumPoolSize(properties.getMaximumPoolSize()); .nowAllowsCoreThreadTimeOut(properties.getAllowCoreThreadTimeOut())
changeRequest.setNowAllowsCoreThreadTimeOut(properties.getAllowCoreThreadTimeOut()); .nowKeepAliveTime(properties.getKeepAliveTime())
changeRequest.setNowKeepAliveTime(properties.getKeepAliveTime()); .nowQueueCapacity(properties.getQueueCapacity())
changeRequest.setNowQueueCapacity(properties.getQueueCapacity()); .nowRejectedName(properties.getRejectedHandler())
changeRequest.setNowRejectedName(properties.getRejectedHandler()); .nowExecuteTimeOut(properties.getExecuteTimeOut())
changeRequest.setNowExecuteTimeOut(properties.getExecuteTimeOut()); .build();
return changeRequest; changeParameterNotifyRequest.setThreadPoolId(beforeProperties.getThreadPoolId());
return changeParameterNotifyRequest;
} }
/** /**
@ -257,7 +258,7 @@ public class ExecutorsListener implements ApplicationListener<Hippo4jCoreDynamic
ResizableCapacityLinkedBlockingQueue<?> queue = (ResizableCapacityLinkedBlockingQueue<?>) executor.getQueue(); ResizableCapacityLinkedBlockingQueue<?> queue = (ResizableCapacityLinkedBlockingQueue<?>) executor.getQueue();
queue.setCapacity(properties.getQueueCapacity()); queue.setCapacity(properties.getQueueCapacity());
} else { } else {
log.warn("The queue length cannot be modified. Queue type mismatch. Current queue type :: {}", executor.getQueue().getClass().getSimpleName()); log.warn("The queue length cannot be modified. Queue type mismatch. Current queue type: {}", executor.getQueue().getClass().getSimpleName());
} }
} }
} }

@ -23,7 +23,7 @@ import lombok.Setter;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
/** /**
* Hippo4j core dynamic refresh event. * Hippo-4j core dynamic refresh event.
*/ */
public class Hippo4jCoreDynamicRefreshEvent extends ApplicationEvent { public class Hippo4jCoreDynamicRefreshEvent extends ApplicationEvent {

@ -18,7 +18,7 @@
package cn.hippo4j.core.springboot.starter.refresher.event; package cn.hippo4j.core.springboot.starter.refresher.event;
/** /**
* Hippo4j core dynamic refresh event order. * Hippo-4j core dynamic refresh event order.
*/ */
public interface Hippo4jCoreDynamicRefreshEventOrder { public interface Hippo4jCoreDynamicRefreshEventOrder {

@ -43,13 +43,13 @@ public class PlatformsListener implements ApplicationListener<Hippo4jCoreDynamic
public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties(); BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties();
List<ExecutorProperties> executors = bindableCoreProperties.getExecutors(); List<ExecutorProperties> executors = bindableCoreProperties.getExecutors();
for (ExecutorProperties executor : executors) { for (ExecutorProperties executorProperties : executors) {
String threadPoolId = executor.getThreadPoolId(); String threadPoolId = executorProperties.getThreadPoolId();
DynamicThreadPoolWrapper wrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId); DynamicThreadPoolWrapper wrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId);
if (wrapper != null && !wrapper.isInitFlag()) { if (wrapper != null && !wrapper.isInitFlag()) {
Hippo4jBaseSendMessageService sendMessageService = ApplicationContextHolder.getBean(Hippo4jBaseSendMessageService.class); Hippo4jBaseSendMessageService sendMessageService = ApplicationContextHolder.getBean(Hippo4jBaseSendMessageService.class);
CoreNotifyConfigBuilder configBuilder = ApplicationContextHolder.getBean(CoreNotifyConfigBuilder.class); CoreNotifyConfigBuilder configBuilder = ApplicationContextHolder.getBean(CoreNotifyConfigBuilder.class);
Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(executor); Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(executorProperties);
sendMessageService.putPlatform(notifyConfig); sendMessageService.putPlatform(notifyConfig);
wrapper.setInitFlag(Boolean.TRUE); wrapper.setInitFlag(Boolean.TRUE);
} }

@ -63,25 +63,25 @@ public class WebExecutorListener implements ApplicationListener<Hippo4jCoreDynam
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to modify web thread pool.", ex); log.error("Failed to modify web thread pool.", ex);
} }
} }
private ThreadPoolParameterInfo buildWebPoolParameter(BootstrapCoreProperties bindableCoreProperties) { private ThreadPoolParameterInfo buildWebPoolParameter(BootstrapCoreProperties bindableCoreProperties) {
ThreadPoolParameterInfo parameterInfo = null; ThreadPoolParameterInfo threadPoolParameterInfo = null;
WebThreadPoolProperties poolProperties = null; WebThreadPoolProperties webThreadPoolProperties = null;
if (bindableCoreProperties.getTomcat() != null) { if (bindableCoreProperties.getTomcat() != null) {
poolProperties = bindableCoreProperties.getTomcat(); webThreadPoolProperties = bindableCoreProperties.getTomcat();
} else if (bindableCoreProperties.getUndertow() != null) { } else if (bindableCoreProperties.getUndertow() != null) {
poolProperties = bindableCoreProperties.getUndertow(); webThreadPoolProperties = bindableCoreProperties.getUndertow();
} else if (bindableCoreProperties.getJetty() != null) { } else if (bindableCoreProperties.getJetty() != null) {
poolProperties = bindableCoreProperties.getJetty(); webThreadPoolProperties = bindableCoreProperties.getJetty();
} }
if (poolProperties != null) { if (webThreadPoolProperties != null) {
parameterInfo = new ThreadPoolParameterInfo(); threadPoolParameterInfo = ThreadPoolParameterInfo.builder()
parameterInfo.setCoreSize(poolProperties.getCorePoolSize()); .coreSize(webThreadPoolProperties.getCorePoolSize())
parameterInfo.setMaxSize(poolProperties.getMaximumPoolSize()); .maximumPoolSize(webThreadPoolProperties.getMaximumPoolSize())
parameterInfo.setKeepAliveTime(poolProperties.getKeepAliveTime()); .keepAliveTime(webThreadPoolProperties.getKeepAliveTime())
.build();
} }
return parameterInfo; return threadPoolParameterInfo;
} }
} }

@ -43,9 +43,6 @@ import java.util.concurrent.TimeUnit;
/** /**
* Dynamic thread-pool post processor. * Dynamic thread-pool post processor.
*
* @author chen.ma
* @date 2021/8/2 20:40
*/ */
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
@ -99,11 +96,11 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
/** /**
* Fill the thread pool and register. * Fill the thread pool and register.
* *
* @param dynamicThreadPoolWrap * @param dynamicThreadPoolWrapper
*/ */
protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrap) { protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrapper) {
String threadPoolId = dynamicThreadPoolWrap.getThreadPoolId(); String threadPoolId = dynamicThreadPoolWrapper.getThreadPoolId();
ThreadPoolExecutor newDynamicPoolExecutor = dynamicThreadPoolWrap.getExecutor(); ThreadPoolExecutor newDynamicPoolExecutor = dynamicThreadPoolWrapper.getExecutor();
ExecutorProperties executorProperties = null; ExecutorProperties executorProperties = null;
if (null != bootstrapCoreProperties.getExecutors()) { if (null != bootstrapCoreProperties.getExecutors()) {
executorProperties = bootstrapCoreProperties.getExecutors() executorProperties = bootstrapCoreProperties.getExecutors()
@ -126,16 +123,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
.allowCoreThreadTimeOut(executorProperties.getAllowCoreThreadTimeOut()) .allowCoreThreadTimeOut(executorProperties.getAllowCoreThreadTimeOut())
.build(); .build();
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to initialize thread pool configuration. error :: {}", ex); log.error("Failed to initialize thread pool configuration. error: {}", ex);
} finally { } finally {
if (Objects.isNull(dynamicThreadPoolWrap.getExecutor())) { if (Objects.isNull(dynamicThreadPoolWrapper.getExecutor())) {
dynamicThreadPoolWrap.setExecutor(CommonDynamicThreadPool.getInstance(threadPoolId)); dynamicThreadPoolWrapper.setExecutor(CommonDynamicThreadPool.getInstance(threadPoolId));
} }
dynamicThreadPoolWrap.setInitFlag(Boolean.TRUE); dynamicThreadPoolWrapper.setInitFlag(Boolean.TRUE);
} }
} }
if (dynamicThreadPoolWrapper.getExecutor() instanceof AbstractDynamicExecutorSupport) {
if (dynamicThreadPoolWrap.getExecutor() instanceof AbstractDynamicExecutorSupport) {
ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
boolean isAlarm = Optional.ofNullable(notify) boolean isAlarm = Optional.ofNullable(notify)
.map(each -> each.getIsAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); .map(each -> each.getIsAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true);
@ -151,18 +147,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
threadPoolNotifyAlarm.setInterval(interval); threadPoolNotifyAlarm.setInterval(interval);
threadPoolNotifyAlarm.setReceive(receive); threadPoolNotifyAlarm.setReceive(receive);
GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm);
TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).getTaskDecorator();
TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).getTaskDecorator();
((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setTaskDecorator(taskDecorator); ((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setTaskDecorator(taskDecorator);
long awaitTerminationMillis = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).awaitTerminationMillis;
long awaitTerminationMillis = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).awaitTerminationMillis; boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).waitForTasksToCompleteOnShutdown;
boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).waitForTasksToCompleteOnShutdown;
((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown); ((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown);
} }
dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor); dynamicThreadPoolWrapper.setExecutor(newDynamicPoolExecutor);
} }
GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrapper.getThreadPoolId(), dynamicThreadPoolWrapper);
GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrap.getThreadPoolId(), dynamicThreadPoolWrap);
GlobalCoreThreadPoolManage.register( GlobalCoreThreadPoolManage.register(
threadPoolId, threadPoolId,
executorProperties == null executorProperties == null
@ -180,10 +173,10 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
*/ */
private ExecutorProperties buildExecutorProperties(String threadPoolId, ThreadPoolExecutor executor) { private ExecutorProperties buildExecutorProperties(String threadPoolId, ThreadPoolExecutor executor) {
ExecutorProperties executorProperties = new ExecutorProperties(); ExecutorProperties executorProperties = new ExecutorProperties();
BlockingQueue<Runnable> queue = executor.getQueue(); BlockingQueue<Runnable> blockingQueue = executor.getQueue();
int queueSize = queue.size(); int queueSize = blockingQueue.size();
String queueType = queue.getClass().getSimpleName(); String queueType = blockingQueue.getClass().getSimpleName();
int remainingCapacity = queue.remainingCapacity(); int remainingCapacity = blockingQueue.remainingCapacity();
int queueCapacity = queueSize + remainingCapacity; int queueCapacity = queueSize + remainingCapacity;
executorProperties.setCorePoolSize(executor.getCorePoolSize()) executorProperties.setCorePoolSize(executor.getCorePoolSize())
.setMaximumPoolSize(executor.getMaximumPoolSize()) .setMaximumPoolSize(executor.getMaximumPoolSize())

@ -24,9 +24,6 @@ import java.util.Map;
/** /**
* Global core thread-pool manage. * Global core thread-pool manage.
*
* @author chen.ma
* @date 2022/2/26 19:47
*/ */
public class GlobalCoreThreadPoolManage { public class GlobalCoreThreadPoolManage {

Loading…
Cancel
Save