From 2f4c8bedbe2b55941be9d9000cc2ea446bae2659 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sat, 5 Nov 2022 22:02:13 +0800 Subject: [PATCH] Refactor dynamic thread pool registration variable naming --- .../model/register/DynamicThreadPoolRegisterWrapper.java | 8 ++++---- .../core/inittest/RegisterDynamicThreadPoolTest.java | 6 +++--- .../config/service/biz/impl/ConfigServiceImpl.java | 4 ++-- .../starter/support/DynamicThreadPoolConfigService.java | 9 +++------ .../starter/support/DynamicThreadPoolConfigService.java | 6 +++--- .../starter/support/DynamicThreadPoolPostProcessor.java | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/DynamicThreadPoolRegisterWrapper.java b/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/DynamicThreadPoolRegisterWrapper.java index a543223e..a14fbc53 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/DynamicThreadPoolRegisterWrapper.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/DynamicThreadPoolRegisterWrapper.java @@ -38,7 +38,7 @@ public class DynamicThreadPoolRegisterWrapper { /** * Dynamic thread-pool register parameter */ - private DynamicThreadPoolRegisterParameter dynamicThreadPoolRegisterParameter; + private DynamicThreadPoolRegisterParameter parameter; // Hippo4j server ---------------------------------------------------------------------- @@ -65,12 +65,12 @@ public class DynamicThreadPoolRegisterWrapper { /** * Dynamic thread-pool server notify parameter */ - private DynamicThreadPoolRegisterServerNotifyParameter dynamicThreadPoolRegisterServerNotifyParameter; + private DynamicThreadPoolRegisterServerNotifyParameter serverNotify; // Hippo4j core ---------------------------------------------------------------------- /** - * Dynamic thread-pool core notify parameter + * Dynamic thread-pool config notify parameter */ - private DynamicThreadPoolRegisterCoreNotifyParameter dynamicThreadPoolRegisterCoreNotifyParameter; + private DynamicThreadPoolRegisterCoreNotifyParameter configNotify; } diff --git a/hippo4j-example/hippo4j-example-core/src/main/java/cn/hippo4j/example/core/inittest/RegisterDynamicThreadPoolTest.java b/hippo4j-example/hippo4j-example-core/src/main/java/cn/hippo4j/example/core/inittest/RegisterDynamicThreadPoolTest.java index 9bc5dc79..5699a205 100644 --- a/hippo4j-example/hippo4j-example-core/src/main/java/cn/hippo4j/example/core/inittest/RegisterDynamicThreadPoolTest.java +++ b/hippo4j-example/hippo4j-example-core/src/main/java/cn/hippo4j/example/core/inittest/RegisterDynamicThreadPoolTest.java @@ -68,9 +68,9 @@ public class RegisterDynamicThreadPoolTest { DynamicThreadPoolRegisterWrapper registerWrapper = DynamicThreadPoolRegisterWrapper.builder() .updateIfExists(true) .notifyUpdateIfExists(true) - .dynamicThreadPoolRegisterParameter(parameterInfo) - .dynamicThreadPoolRegisterCoreNotifyParameter(coreNotifyParameter) - .dynamicThreadPoolRegisterServerNotifyParameter(serverNotifyParameter) + .parameter(parameterInfo) + .configNotify(coreNotifyParameter) + .serverNotify(serverNotifyParameter) .build(); ThreadPoolExecutor dynamicThreadPool = GlobalThreadPoolManage.dynamicRegister(registerWrapper); log.info("Dynamic registration thread pool parameter details: {}", JSONUtil.toJSONString(dynamicThreadPool)); diff --git a/hippo4j-server/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigServiceImpl.java b/hippo4j-server/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigServiceImpl.java index bf70a5b9..ab5c43a2 100644 --- a/hippo4j-server/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigServiceImpl.java +++ b/hippo4j-server/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigServiceImpl.java @@ -151,7 +151,7 @@ public class ConfigServiceImpl implements ConfigService { ConfigServiceImpl configService = ApplicationContextHolder.getBean(this.getClass()); configService.updateConfigInfo(null, false, configAllInfo); } - DynamicThreadPoolRegisterServerNotifyParameter serverNotifyParameter = registerWrapper.getDynamicThreadPoolRegisterServerNotifyParameter(); + DynamicThreadPoolRegisterServerNotifyParameter serverNotifyParameter = registerWrapper.getServerNotify(); if (serverNotifyParameter != null) { ArrayList notifyTypes = new ArrayList<>(); Collections.addAll(notifyTypes, "CONFIG", "ALARM"); @@ -177,7 +177,7 @@ public class ConfigServiceImpl implements ConfigService { } private ConfigAllInfo parseConfigAllInfo(DynamicThreadPoolRegisterWrapper registerWrapper) { - DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getDynamicThreadPoolRegisterParameter(); + DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); ConfigAllInfo configAllInfo = JSONUtil.parseObject(JSONUtil.toJSONString(registerParameter), ConfigAllInfo.class); configAllInfo.setTenantId(registerWrapper.getTenantId()); configAllInfo.setItemId(registerWrapper.getItemId()); diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolConfigService.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolConfigService.java index d834361d..4a997d77 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolConfigService.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolConfigService.java @@ -39,29 +39,26 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer @Override public ThreadPoolExecutor registerDynamicThreadPool(DynamicThreadPoolRegisterWrapper registerWrapper) { - DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getDynamicThreadPoolRegisterParameter(); + DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); String threadPoolId = registerParameter.getThreadPoolId(); ThreadPoolExecutor dynamicThreadPoolExecutor = buildDynamicThreadPoolExecutor(registerParameter); DynamicThreadPoolWrapper dynamicThreadPoolWrapper = DynamicThreadPoolWrapper.builder() .threadPoolId(threadPoolId) .executor(dynamicThreadPoolExecutor) .build(); - // Register pool. GlobalThreadPoolManage.registerPool(threadPoolId, dynamicThreadPoolWrapper); ExecutorProperties executorProperties = buildExecutorProperties(registerWrapper); - // Register properties. GlobalCoreThreadPoolManage.register(threadPoolId, executorProperties); - DynamicThreadPoolRegisterCoreNotifyParameter notifyParameter = registerWrapper.getDynamicThreadPoolRegisterCoreNotifyParameter(); + DynamicThreadPoolRegisterCoreNotifyParameter notifyParameter = registerWrapper.getConfigNotify(); ThreadPoolNotifyAlarm notifyAlarm = new ThreadPoolNotifyAlarm(true, registerParameter.getActiveAlarm(), registerParameter.getCapacityAlarm()); notifyAlarm.setReceives(notifyParameter.getReceives()); notifyAlarm.setInterval(notifyParameter.getInterval()); - // Register notify. GlobalNotifyAlarmManage.put(threadPoolId, notifyAlarm); return dynamicThreadPoolExecutor; } private ExecutorProperties buildExecutorProperties(DynamicThreadPoolRegisterWrapper registerWrapper) { - DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getDynamicThreadPoolRegisterParameter(); + DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); ExecutorProperties executorProperties = ExecutorProperties.builder() .corePoolSize(registerParameter.getCorePoolSize()) .maximumPoolSize(registerParameter.getMaximumPoolSize()) diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java index 02c9eb02..663b07dc 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java @@ -73,7 +73,7 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer } private ThreadPoolExecutor registerExecutor(DynamicThreadPoolRegisterWrapper registerWrapper) { - DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getDynamicThreadPoolRegisterParameter(); + DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); checkThreadPoolParameter(registerParameter); String threadPoolId = registerParameter.getThreadPoolId(); try { @@ -98,11 +98,11 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer } private void subscribeConfig(DynamicThreadPoolRegisterWrapper registerWrapper) { - dynamicThreadPoolSubscribeConfig.subscribeConfig(registerWrapper.getDynamicThreadPoolRegisterParameter().getThreadPoolId()); + dynamicThreadPoolSubscribeConfig.subscribeConfig(registerWrapper.getParameter().getThreadPoolId()); } private void putNotifyAlarmConfig(DynamicThreadPoolRegisterWrapper registerWrapper) { - DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getDynamicThreadPoolRegisterParameter(); + DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( BooleanUtil.toBoolean(String.valueOf(registerParameter.getIsAlarm())), registerParameter.getActiveAlarm(), diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java index 041d64ae..62bbe59b 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -156,7 +156,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { .rejectedPolicyType(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName())) .build(); DynamicThreadPoolRegisterWrapper registerWrapper = DynamicThreadPoolRegisterWrapper.builder() - .dynamicThreadPoolRegisterParameter(parameterInfo) + .parameter(parameterInfo) .build(); GlobalThreadPoolManage.dynamicRegister(registerWrapper); }