diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/notify/DynamicThreadPoolRegisterCoreNotifyParameter.java b/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/notify/DynamicThreadPoolRegisterCoreNotifyParameter.java index d124fd1a..b4da1736 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/notify/DynamicThreadPoolRegisterCoreNotifyParameter.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/model/register/notify/DynamicThreadPoolRegisterCoreNotifyParameter.java @@ -31,19 +31,16 @@ public class DynamicThreadPoolRegisterCoreNotifyParameter { /** * Whether to enable thread pool running alarm */ - @NonNull - private Boolean alarm; + private Boolean alarm = Boolean.TRUE; /** * Active alarm */ - @NonNull private Integer activeAlarm; /** * Capacity alarm */ - @NonNull private Integer capacityAlarm; /** diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java index 90d24bad..d27c04e8 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java @@ -106,7 +106,8 @@ public class ThreadPoolAdapterService { try { String resultStr = HttpUtil.get(urlString, param, HTTP_EXECUTE_TIMEOUT); if (StringUtil.isNotBlank(resultStr)) { - Result restResult = JSONUtil.parseObject(resultStr, new TypeReference>(){}); + Result restResult = JSONUtil.parseObject(resultStr, new TypeReference>() { + }); result.add(restResult.getData()); } } catch (Throwable ex) { diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java index a1aea70b..09bde6f0 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java @@ -24,10 +24,10 @@ import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler; import cn.hippo4j.core.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor; import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder; -import cn.hippo4j.core.springboot.starter.refresher.event.AdapterExecutorsListener; -import cn.hippo4j.core.springboot.starter.refresher.event.ExecutorsListener; -import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsListener; -import cn.hippo4j.core.springboot.starter.refresher.event.WebExecutorListener; +import cn.hippo4j.core.springboot.starter.refresher.event.AdapterExecutorsRefreshListener; +import cn.hippo4j.core.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener; +import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsRefreshListener; +import cn.hippo4j.core.springboot.starter.refresher.event.WebExecutorRefreshListener; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolAdapterRegister; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolPostProcessor; @@ -94,25 +94,25 @@ public class DynamicThreadPoolCoreAutoConfiguration { @Bean @SuppressWarnings("all") - public ExecutorsListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, - CoreNotifyConfigBuilder coreNotifyConfigBuilder, - Hippo4jBaseSendMessageService hippoBaseSendMessageService) { - return new ExecutorsListener(threadPoolNotifyAlarmHandler, coreNotifyConfigBuilder, hippoBaseSendMessageService); + public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, + CoreNotifyConfigBuilder coreNotifyConfigBuilder, + Hippo4jBaseSendMessageService hippoBaseSendMessageService) { + return new DynamicThreadPoolRefreshListener(threadPoolNotifyAlarmHandler, coreNotifyConfigBuilder, hippoBaseSendMessageService); } @Bean - public AdapterExecutorsListener hippo4jAdapterExecutorsListener() { - return new AdapterExecutorsListener(); + public AdapterExecutorsRefreshListener hippo4jAdapterExecutorsListener() { + return new AdapterExecutorsRefreshListener(); } @Bean - public PlatformsListener hippo4jPlatformsListener() { - return new PlatformsListener(); + public PlatformsRefreshListener hippo4jPlatformsListener() { + return new PlatformsRefreshListener(); } @Bean - public WebExecutorListener hippo4jWebExecutorListener() { - return new WebExecutorListener(); + public WebExecutorRefreshListener hippo4jWebExecutorListener() { + return new WebExecutorRefreshListener(); } @Bean diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolNotifyProperties.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolNotifyProperties.java new file mode 100644 index 00000000..0f132f0a --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/DynamicThreadPoolNotifyProperties.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.core.springboot.starter.config; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Dynamic thread-pool notify properties. + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DynamicThreadPoolNotifyProperties { + + /** + * Interval + */ + private Integer interval; + + /** + * Receives + */ + private String receives; +} diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/ExecutorProperties.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/ExecutorProperties.java index 60d013fa..735a0d13 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/ExecutorProperties.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/config/ExecutorProperties.java @@ -17,7 +17,6 @@ package cn.hippo4j.core.springboot.starter.config; -import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -29,9 +28,9 @@ import lombok.experimental.Accessors; */ @Data @Builder -@Accessors(chain = true) @NoArgsConstructor @AllArgsConstructor +@Accessors(chain = true) public class ExecutorProperties { /** @@ -84,8 +83,23 @@ public class ExecutorProperties { */ private String threadNamePrefix; + /** + * Whether to enable thread pool running alarm + */ + private Boolean alarm; + + /** + * Active alarm + */ + private Integer activeAlarm; + + /** + * Capacity alarm + */ + private Integer capacityAlarm; + /** * Notify */ - private ThreadPoolNotifyAlarm notify; + private DynamicThreadPoolNotifyProperties notify; } diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/notify/CoreNotifyConfigBuilder.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/notify/CoreNotifyConfigBuilder.java index 230e8d6c..dd05837c 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/notify/CoreNotifyConfigBuilder.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/notify/CoreNotifyConfigBuilder.java @@ -56,7 +56,7 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder { log.warn("Failed to build notify, executors configuration is empty."); return resultMap; } - List actual = executors.stream().filter(each -> Optional.ofNullable(each.getNotify()).map(notify -> notify.getAlarm()).orElse(false)).collect(Collectors.toList()); + List actual = executors.stream().filter(each -> Optional.ofNullable(each.getAlarm()).orElse(false)).collect(Collectors.toList()); if (!globalAlarm && CollectionUtil.isEmpty(actual)) { return resultMap; } diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/BootstrapCorePropertiesBinderAdapt.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/BootstrapCorePropertiesBinderAdapt.java index 7053b0c5..38978be1 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/BootstrapCorePropertiesBinderAdapt.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/BootstrapCorePropertiesBinderAdapt.java @@ -20,9 +20,9 @@ package cn.hippo4j.core.springboot.starter.refresher; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; +import cn.hippo4j.core.springboot.starter.config.DynamicThreadPoolNotifyProperties; import cn.hippo4j.core.springboot.starter.config.ExecutorProperties; import cn.hippo4j.core.springboot.starter.config.NotifyPlatformProperties; -import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import com.google.common.collect.Lists; @@ -136,7 +136,7 @@ public class BootstrapCorePropertiesBinderAdapt { ExecutorProperties executorProperties = BeanUtil.mapToBean(executorSingleMap, ExecutorProperties.class, true, CopyOptions.create()); if (executorProperties != null) { if (CollectionUtil.isNotEmpty(notifySingleMap)) { - ThreadPoolNotifyAlarm alarm = BeanUtil.mapToBean(notifySingleMap, ThreadPoolNotifyAlarm.class, true, CopyOptions.create()); + DynamicThreadPoolNotifyProperties alarm = BeanUtil.mapToBean(notifySingleMap, DynamicThreadPoolNotifyProperties.class, true, CopyOptions.create()); alarm.setReceives(alarm.getReceives()); executorProperties.setNotify(alarm); } diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/ZookeeperRefresherHandler.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/ZookeeperRefresherHandler.java index 25f875e2..1713f7b4 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/ZookeeperRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/ZookeeperRefresherHandler.java @@ -110,9 +110,9 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr public void registerNotifyAlarmManage() { bootstrapCoreProperties.getExecutors().forEach(executorProperties -> { ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( - executorProperties.getNotify().getAlarm(), - executorProperties.getNotify().getCapacityAlarm(), - executorProperties.getNotify().getActiveAlarm()); + executorProperties.getAlarm(), + executorProperties.getCapacityAlarm(), + executorProperties.getActiveAlarm()); threadPoolNotifyAlarm.setInterval(executorProperties.getNotify().getInterval()); threadPoolNotifyAlarm.setReceives(executorProperties.getNotify().getReceives()); GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm); diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsListener.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java similarity index 95% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsListener.java rename to hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java index 217f1288..a0ec4b53 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsListener.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java @@ -36,11 +36,11 @@ import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDyna import static cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolAdapterRegister.ADAPTER_EXECUTORS_MAP; /** - * Adapter executors listener. + * Adapter executors refresh listener. */ @Slf4j @Order(ADAPTER_EXECUTORS_LISTENER) -public class AdapterExecutorsListener implements ApplicationListener { +public class AdapterExecutorsRefreshListener implements ApplicationListener { @Override public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent event) { diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/ExecutorsListener.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java similarity index 97% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/ExecutorsListener.java rename to hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java index a0db5d50..4a8aa52e 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/ExecutorsListener.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/DynamicThreadPoolRefreshListener.java @@ -54,12 +54,12 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.EXECUTORS_LISTENER; /** - * Executors listener. + * Dynamic thread-pool refresh listener. */ @Slf4j @RequiredArgsConstructor @Order(EXECUTORS_LISTENER) -public class ExecutorsListener implements ApplicationListener { +public class DynamicThreadPoolRefreshListener implements ApplicationListener { private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler; @@ -162,11 +162,10 @@ public class ExecutorsListener implements ApplicationListener { +public class PlatformsRefreshListener implements ApplicationListener { @Override public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) { diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorListener.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorRefreshListener.java similarity index 96% rename from hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorListener.java rename to hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorRefreshListener.java index e191caef..96a8ee7e 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorListener.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/refresher/event/WebExecutorRefreshListener.java @@ -33,11 +33,11 @@ import java.util.Objects; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER; /** - * Web executor listener. + * Web executor refresh listener. */ @Slf4j @Order(WEB_EXECUTOR_LISTENER) -public class WebExecutorListener implements ApplicationListener { +public class WebExecutorRefreshListener implements ApplicationListener { @Override public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) { diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java index ee9c3be4..9ef99fa5 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -27,6 +27,7 @@ import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.support.*; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; +import cn.hippo4j.core.springboot.starter.config.DynamicThreadPoolNotifyProperties; import cn.hippo4j.core.springboot.starter.config.ExecutorProperties; import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; @@ -137,13 +138,13 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { } } if (dynamicThreadPoolWrapper.getExecutor() instanceof AbstractDynamicExecutorSupport) { - ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); - boolean isAlarm = Optional.ofNullable(notify) - .map(each -> each.getAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); - int activeAlarm = Optional.ofNullable(notify) - .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80); - int capacityAlarm = Optional.ofNullable(notify) - .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80); + + DynamicThreadPoolNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); + boolean isAlarm = Optional.ofNullable(bootstrapCoreProperties.getAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); + int activeAlarm = + Optional.ofNullable(bootstrapCoreProperties.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80); + int capacityAlarm = Optional.ofNullable(bootstrapCoreProperties.getCapacityAlarm()) + .orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80); int interval = Optional.ofNullable(notify) .map(each -> each.getInterval()).orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5); String receive = Optional.ofNullable(notify)