Adjust hippo4j-core module properties

pull/516/head
chen.ma 2 years ago
parent 71e965c85d
commit a90ac19bb6

@ -31,19 +31,16 @@ public class DynamicThreadPoolRegisterCoreNotifyParameter {
/** /**
* Whether to enable thread pool running alarm * Whether to enable thread pool running alarm
*/ */
@NonNull private Boolean alarm = Boolean.TRUE;
private Boolean alarm;
/** /**
* Active alarm * Active alarm
*/ */
@NonNull
private Integer activeAlarm; private Integer activeAlarm;
/** /**
* Capacity alarm * Capacity alarm
*/ */
@NonNull
private Integer capacityAlarm; private Integer capacityAlarm;
/** /**

@ -106,7 +106,8 @@ public class ThreadPoolAdapterService {
try { try {
String resultStr = HttpUtil.get(urlString, param, HTTP_EXECUTE_TIMEOUT); String resultStr = HttpUtil.get(urlString, param, HTTP_EXECUTE_TIMEOUT);
if (StringUtil.isNotBlank(resultStr)) { if (StringUtil.isNotBlank(resultStr)) {
Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>(){}); Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>() {
});
result.add(restResult.getData()); result.add(restResult.getData());
} }
} catch (Throwable ex) { } catch (Throwable ex) {

@ -24,10 +24,10 @@ import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.handler.DynamicThreadPoolBannerHandler;
import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor; import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor;
import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder; 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.AdapterExecutorsRefreshListener;
import cn.hippo4j.core.springboot.starter.refresher.event.ExecutorsListener; import cn.hippo4j.core.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener;
import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsListener; import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsRefreshListener;
import cn.hippo4j.core.springboot.starter.refresher.event.WebExecutorListener; import cn.hippo4j.core.springboot.starter.refresher.event.WebExecutorRefreshListener;
import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolAdapterRegister; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolAdapterRegister;
import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolConfigService;
import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolPostProcessor; import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolPostProcessor;
@ -94,25 +94,25 @@ public class DynamicThreadPoolCoreAutoConfiguration {
@Bean @Bean
@SuppressWarnings("all") @SuppressWarnings("all")
public ExecutorsListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler,
CoreNotifyConfigBuilder coreNotifyConfigBuilder, CoreNotifyConfigBuilder coreNotifyConfigBuilder,
Hippo4jBaseSendMessageService hippoBaseSendMessageService) { Hippo4jBaseSendMessageService hippoBaseSendMessageService) {
return new ExecutorsListener(threadPoolNotifyAlarmHandler, coreNotifyConfigBuilder, hippoBaseSendMessageService); return new DynamicThreadPoolRefreshListener(threadPoolNotifyAlarmHandler, coreNotifyConfigBuilder, hippoBaseSendMessageService);
} }
@Bean @Bean
public AdapterExecutorsListener hippo4jAdapterExecutorsListener() { public AdapterExecutorsRefreshListener hippo4jAdapterExecutorsListener() {
return new AdapterExecutorsListener(); return new AdapterExecutorsRefreshListener();
} }
@Bean @Bean
public PlatformsListener hippo4jPlatformsListener() { public PlatformsRefreshListener hippo4jPlatformsListener() {
return new PlatformsListener(); return new PlatformsRefreshListener();
} }
@Bean @Bean
public WebExecutorListener hippo4jWebExecutorListener() { public WebExecutorRefreshListener hippo4jWebExecutorListener() {
return new WebExecutorListener(); return new WebExecutorRefreshListener();
} }
@Bean @Bean

@ -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;
}

@ -17,7 +17,6 @@
package cn.hippo4j.core.springboot.starter.config; package cn.hippo4j.core.springboot.starter.config;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -29,9 +28,9 @@ import lombok.experimental.Accessors;
*/ */
@Data @Data
@Builder @Builder
@Accessors(chain = true)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Accessors(chain = true)
public class ExecutorProperties { public class ExecutorProperties {
/** /**
@ -84,8 +83,23 @@ public class ExecutorProperties {
*/ */
private String threadNamePrefix; private String threadNamePrefix;
/**
* Whether to enable thread pool running alarm
*/
private Boolean alarm;
/**
* Active alarm
*/
private Integer activeAlarm;
/**
* Capacity alarm
*/
private Integer capacityAlarm;
/** /**
* Notify * Notify
*/ */
private ThreadPoolNotifyAlarm notify; private DynamicThreadPoolNotifyProperties notify;
} }

@ -56,7 +56,7 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
log.warn("Failed to build notify, executors configuration is empty."); log.warn("Failed to build notify, executors configuration is empty.");
return resultMap; return resultMap;
} }
List<ExecutorProperties> actual = executors.stream().filter(each -> Optional.ofNullable(each.getNotify()).map(notify -> notify.getAlarm()).orElse(false)).collect(Collectors.toList()); List<ExecutorProperties> actual = executors.stream().filter(each -> Optional.ofNullable(each.getAlarm()).orElse(false)).collect(Collectors.toList());
if (!globalAlarm && CollectionUtil.isEmpty(actual)) { if (!globalAlarm && CollectionUtil.isEmpty(actual)) {
return resultMap; return resultMap;
} }

