【优化】调整client端请求方式

【优化】调整client端请求方式,改为由server端转发获取client端线程池信息
pull/150/head
eddy 2 years ago
parent 6a5ee7fcef
commit d2aadc520c

@ -29,7 +29,7 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public IPage<PermissionRespDTO> listPermission(int pageNo, int pageSize) {
PermissionQueryPageReqDTO queryPage = new PermissionQueryPageReqDTO(pageNo, pageSize);
IPage<PermissionInfo> selectPage = permissionMapper.selectPage(queryPage, null);
IPage<PermissionInfo> selectPage = permissionMapper.selectPage((IPage)queryPage, null);
return selectPage.convert(each -> BeanUtil.toBean(each, PermissionRespDTO.class));
}

@ -36,7 +36,7 @@ public class RoleServiceImpl implements RoleService {
@Override
public IPage<RoleRespDTO> listRole(int pageNo, int pageSize) {
RoleQueryPageReqDTO queryPage = new RoleQueryPageReqDTO(pageNo, pageSize);
IPage<RoleInfo> selectPage = roleMapper.selectPage(queryPage, null);
IPage<RoleInfo> selectPage = roleMapper.selectPage((IPage)queryPage, null);
return selectPage.convert(each -> BeanUtil.toBean(each, RoleRespDTO.class));
}

@ -44,7 +44,7 @@ public class UserServiceImpl implements UserService {
public IPage<UserRespDTO> listUser(UserQueryPageReqDTO reqDTO) {
LambdaQueryWrapper<UserInfo> queryWrapper = Wrappers.lambdaQuery(UserInfo.class)
.eq(StringUtil.isNotBlank(reqDTO.getUserName()), UserInfo::getUserName, reqDTO.getUserName());
IPage<UserInfo> selectPage = userMapper.selectPage(reqDTO, queryWrapper);
IPage<UserInfo> selectPage = userMapper.selectPage((IPage)reqDTO, queryWrapper);
return selectPage.convert(each -> BeanUtil.toBean(each, UserRespDTO.class));
}

@ -46,7 +46,7 @@ public class ItemServiceImpl implements ItemService {
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), ItemInfo::getOwner, reqDTO.getOwner());
Page<ItemInfo> resultPage = itemInfoMapper.selectPage(reqDTO, wrapper);
Page<ItemInfo> resultPage = itemInfoMapper.selectPage((Page)reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, ItemRespDTO.class));
}

@ -32,7 +32,7 @@ public class LogRecordBizServiceImpl implements LogRecordBizService {
.eq(StrUtil.isNotBlank(pageQuery.getCategory()), LogRecordInfo::getCategory, pageQuery.getCategory())
.eq(StrUtil.isNotBlank(pageQuery.getOperator()), LogRecordInfo::getOperator, pageQuery.getOperator())
.orderByDesc(LogRecordInfo::getCreateTime);
IPage<LogRecordInfo> selectPage = logRecordMapper.selectPage(pageQuery, queryWrapper);
IPage<LogRecordInfo> selectPage = logRecordMapper.selectPage((IPage)pageQuery, queryWrapper);
return selectPage.convert(each -> BeanUtil.convert(each, LogRecordRespDTO.class));
}

@ -63,7 +63,7 @@ public class NotifyServiceImpl implements NotifyService {
.eq(StrUtil.isNotBlank(reqDTO.getTpId()), NotifyInfo::getTpId, reqDTO.getTpId())
.orderByDesc(NotifyInfo::getGmtCreate);
IPage<NotifyInfo> resultPage = notifyInfoMapper.selectPage(reqDTO, queryWrapper);
IPage<NotifyInfo> resultPage = notifyInfoMapper.selectPage((IPage)reqDTO, queryWrapper);
return resultPage.convert(each -> BeanUtil.convert(each, NotifyRespDTO.class));
}

@ -62,7 +62,7 @@ public class TenantServiceImpl implements TenantService {
.eq(!StringUtils.isEmpty(reqDTO.getTenantName()), TenantInfo::getTenantName, reqDTO.getTenantName())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), TenantInfo::getOwner, reqDTO.getOwner());
Page resultPage = tenantInfoMapper.selectPage(reqDTO, wrapper);
Page resultPage = tenantInfoMapper.selectPage((Page)reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, TenantRespDTO.class));
}

@ -43,7 +43,7 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
.eq(ConfigAllInfo::getDelFlag, DelEnum.NORMAL)
.orderByDesc(ConfigAllInfo::getGmtCreate);
return configInfoMapper.selectPage(reqDTO, wrapper).convert(each -> BeanUtil.convert(each, ThreadPoolRespDTO.class));
return configInfoMapper.selectPage((IPage)reqDTO, wrapper).convert(each -> BeanUtil.convert(each, ThreadPoolRespDTO.class));
}
@Override

@ -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,19 @@ 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());
}
}

@ -47,7 +47,7 @@ public class ThreadPoolStatusHandler {
Method runStateAtLeast = ReflectUtil.getMethodByName(ThreadPoolExecutor.class, "runStateAtLeast");
cn.hippo4j.common.toolkit.ReflectUtil.setAccessible(runStateAtLeast);
int terminated = (int) ReflectUtil.getFieldValue(executor, "TERMINATED");
String resultStatus = ReflectUtil.invoke(executor, runStateAtLeast, ctl.get(), terminated) ? TERMINATED : SHUTTING_DOWN;
String resultStatus = (boolean)ReflectUtil.invoke(executor, runStateAtLeast, ctl.get(), terminated) ? TERMINATED : SHUTTING_DOWN;
return resultStatus;
} catch (Exception ex) {
log.error("Failed to get thread pool status.", ex);

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-tools</artifactId>
<version>1.1.0-2022032101</version>
</parent>
<groupId>cn.hippo4j</groupId>
<artifactId>log-record-tool</artifactId>
<version>1.1.0-2022032101</version>
<name>${project.artifactId}</name>
<description>操作日志记录工具类.</description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
</project>
Loading…
Cancel
Save