适配 SpringBoot 多容器线程池监控. (#68)

pull/84/head
chen.ma 3 years ago
parent 417b3ba156
commit 13498d43cb

@ -14,8 +14,8 @@ import cn.hippo4j.starter.handler.BaseThreadDetailStateHandler;
import cn.hippo4j.starter.handler.DynamicThreadPoolBannerHandler;
import cn.hippo4j.starter.handler.ThreadPoolRunStateHandler;
import cn.hippo4j.starter.handler.web.TomcatWebThreadPoolHandler;
import cn.hippo4j.starter.handler.web.WebThreadPoolHandlerChoose;
import cn.hippo4j.starter.handler.web.WebThreadPoolRunStateHandler;
import cn.hippo4j.starter.handler.web.WebThreadPoolService;
import cn.hippo4j.starter.monitor.ReportingEventExecutor;
import cn.hippo4j.starter.monitor.collect.RunTimeInfoCollector;
import cn.hippo4j.starter.monitor.send.HttpConnectSender;
@ -143,15 +143,21 @@ public class DynamicThreadPoolAutoConfiguration {
}
@Bean
@ConditionalOnBean(name = "tomcatServletWebServerFactory")
public TomcatWebThreadPoolHandler tomcatWebThreadPoolHandler() {
return new TomcatWebThreadPoolHandler(applicationContext);
}
@Bean
public WebThreadPoolController webThreadPoolController(WebThreadPoolService webThreadPoolService,
public WebThreadPoolHandlerChoose webThreadPoolServiceChoose() {
return new WebThreadPoolHandlerChoose();
}
@Bean
public WebThreadPoolController webThreadPoolController(WebThreadPoolHandlerChoose webThreadPoolServiceChoose,
ThreadDetailState threadDetailState,
WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) {
return new WebThreadPoolController(webThreadPoolService, threadDetailState, webThreadPoolRunStateHandler);
return new WebThreadPoolController(webThreadPoolServiceChoose, threadDetailState, webThreadPoolRunStateHandler);
}
}

@ -5,6 +5,7 @@ import cn.hippo4j.common.model.PoolParameterInfo;
import cn.hippo4j.common.model.PoolRunStateInfo;
import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.starter.handler.web.WebThreadPoolHandlerChoose;
import cn.hippo4j.starter.handler.web.WebThreadPoolRunStateHandler;
import cn.hippo4j.starter.handler.web.WebThreadPoolService;
import lombok.AllArgsConstructor;
@ -23,7 +24,7 @@ import java.util.concurrent.Executor;
@AllArgsConstructor
public class WebThreadPoolController {
private final WebThreadPoolService webThreadPoolService;
private final WebThreadPoolHandlerChoose webThreadPoolServiceChoose;
private final ThreadDetailState threadDetailState;
@ -31,6 +32,7 @@ public class WebThreadPoolController {
@GetMapping("/web/run/state")
public Result<PoolRunStateInfo> getPoolRunState() {
WebThreadPoolService webThreadPoolService = webThreadPoolServiceChoose.choose();
Executor webThreadPool = webThreadPoolService.getWebThreadPool();
PoolRunStateInfo poolRunState = webThreadPoolRunStateHandler.getPoolRunState(null, webThreadPool);
return Results.success(poolRunState);
@ -38,6 +40,7 @@ public class WebThreadPoolController {
@PostMapping("/web/update/pool")
public Result<Void> updateWebThreadPool(@RequestBody PoolParameterInfo poolParameterInfo) {
WebThreadPoolService webThreadPoolService = webThreadPoolServiceChoose.choose();
webThreadPoolService.updateWebThreadPool(poolParameterInfo);
return Results.success();
}

@ -0,0 +1,32 @@
package cn.hippo4j.starter.handler.web;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.web.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
/**
* Web thread pool handler choose.
*
* @author chen.ma
* @date 2022/1/20 20:15
*/
@Slf4j
public class WebThreadPoolHandlerChoose {
/**
* Choose the web thread pool service bean.
*
* @return
*/
public WebThreadPoolService choose() {
WebThreadPoolService webThreadPoolService;
try {
webThreadPoolService = ApplicationContextHolder.getBean(WebThreadPoolService.class);
} catch (Exception ex) {
throw new ServiceException("Web thread pool service bean not found.", ex);
}
return webThreadPoolService;
}
}
Loading…
Cancel
Save