Merge pull request #150 from xqxyxchy/develop

【优化】调整client端请求方式
pull/153/head
龙台 Long Tai 3 years ago committed by GitHub
commit a4693978ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,11 @@
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
<build>

@ -2,9 +2,15 @@ package cn.hippo4j.console.controller;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.model.InstanceInfo;
import cn.hippo4j.common.model.PoolBaseInfo;
import cn.hippo4j.common.model.PoolParameterInfo;
import cn.hippo4j.common.model.PoolRunStateInfo;
import cn.hippo4j.common.model.ThreadDetailStateInfo;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.common.web.executor.WebThreadPoolService;
import cn.hippo4j.config.model.CacheItem;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolDelReqDTO;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO;
@ -17,7 +23,10 @@ import cn.hippo4j.console.model.ThreadPoolInstanceInfo;
import cn.hippo4j.discovery.core.BaseInstanceRegistry;
import cn.hippo4j.discovery.core.Lease;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
@ -26,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import static cn.hippo4j.common.toolkit.ContentUtil.getGroupKey;
@ -57,7 +67,7 @@ public class ThreadPoolController {
@PostMapping("/save_or_update")
public Result saveOrUpdateThreadPoolConfig(@RequestParam(value = "identify", required = false) String identify,
@Validated @RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) {
@Validated @RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) {
threadPoolService.saveOrUpdateThreadPoolConfig(identify, reqDTO);
return Results.success();
}
@ -74,8 +84,52 @@ public class ThreadPoolController {
return Results.success();
}
@GetMapping("/run/state/{tpId}")
public Result runState(@PathVariable("tpId") String tpId,
@RequestParam(value = "clientAddress", required = true) String clientAddress) {
String urlString = StrBuilder.create("http://", clientAddress, "/run/state/", tpId).toString();
String data = HttpUtil.get(urlString);
Result result = JSONUtil.parseObject(data, Result.class);
return result;
}
@GetMapping("/run/thread/state/{tpId}")
public Result runThreadState(@PathVariable("tpId") String tpId,
@RequestParam(value = "clientAddress", required = true) String clientAddress) {
String urlString = StrBuilder.create("http://", clientAddress, "/run/thread/state/", tpId).toString();
String data = HttpUtil.get(urlString);
Result result = JSONUtil.parseObject(data, Result.class);
return result;
}
@GetMapping("/web/base/info")
public Result getPoolBaseState(@RequestParam(value = "clientAddress", required = true) String clientAddress) {
String urlString = StrBuilder.create("http://", clientAddress, "/web/base/info").toString();
String data = HttpUtil.get(urlString);
Result result = JSONUtil.parseObject(data, Result.class);
return result;
}
@GetMapping("/web/run/state")
public Result getPoolRunState(@RequestParam(value = "clientAddress", required = true) String clientAddress) {
String urlString = StrBuilder.create("http://", clientAddress, "/web/run/state").toString();
String data = HttpUtil.get(urlString);
Result result = JSONUtil.parseObject(data, Result.class);
return result;
}
@PostMapping("/web/update/pool")
public Result<Void> updateWebThreadPool(@RequestParam(value = "clientAddress", required = true) String clientAddress,
@RequestBody PoolParameterInfo poolParameterInfo) {
String urlString = StrBuilder.create("http://", clientAddress, "/web/update/pool").toString();
String data = HttpUtil.post(urlString, JSONUtil.toJSONString(poolParameterInfo));
Result result = JSONUtil.parseObject(data, Result.class);
return result;
}
@GetMapping("/list/instance/{itemId}/{tpId}")
public Result<List<ThreadPoolInstanceInfo>> listInstance(@PathVariable("itemId") String itemId, @PathVariable("tpId") String tpId) {
public Result<List<ThreadPoolInstanceInfo>> listInstance(@PathVariable("itemId") String itemId,
@PathVariable("tpId") String tpId) {
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
Lease<InstanceInfo> first = CollUtil.getFirst(leases);
if (first == null) {
@ -86,19 +140,18 @@ public class ThreadPoolController {
String itemTenantKey = holder.getGroupKey();
String groupKey = getGroupKey(tpId, itemTenantKey);
Map<String, CacheItem> content = ConfigCacheService.getContent(groupKey);
Map<String, String> activeMap = leases.stream()
.map(each -> each.getHolder())
.filter(each -> StringUtil.isNotBlank(each.getActive()))
Map<String, String> activeMap =
leases.stream().map(each -> each.getHolder()).filter(each -> StringUtil.isNotBlank(each.getActive()))
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getActive));
Map<String, String> clientBasePathMap = leases.stream()
.map(each -> each.getHolder())
Map<String, String> clientBasePathMap = leases.stream().map(each -> each.getHolder())
.filter(each -> StringUtil.isNotBlank(each.getClientBasePath()))
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getClientBasePath));
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
content.forEach((key, val) -> {
ThreadPoolInstanceInfo threadPoolInstanceInfo = BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
ThreadPoolInstanceInfo threadPoolInstanceInfo =
BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
threadPoolInstanceInfo.setClientAddress(StrUtil.subBefore(key, Constants.IDENTIFY_SLICER_SYMBOL, false));
threadPoolInstanceInfo.setActive(activeMap.get(key));
threadPoolInstanceInfo.setIdentify(key);

@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=renderer content=webkit><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=/favicon.ico><title>Hippo4J Web</title><link href=/static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=/static/css/app.ed1e0bc9.css rel=stylesheet></head><body><div id=app></div><script src=/static/js/chunk-elementUI.bc99dd6f.js></script><script src=/static/js/chunk-libs.75ab222e.js></script><script>(function(e){function n(n){for(var t,r,o=n[0],d=n[1],f=n[2],h=0,i=[];h<o.length;h++)r=o[h],u[r]&&i.push(u[r][0]),u[r]=0;for(t in d)Object.prototype.hasOwnProperty.call(d,t)&&(e[t]=d[t]);l&&l(n);while(i.length)i.shift()();return a.push.apply(a,f||[]),c()}function c(){for(var e,n=0;n<a.length;n++){for(var c=a[n],t=!0,r=1;r<c.length;r++){var o=c[r];0!==u[o]&&(t=!1)}t&&(a.splice(n--,1),e=d(d.s=c[0]))}return e}var t={},r={runtime:0},u={runtime:0},a=[];function o(e){return d.p+"static/js/"+({}[e]||e)+"."+{"chunk-04a4268a":"c9a819e9","chunk-0d3c079f":"a15f890a","chunk-1504cdfc":"10f6cf66","chunk-16eb7b18":"f972e32c","chunk-2d230fe7":"19def69d","chunk-3714bce8":"3efea7f0","chunk-380263e8":"4584cf97","chunk-45e73af7":"dd61708c","chunk-4934959c":"cb4ed23b","chunk-4b345e33":"779d562d","chunk-648295c6":"b36e1548","chunk-6f742c38":"47b5bb28","chunk-7b878d9e":"2665486c","chunk-91584750":"81deb5be","chunk-a6de055c":"0aed52f9","chunk-bc53b446":"6993c4c9","chunk-434632c4":"32bd5259","chunk-e25b23da":"cd797eb1"}[e]+".js"}function d(n){if(t[n])return t[n].exports;var c=t[n]={i:n,l:!1,exports:{}};return e[n].call(c.exports,c,c.exports,d),c.l=!0,c.exports}d.e=function(e){var n=[],c={"chunk-0d3c079f":1,"chunk-1504cdfc":1,"chunk-16eb7b18":1,"chunk-3714bce8":1,"chunk-380263e8":1,"chunk-45e73af7":1,"chunk-4934959c":1,"chunk-4b345e33":1,"chunk-648295c6":1,"chunk-6f742c38":1,"chunk-7b878d9e":1,"chunk-91584750":1,"chunk-a6de055c":1,"chunk-bc53b446":1,"chunk-434632c4":1,"chunk-e25b23da":1};r[e]?n.push(r[e]):0!==r[e]&&c[e]&&n.push(r[e]=new Promise((function(n,c){for(var t="static/css/"+({}[e]||e)+"."+{"chunk-04a4268a":"31d6cfe0","chunk-0d3c079f":"96d11b58","chunk-1504cdfc":"febaf7ae","chunk-16eb7b18":"6d24dacd","chunk-2d230fe7":"31d6cfe0","chunk-3714bce8":"0ea63c11","chunk-380263e8":"6d24dacd","chunk-45e73af7":"5f8941eb","chunk-4934959c":"6d24dacd","chunk-4b345e33":"6d24dacd","chunk-648295c6":"6d24dacd","chunk-6f742c38":"454dc39d","chunk-7b878d9e":"62f36dd0","chunk-91584750":"13a7e89e","chunk-a6de055c":"9905f991","chunk-bc53b446":"55a106d0","chunk-434632c4":"adc5827d","chunk-e25b23da":"6d24dacd"}[e]+".css",u=d.p+t,a=document.getElementsByTagName("link"),o=0;o<a.length;o++){var f=a[o],h=f.getAttribute("data-href")||f.getAttribute("href");if("stylesheet"===f.rel&&(h===t||h===u))return n()}var i=document.getElementsByTagName("style");for(o=0;o<i.length;o++){f=i[o],h=f.getAttribute("data-href");if(h===t||h===u)return n()}var l=document.createElement("link");l.rel="stylesheet",l.type="text/css",l.onload=n,l.onerror=function(n){var t=n&&n.target&&n.target.src||u,a=new Error("Loading CSS chunk "+e+" failed.\n("+t+")");a.request=t,delete r[e],l.parentNode.removeChild(l),c(a)},l.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(l)})).then((function(){r[e]=0})));var t=u[e];if(0!==t)if(t)n.push(t[2]);else{var a=new Promise((function(n,c){t=u[e]=[n,c]}));n.push(t[2]=a);var f,h=document.createElement("script");h.charset="utf-8",h.timeout=120,d.nc&&h.setAttribute("nonce",d.nc),h.src=o(e),f=function(n){h.onerror=h.onload=null,clearTimeout(i);var c=u[e];if(0!==c){if(c){var t=n&&("load"===n.type?"missing":n.type),r=n&&n.target&&n.target.src,a=new Error("Loading chunk "+e+" failed.\n("+t+": "+r+")");a.type=t,a.request=r,c[1](a)}u[e]=void 0}};var i=setTimeout((function(){f({type:"timeout",target:h})}),12e4);h.onerror=h.onload=f,document.head.appendChild(h)}return Promise.all(n)},d.m=e,d.c=t,d.d=function(e,n,c){d.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:c})},d.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.t=function(e,n){if(1&n&&(e=d(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var c=Object.create(null);if(d.r(c),Object.defineProperty(c,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var t in e)d.d(c,t,function(n){return e[n]}.bind(null,t));return c},d.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return d.d(n,"a",n),n},d.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},d.p="/",d.oe=function(e){throw console.error(e),e};var f=window["webpackJsonp"]=window["webpackJsonp"]||[],h=f.push.bind(f);f.push=n,f=f.slice();for(var i=0;i<f.length;i++)n(f[i]);var l=h;c()})([]);</script><script src=/static/js/app.8f67bb7b.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=renderer content=webkit><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=/favicon.ico><title>Hippo4J Web</title><link href=/static/css/chunk-libs.5cf311f0.css rel=stylesheet><link href=/static/css/app.b20ed1d7.css rel=stylesheet></head><body><div id=app></div><script src=/static/js/chunk-elementUI.d48e2bf7.js></script><script src=/static/js/chunk-libs.fe111d69.js></script><script>(function(e){function n(n){for(var c,r,o=n[0],h=n[1],f=n[2],d=0,i=[];d<o.length;d++)r=o[d],u[r]&&i.push(u[r][0]),u[r]=0;for(c in h)Object.prototype.hasOwnProperty.call(h,c)&&(e[c]=h[c]);l&&l(n);while(i.length)i.shift()();return a.push.apply(a,f||[]),t()}function t(){for(var e,n=0;n<a.length;n++){for(var t=a[n],c=!0,r=1;r<t.length;r++){var o=t[r];0!==u[o]&&(c=!1)}c&&(a.splice(n--,1),e=h(h.s=t[0]))}return e}var c={},r={runtime:0},u={runtime:0},a=[];function o(e){return h.p+"static/js/"+({}[e]||e)+"."+{"chunk-04a4268a":"c9a819e9","chunk-1504cdfc":"27cead91","chunk-16eb7b18":"4a893ed8","chunk-2d230fe7":"19def69d","chunk-3714bce8":"e46b08f1","chunk-380263e8":"a0a57a63","chunk-45e73af7":"8a4c3972","chunk-4934959c":"d136ce71","chunk-4b345e33":"34b2197e","chunk-648295c6":"4847e0fe","chunk-6f742c38":"3d037de8","chunk-74061722":"f14efd6b","chunk-7b878d9e":"df580de3","chunk-91584750":"5760ea18","chunk-a6de055c":"ab7b6d21","chunk-bc53b446":"ca33db0c","chunk-434632c4":"18ecb7e6","chunk-e25b23da":"57f7ba66"}[e]+".js"}function h(n){if(c[n])return c[n].exports;var t=c[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,h),t.l=!0,t.exports}h.e=function(e){var n=[],t={"chunk-1504cdfc":1,"chunk-16eb7b18":1,"chunk-3714bce8":1,"chunk-380263e8":1,"chunk-45e73af7":1,"chunk-4934959c":1,"chunk-4b345e33":1,"chunk-648295c6":1,"chunk-6f742c38":1,"chunk-74061722":1,"chunk-7b878d9e":1,"chunk-91584750":1,"chunk-a6de055c":1,"chunk-bc53b446":1,"chunk-434632c4":1,"chunk-e25b23da":1};r[e]?n.push(r[e]):0!==r[e]&&t[e]&&n.push(r[e]=new Promise((function(n,t){for(var c="static/css/"+({}[e]||e)+"."+{"chunk-04a4268a":"31d6cfe0","chunk-1504cdfc":"225cb76f","chunk-16eb7b18":"e79296f6","chunk-2d230fe7":"31d6cfe0","chunk-3714bce8":"da5f00e0","chunk-380263e8":"e79296f6","chunk-45e73af7":"5f8941eb","chunk-4934959c":"23e5e93a","chunk-4b345e33":"e79296f6","chunk-648295c6":"23e5e93a","chunk-6f742c38":"454dc39d","chunk-74061722":"d522cc7d","chunk-7b878d9e":"879ae257","chunk-91584750":"13a7e89e","chunk-a6de055c":"e79296f6","chunk-bc53b446":"55a106d0","chunk-434632c4":"adc5827d","chunk-e25b23da":"23e5e93a"}[e]+".css",u=h.p+c,a=document.getElementsByTagName("link"),o=0;o<a.length;o++){var f=a[o],d=f.getAttribute("data-href")||f.getAttribute("href");if("stylesheet"===f.rel&&(d===c||d===u))return n()}var i=document.getElementsByTagName("style");for(o=0;o<i.length;o++){f=i[o],d=f.getAttribute("data-href");if(d===c||d===u)return n()}var l=document.createElement("link");l.rel="stylesheet",l.type="text/css",l.onload=n,l.onerror=function(n){var c=n&&n.target&&n.target.src||u,a=new Error("Loading CSS chunk "+e+" failed.\n("+c+")");a.request=c,delete r[e],l.parentNode.removeChild(l),t(a)},l.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(l)})).then((function(){r[e]=0})));var c=u[e];if(0!==c)if(c)n.push(c[2]);else{var a=new Promise((function(n,t){c=u[e]=[n,t]}));n.push(c[2]=a);var f,d=document.createElement("script");d.charset="utf-8",d.timeout=120,h.nc&&d.setAttribute("nonce",h.nc),d.src=o(e),f=function(n){d.onerror=d.onload=null,clearTimeout(i);var t=u[e];if(0!==t){if(t){var c=n&&("load"===n.type?"missing":n.type),r=n&&n.target&&n.target.src,a=new Error("Loading chunk "+e+" failed.\n("+c+": "+r+")");a.type=c,a.request=r,t[1](a)}u[e]=void 0}};var i=setTimeout((function(){f({type:"timeout",target:d})}),12e4);d.onerror=d.onload=f,document.head.appendChild(d)}return Promise.all(n)},h.m=e,h.c=c,h.d=function(e,n,t){h.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},h.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},h.t=function(e,n){if(1&n&&(e=h(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(h.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var c in e)h.d(t,c,function(n){return e[n]}.bind(null,c));return t},h.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return h.d(n,"a",n),n},h.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},h.p="/",h.oe=function(e){throw console.error(e),e};var f=window["webpackJsonp"]=window["webpackJsonp"]||[],d=f.push.bind(f);f.push=n,f=f.slice();for(var i=0;i<f.length;i++)n(f[i]);var l=d;t()})([]);</script><script src=/static/js/app.c9e78c0a.js></script></body></html>

@ -1 +1 @@
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.pagination-container[data-v-6af373ef]{background:#fff;padding:32px 16px}.pagination-container.hidden[data-v-6af373ef]{display:none}.stack-info>li[data-v-46b5eaa5]{margin-bottom:24px}.stack-info>li p[data-v-46b5eaa5]:first-child{color:#06f;font-weight:600;margin-top:10px}.stack-info>li ul[data-v-46b5eaa5]{margin-left:30px}.stack-info>li ul li[data-v-46b5eaa5]{color:#fc5531;text-align:justify;margin:10px auto}
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.pagination-container[data-v-6af373ef]{background:#fff;padding:32px 16px}.pagination-container.hidden[data-v-6af373ef]{display:none}.stack-info>li[data-v-71812458]{margin-bottom:24px}.stack-info>li p[data-v-71812458]:first-child{color:#06f;font-weight:600;margin-top:10px}.stack-info>li ul[data-v-71812458]{margin-left:30px}.stack-info>li ul li[data-v-71812458]{color:#fc5531;text-align:justify;margin:10px auto}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,18 +1,23 @@
package cn.hippo4j.starter.handler;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.util.ReflectionUtils;
import org.xnio.XnioWorker;
import cn.hippo4j.common.model.PoolBaseInfo;
import cn.hippo4j.common.model.PoolRunStateInfo;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.toolkit.CalculateUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Abstract threadPool runtime info.
*
@ -61,57 +66,107 @@ public abstract class AbstractThreadPoolRuntime {
public PoolRunStateInfo getPoolRunState(String threadPoolId, Executor executor) {
PoolRunStateInfo stateInfo = new PoolRunStateInfo();
if (executor != null && executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
// 核心线程数
int corePoolSize = pool.getCorePoolSize();
// 最大线程数
int maximumPoolSize = pool.getMaximumPoolSize();
// 线程池当前线程数 (有锁)
int poolSize = pool.getPoolSize();
// 活跃线程数 (有锁)
int activeCount = pool.getActiveCount();
// 同时进入池中的最大线程数 (有锁)
int largestPoolSize = pool.getLargestPoolSize();
// 线程池中执行任务总数量 (有锁)
long completedTaskCount = pool.getCompletedTaskCount();
// 当前负载
String currentLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
// 峰值负载
String peakLoad = CalculateUtil.divide(largestPoolSize, maximumPoolSize) + "";
BlockingQueue<Runnable> queue = pool.getQueue();
// 队列元素个数
int queueSize = queue.size();
// 队列类型
String queueType = queue.getClass().getSimpleName();
// 队列剩余容量
int remainingCapacity = queue.remainingCapacity();
// 队列容量
int queueCapacity = queueSize + remainingCapacity;
stateInfo.setCoreSize(corePoolSize);
stateInfo.setTpId(threadPoolId);
stateInfo.setPoolSize(poolSize);
stateInfo.setMaximumSize(maximumPoolSize);
stateInfo.setActiveSize(activeCount);
stateInfo.setCurrentLoad(currentLoad);
stateInfo.setPeakLoad(peakLoad);
stateInfo.setQueueType(queueType);
stateInfo.setQueueSize(queueSize);
stateInfo.setQueueCapacity(queueCapacity);
stateInfo.setQueueRemainingCapacity(remainingCapacity);
stateInfo.setLargestPoolSize(largestPoolSize);
stateInfo.setCompletedTaskCount(completedTaskCount);
long rejectCount = pool instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor) pool).getRejectCountNum()
: -1L;
stateInfo.setRejectCount(rejectCount);
stateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date()));
stateInfo.setTimestamp(System.currentTimeMillis());
createJucThreadPoolStateInfo(threadPoolId, executor, stateInfo);
} else if (executor != null && executor instanceof XnioWorker) {
createXnioThreadPoolStateInfo(threadPoolId, executor, stateInfo);
}
return supplement(stateInfo);
}
private void createXnioThreadPoolStateInfo(String threadPoolId, Executor executor, PoolRunStateInfo stateInfo) {
XnioWorker xnioWorker = (XnioWorker)executor;
// private final TaskPool taskPool;
Field field = ReflectionUtils.findField(XnioWorker.class, "taskPool");
ReflectionUtils.makeAccessible(field);
Object fieldObject = ReflectionUtils.getField(field, xnioWorker);
// 核心线程数
Method getCorePoolSize = ReflectionUtils.findMethod(fieldObject.getClass(), "getCorePoolSize");
ReflectionUtils.makeAccessible(getCorePoolSize);
int corePoolSize = (int)ReflectionUtils.invokeMethod(getCorePoolSize, fieldObject);
// 最大线程数
Method getMaximumPoolSize = ReflectionUtils.findMethod(fieldObject.getClass(), "getMaximumPoolSize");
ReflectionUtils.makeAccessible(getMaximumPoolSize);
int maximumPoolSize = (int)ReflectionUtils.invokeMethod(getMaximumPoolSize, fieldObject);
// 线程池当前线程数 (有锁)
Method getPoolSize = ReflectionUtils.findMethod(fieldObject.getClass(), "getPoolSize");
ReflectionUtils.makeAccessible(getPoolSize);
int poolSize = (int)ReflectionUtils.invokeMethod(getPoolSize, fieldObject);
// 活跃线程数 (有锁)
Method getActiveCount = ReflectionUtils.findMethod(fieldObject.getClass(), "getActiveCount");
ReflectionUtils.makeAccessible(getActiveCount);
int activeCount = (int)ReflectionUtils.invokeMethod(getActiveCount, fieldObject);
activeCount = (activeCount <= 0) ? 0 : activeCount;
// 当前负载
String currentLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
// 峰值负载
// 没有峰值记录,直接使用当前数据
String peakLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
stateInfo.setCoreSize(corePoolSize);
stateInfo.setTpId(threadPoolId);
stateInfo.setPoolSize(poolSize);
stateInfo.setMaximumSize(maximumPoolSize);
stateInfo.setActiveSize(activeCount);
stateInfo.setCurrentLoad(currentLoad);
stateInfo.setPeakLoad(peakLoad);
long rejectCount = fieldObject instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor)fieldObject).getRejectCountNum() : -1L;
stateInfo.setRejectCount(rejectCount);
stateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date()));
stateInfo.setTimestamp(System.currentTimeMillis());
}
private void createJucThreadPoolStateInfo(String threadPoolId, Executor executor, PoolRunStateInfo stateInfo) {
ThreadPoolExecutor pool = (ThreadPoolExecutor)executor;
// 核心线程数
int corePoolSize = pool.getCorePoolSize();
// 最大线程数
int maximumPoolSize = pool.getMaximumPoolSize();
// 线程池当前线程数 (有锁)
int poolSize = pool.getPoolSize();
// 活跃线程数 (有锁)
int activeCount = pool.getActiveCount();
// 同时进入池中的最大线程数 (有锁)
int largestPoolSize = pool.getLargestPoolSize();
// 线程池中执行任务总数量 (有锁)
long completedTaskCount = pool.getCompletedTaskCount();
// 当前负载
String currentLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
// 峰值负载
String peakLoad = CalculateUtil.divide(largestPoolSize, maximumPoolSize) + "";
BlockingQueue<Runnable> queue = pool.getQueue();
// 队列元素个数
int queueSize = queue.size();
// 队列类型
String queueType = queue.getClass().getSimpleName();
// 队列剩余容量
int remainingCapacity = queue.remainingCapacity();
// 队列容量
int queueCapacity = queueSize + remainingCapacity;
stateInfo.setCoreSize(corePoolSize);
stateInfo.setTpId(threadPoolId);
stateInfo.setPoolSize(poolSize);
stateInfo.setMaximumSize(maximumPoolSize);
stateInfo.setActiveSize(activeCount);
stateInfo.setCurrentLoad(currentLoad);
stateInfo.setPeakLoad(peakLoad);
stateInfo.setQueueType(queueType);
stateInfo.setQueueSize(queueSize);
stateInfo.setQueueCapacity(queueCapacity);
stateInfo.setQueueRemainingCapacity(remainingCapacity);
stateInfo.setLargestPoolSize(largestPoolSize);
stateInfo.setCompletedTaskCount(completedTaskCount);
long rejectCount =
pool instanceof DynamicThreadPoolExecutor ? ((DynamicThreadPoolExecutor)pool).getRejectCountNum() : -1L;
stateInfo.setRejectCount(rejectCount);
stateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date()));
stateInfo.setTimestamp(System.currentTimeMillis());
}
}

Loading…
Cancel
Save