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

pull/327/head
chen.ma 2 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.config.ApplicationContextHolder;
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.inet.InetUtils;
import cn.hippo4j.starter.controller.PoolRunStateController;
@ -87,7 +87,7 @@ public class DynamicThreadPoolAutoConfiguration {
public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent,
ThreadPoolOperation threadPoolOperation,
ApplicationContextHolder hippo4JApplicationContextHolder,
ThreadPoolDynamicRefresh threadPoolDynamicRefresh) {
ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh) {
return new DynamicThreadPoolPostProcessor(properties, httpAgent, threadPoolOperation, threadPoolDynamicRefresh);
}

@ -1,11 +1,12 @@
package cn.hippo4j.starter.config;
import cn.hippo4j.common.api.NotifyConfigBuilder;
import cn.hippo4j.common.notify.*;
import cn.hippo4j.common.notify.platform.DingSendMessageHandler;
import cn.hippo4j.common.notify.platform.LarkSendMessageHandler;
import cn.hippo4j.common.notify.platform.WeChatSendMessageHandler;
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.remote.HttpAgent;
import lombok.AllArgsConstructor;
@ -59,8 +60,8 @@ public class MessageNotifyConfiguration {
}
@Bean
public ThreadPoolDynamicRefresh threadPoolDynamicRefresh(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) {
return new ThreadPoolDynamicRefresh(threadPoolNotifyAlarmHandler);
public ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh(ThreadPoolNotifyAlarmHandler 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.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.*;
import cn.hippo4j.core.refresh.ThreadPoolDynamicRefresh;
import cn.hippo4j.starter.config.BootstrapProperties;
import cn.hippo4j.starter.remote.HttpAgent;
import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil;
@ -50,7 +49,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
private final ThreadPoolOperation threadPoolOperation;
private final ThreadPoolDynamicRefresh threadPoolDynamicRefresh;
private final ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh;
private final ExecutorService executorService = ThreadPoolBuilder.builder()
.corePoolSize(2)
@ -193,7 +192,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
*/
protected void subscribeConfig(DynamicThreadPoolWrapper dynamicThreadPoolWrap) {
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.model.PoolParameter;
import cn.hippo4j.common.model.PoolParameterInfo;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
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.ResizableCapacityLinkedBlockIngQueue;
import cn.hippo4j.core.proxy.RejectedProxyUtil;
import cn.hippo4j.common.api.ThreadPoolDynamicRefresh;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -22,23 +24,19 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* ThreadPool dynamic refresh.
* Thread pool dynamic refresh.
*
* @author chen.ma
* @date 2021/6/20 15:51
*/
@Slf4j
@AllArgsConstructor
public class ThreadPoolDynamicRefresh {
public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
/**
* Refresh dynamic pool.
*
* @param content
*/
public void refreshDynamicPool(String content) {
@Override
public void dynamicRefresh(String content) {
PoolParameterInfo parameter = JSONUtil.parseObject(content, PoolParameterInfo.class);
String threadPoolId = parameter.getTpId();
@ -53,7 +51,7 @@ public class ThreadPoolDynamicRefresh {
* @param parameter
* @param executor
*/
public void refreshDynamicPool(PoolParameterInfo parameter, ThreadPoolExecutor executor) {
public void refreshDynamicPool(PoolParameter parameter, ThreadPoolExecutor executor) {
String threadPoolId = parameter.getTpId();
int originalCoreSize = executor.getCorePoolSize();
int originalMaximumPoolSize = executor.getMaximumPoolSize();
@ -119,7 +117,7 @@ public class ThreadPoolDynamicRefresh {
* @param executor
* @param parameter
*/
public void changePoolInfo(ThreadPoolExecutor executor, PoolParameterInfo parameter) {
public void changePoolInfo(ThreadPoolExecutor executor, PoolParameter parameter) {
if (parameter.getCoreSize() != null) {
executor.setCorePoolSize(parameter.getCoreSize());
}
Loading…
Cancel
Save