重构 hippo4j-starter 动态刷新功能.

pull/327/head
chen.ma 3 years ago
parent f5010e5ff8
commit 9fdf96841f

@ -3,7 +3,7 @@ package cn.hippo4j.starter.config;
import cn.hippo4j.common.api.ThreadDetailState; import cn.hippo4j.common.api.ThreadDetailState;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.core.config.UtilAutoConfiguration; import cn.hippo4j.core.config.UtilAutoConfiguration;
import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh; import cn.hippo4j.starter.core.ServerThreadPoolDynamicRefresh;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.core.toolkit.IdentifyUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hippo4j.starter.controller.PoolRunStateController; import cn.hippo4j.starter.controller.PoolRunStateController;
@ -87,7 +87,7 @@ public class DynamicThreadPoolAutoConfiguration {
public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent, public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent,
ThreadPoolOperation threadPoolOperation, ThreadPoolOperation threadPoolOperation,
ApplicationContextHolder hippo4JApplicationContextHolder, ApplicationContextHolder hippo4JApplicationContextHolder,
ThreadPoolDynamicRefresh threadPoolDynamicRefresh) { ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh) {
return new DynamicThreadPoolPostProcessor(properties, httpAgent, threadPoolOperation, threadPoolDynamicRefresh); return new DynamicThreadPoolPostProcessor(properties, httpAgent, threadPoolOperation, threadPoolDynamicRefresh);
} }

@ -1,11 +1,12 @@
package cn.hippo4j.starter.config; package cn.hippo4j.starter.config;
import cn.hippo4j.common.api.NotifyConfigBuilder;
import cn.hippo4j.common.notify.*; import cn.hippo4j.common.notify.*;
import cn.hippo4j.common.notify.platform.DingSendMessageHandler; import cn.hippo4j.common.notify.platform.DingSendMessageHandler;
import cn.hippo4j.common.notify.platform.LarkSendMessageHandler; import cn.hippo4j.common.notify.platform.LarkSendMessageHandler;
import cn.hippo4j.common.notify.platform.WeChatSendMessageHandler; import cn.hippo4j.common.notify.platform.WeChatSendMessageHandler;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler; import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh; import cn.hippo4j.starter.core.ServerThreadPoolDynamicRefresh;
import cn.hippo4j.starter.notify.ServerNotifyConfigBuilder; import cn.hippo4j.starter.notify.ServerNotifyConfigBuilder;
import cn.hippo4j.starter.remote.HttpAgent; import cn.hippo4j.starter.remote.HttpAgent;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -59,8 +60,8 @@ public class MessageNotifyConfiguration {
} }
@Bean @Bean
public ThreadPoolDynamicRefresh threadPoolDynamicRefresh(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) { public ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) {
return new ThreadPoolDynamicRefresh(threadPoolNotifyAlarmHandler); return new ServerThreadPoolDynamicRefresh(threadPoolNotifyAlarmHandler);
} }
} }

@ -13,7 +13,6 @@ import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.*; import cn.hippo4j.core.executor.support.*;
import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh;
import cn.hippo4j.starter.config.BootstrapProperties; import cn.hippo4j.starter.config.BootstrapProperties;
import cn.hippo4j.starter.remote.HttpAgent; import cn.hippo4j.starter.remote.HttpAgent;
import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil;
@ -50,7 +49,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
private final ThreadPoolOperation threadPoolOperation; private final ThreadPoolOperation threadPoolOperation;
private final ThreadPoolDynamicRefresh threadPoolDynamicRefresh; private final ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh;
private final ExecutorService executorService = ThreadPoolBuilder.builder() private final ExecutorService executorService = ThreadPoolBuilder.builder()
.corePoolSize(2) .corePoolSize(2)
@ -193,7 +192,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
*/ */
protected void subscribeConfig(DynamicThreadPoolWrapper dynamicThreadPoolWrap) { protected void subscribeConfig(DynamicThreadPoolWrapper dynamicThreadPoolWrap) {
if (dynamicThreadPoolWrap.isSubscribeFlag()) { if (dynamicThreadPoolWrap.isSubscribeFlag()) {
threadPoolOperation.subscribeConfig(dynamicThreadPoolWrap.getTpId(), executorService, config -> threadPoolDynamicRefresh.refreshDynamicPool(config)); threadPoolOperation.subscribeConfig(dynamicThreadPoolWrap.getTpId(), executorService, config -> threadPoolDynamicRefresh.dynamicRefresh(config));
} }
} }

@ -1,6 +1,7 @@
package cn.hippo4j.core.refresh; package cn.hippo4j.starter.core;
import cn.hippo4j.common.enums.EnableEnum; import cn.hippo4j.common.enums.EnableEnum;
import cn.hippo4j.common.model.PoolParameter;
import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.common.model.PoolParameterInfo;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest; import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
@ -12,6 +13,7 @@ import cn.hippo4j.core.executor.support.QueueTypeEnum;
import cn.hippo4j.core.executor.support.RejectedTypeEnum; import cn.hippo4j.core.executor.support.RejectedTypeEnum;
import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue; import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue;
import cn.hippo4j.core.proxy.RejectedProxyUtil; import cn.hippo4j.core.proxy.RejectedProxyUtil;
import cn.hippo4j.common.api.ThreadPoolDynamicRefresh;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,23 +24,19 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
/** /**
* ThreadPool dynamic refresh. * Thread pool dynamic refresh.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 15:51 * @date 2021/6/20 15:51
*/ */
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class ThreadPoolDynamicRefresh { public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler; private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
/** @Override
* Refresh dynamic pool. public void dynamicRefresh(String content) {
*
* @param content
*/
public void refreshDynamicPool(String content) {
PoolParameterInfo parameter = JSONUtil.parseObject(content, PoolParameterInfo.class); PoolParameterInfo parameter = JSONUtil.parseObject(content, PoolParameterInfo.class);
String threadPoolId = parameter.getTpId(); String threadPoolId = parameter.getTpId();
@ -53,7 +51,7 @@ public class ThreadPoolDynamicRefresh {
* @param parameter * @param parameter
* @param executor * @param executor
*/ */
public void refreshDynamicPool(PoolParameterInfo parameter, ThreadPoolExecutor executor) { public void refreshDynamicPool(PoolParameter parameter, ThreadPoolExecutor executor) {
String threadPoolId = parameter.getTpId(); String threadPoolId = parameter.getTpId();
int originalCoreSize = executor.getCorePoolSize(); int originalCoreSize = executor.getCorePoolSize();
int originalMaximumPoolSize = executor.getMaximumPoolSize(); int originalMaximumPoolSize = executor.getMaximumPoolSize();
@ -119,7 +117,7 @@ public class ThreadPoolDynamicRefresh {
* @param executor * @param executor
* @param parameter * @param parameter
*/ */
public void changePoolInfo(ThreadPoolExecutor executor, PoolParameterInfo parameter) { public void changePoolInfo(ThreadPoolExecutor executor, PoolParameter parameter) {
if (parameter.getCoreSize() != null) { if (parameter.getCoreSize() != null) {
executor.setCorePoolSize(parameter.getCoreSize()); executor.setCorePoolSize(parameter.getCoreSize());
} }
Loading…
Cancel
Save