@ -20,9 +20,9 @@ package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; 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.ExecutorProperties;
import cn.hippo4j.core.springboot.starter.config.NotifyPlatformProperties; 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.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -136,7 +136,7 @@ public class BootstrapCorePropertiesBinderAdapt {
ExecutorProperties executorProperties = BeanUtil.mapToBean(executorSingleMap, ExecutorProperties.class, true, CopyOptions.create()); ExecutorProperties executorProperties = BeanUtil.mapToBean(executorSingleMap, ExecutorProperties.class, true, CopyOptions.create());
if (executorProperties != null) { if (executorProperties != null) {
if (CollectionUtil.isNotEmpty(notifySingleMap)) { 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()); alarm.setReceives(alarm.getReceives());
executorProperties.setNotify(alarm); executorProperties.setNotify(alarm);
} }

@ -110,9 +110,9 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
public void registerNotifyAlarmManage() { public void registerNotifyAlarmManage() {
bootstrapCoreProperties.getExecutors().forEach(executorProperties -> { bootstrapCoreProperties.getExecutors().forEach(executorProperties -> {
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(
executorProperties.getNotify().getAlarm(), executorProperties.getAlarm(),
executorProperties.getNotify().getCapacityAlarm(), executorProperties.getCapacityAlarm(),
executorProperties.getNotify().getActiveAlarm()); executorProperties.getActiveAlarm());
threadPoolNotifyAlarm.setInterval(executorProperties.getNotify().getInterval()); threadPoolNotifyAlarm.setInterval(executorProperties.getNotify().getInterval());
threadPoolNotifyAlarm.setReceives(executorProperties.getNotify().getReceives()); threadPoolNotifyAlarm.setReceives(executorProperties.getNotify().getReceives());
GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm);

@ -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; import static cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolAdapterRegister.ADAPTER_EXECUTORS_MAP;
/** /**
* Adapter executors listener. * Adapter executors refresh listener.
*/ */
@Slf4j @Slf4j
@Order(ADAPTER_EXECUTORS_LISTENER) @Order(ADAPTER_EXECUTORS_LISTENER)
public class AdapterExecutorsListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> { public class AdapterExecutorsRefreshListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
@Override @Override
public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent event) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent event) {

@ -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; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.EXECUTORS_LISTENER;
/** /**
* Executors listener. * Dynamic thread-pool refresh listener.
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@Order(EXECUTORS_LISTENER) @Order(EXECUTORS_LISTENER)
public class ExecutorsListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> { public class DynamicThreadPoolRefreshListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler; private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
@ -162,11 +162,10 @@ public class ExecutorsListener implements ApplicationListener<Hippo4jCoreDynamic
hippo4jBaseSendMessageService.putPlatform(newDynamicThreadPoolNotifyMap); hippo4jBaseSendMessageService.putPlatform(newDynamicThreadPoolNotifyMap);
} }
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(properties.getThreadPoolId()); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(properties.getThreadPoolId());
if (threadPoolNotifyAlarm != null && properties.getNotify() != null) { if (threadPoolNotifyAlarm != null) {
ThreadPoolNotifyAlarm notify = properties.getNotify(); boolean isAlarm = properties.getAlarm();
boolean isAlarm = notify.getAlarm(); Integer activeAlarm = properties.getActiveAlarm();
Integer activeAlarm = notify.getActiveAlarm(); Integer capacityAlarm = properties.getCapacityAlarm();
Integer capacityAlarm = notify.getCapacityAlarm();
if (threadPoolNotifyAlarm.getAlarm() != isAlarm if (threadPoolNotifyAlarm.getAlarm() != isAlarm
|| threadPoolNotifyAlarm.getActiveAlarm() != activeAlarm || threadPoolNotifyAlarm.getActiveAlarm() != activeAlarm
|| threadPoolNotifyAlarm.getCapacityAlarm() != capacityAlarm) { || threadPoolNotifyAlarm.getCapacityAlarm() != capacityAlarm) {

@ -34,10 +34,10 @@ import java.util.Map;
import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.PLATFORMS_LISTENER; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.PLATFORMS_LISTENER;
/** /**
* Platforms listener. * Platforms refresh listener.
*/ */
@Order(PLATFORMS_LISTENER) @Order(PLATFORMS_LISTENER)
public class PlatformsListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> { public class PlatformsRefreshListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
@Override @Override
public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {

@ -33,11 +33,11 @@ import java.util.Objects;
import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER;
/** /**
* Web executor listener. * Web executor refresh listener.
*/ */
@Slf4j @Slf4j
@Order(WEB_EXECUTOR_LISTENER) @Order(WEB_EXECUTOR_LISTENER)
public class WebExecutorListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> { public class WebExecutorRefreshListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
@Override @Override
public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {

@ -27,6 +27,7 @@ import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.*; import cn.hippo4j.core.executor.support.*;
import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; 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.ExecutorProperties;
import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
@ -137,13 +138,13 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
} }
} }
if (dynamicThreadPoolWrapper.getExecutor() instanceof AbstractDynamicExecutorSupport) { if (dynamicThreadPoolWrapper.getExecutor() instanceof AbstractDynamicExecutorSupport) {
ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
boolean isAlarm = Optional.ofNullable(notify) DynamicThreadPoolNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
.map(each -> each.getAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); boolean isAlarm = Optional.ofNullable(bootstrapCoreProperties.getAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true);
int activeAlarm = Optional.ofNullable(notify) int activeAlarm =
.map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80); Optional.ofNullable(bootstrapCoreProperties.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80);
int capacityAlarm = Optional.ofNullable(notify) int capacityAlarm = Optional.ofNullable(bootstrapCoreProperties.getCapacityAlarm())
.map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80); .orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80);
int interval = Optional.ofNullable(notify) int interval = Optional.ofNullable(notify)
.map(each -> each.getInterval()).orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5); .map(each -> each.getInterval()).orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5);
String receive = Optional.ofNullable(notify) String receive = Optional.ofNullable(notify)

Loading…
Cancel
Save