Merge branch 'opengoofy:develop' into develop

pull/659/head
lucky 8 3 years ago committed by GitHub
commit b26ceeaa05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,7 +32,7 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
- 通知报警 - 内置四种报警通知策略,线程池活跃度、容量水位、拒绝策略以及任务执行时间超长;
- 运行监控 - 实时查看线程池运行时数据,最近半小时线程池运行数据图表展示;
- 功能扩展 - 支持线程池任务传递上下文;项目关闭时,支持等待线程池在指定时间内完成任务;
- 多种模式 - 内置两种使用模式:[依赖配置中心](https://hippo4j.cn/docs/user_docs/getting-started/config/hippo4j-core-start) 和 [无中间件依赖](https://hippo4j.cn/docs/user_docs/getting-started/server/hippo4j-server-start)
- 多种模式 - 内置两种使用模式:[依赖配置中心](https://hippo4j.cn/docs/user_docs/getting_started/config/hippo4j-config-start) 和 [无中间件依赖](https://hippo4j.cn/docs/user_docs/getting_started/server/hippo4j-server-start)
- 容器管理 - Tomcat、Jetty、Undertow 容器线程池运行时查看和线程数变更;
- 中间件适配 - Apache RocketMQ、Dubbo、RabbitMQ、Hystrix 消费线程池运行时数据查看和线程数变更。
@ -40,7 +40,7 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
## 快速开始
对于本地演示目的,请参阅 [Quick start](https://hippo4j.cn/docs/user_docs/getting-started/hippo4j-server-start)
对于本地演示目的,请参阅 [Quick start](https://hippo4j.cn/docs/user_docs/user_guide/quick-start)
演示环境:
- http://console.hippo4j.cn/index.html

@ -51,15 +51,20 @@ public abstract class AbstractWebThreadPoolService implements WebThreadPoolServi
if (executor == null) {
synchronized (AbstractWebThreadPoolService.class) {
if (executor == null) {
ApplicationContext applicationContext = ApplicationContextHolder.getInstance();
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
executor = getWebThreadPoolByServer(webServer);
executor = getWebThreadPoolByServer(getWebServer());
}
}
}
return executor;
}
@Override
public WebServer getWebServer() {
ApplicationContext applicationContext = ApplicationContextHolder.getInstance();
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
return webServer;
}
@Override
public void run(ApplicationArguments args) {
try {

@ -21,6 +21,7 @@ import cn.hippo4j.common.model.ThreadPoolBaseInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import org.springframework.boot.web.server.WebServer;
import java.util.concurrent.Executor;
@ -63,4 +64,13 @@ public interface WebThreadPoolService {
* @param threadPoolParameterInfo
*/
void updateWebThreadPool(ThreadPoolParameterInfo threadPoolParameterInfo);
/**
* Get web server.
*
* @return
*/
default WebServer getWebServer() {
return null;
}
}

@ -23,5 +23,8 @@ package cn.hippo4j.common.function;
@FunctionalInterface
public interface Matcher<T> {
/**
* Returns {@code true} if this matches {@code t}, {@code false} otherwise.
*/
boolean match(T t);
}

@ -23,5 +23,8 @@ package cn.hippo4j.common.function;
@FunctionalInterface
public interface NoArgsConsumer {
/**
* Execute operation without parameters.
*/
void accept();
}

@ -17,22 +17,35 @@
package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import org.junit.Test;
public class ContentUtilTest {
@Test
public void assertGetPoolContent() {
String testText = "{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":" +
"\"message-consume\",\"queueType\":1,\"capacity\":4,\"keepAliveTime\":513,\"rejectedType\":4,\"isAlarm\"" +
":1,\"capacityAlarm\":80,\"livenessAlarm\":80,\"allowCoreThreadTimeOut\":1}";
ThreadPoolParameterInfo threadPoolParameterInfo = ThreadPoolParameterInfo.builder().tenantId("prescription")
.itemId("dynamic-threadpool-example").tpId("message-consume").content("描述信息").corePoolSize(1)
.maximumPoolSize(2).queueType(1).capacity(4).keepAliveTime(513).executeTimeOut(null).rejectedType(4)
.isAlarm(1).capacityAlarm(80).livenessAlarm(80).allowCoreThreadTimeOut(1).build();
Assert.isTrue(testText.equals(ContentUtil.getPoolContent(threadPoolParameterInfo)));
}
@Test
public void assertGetGroupKey() {
String testText = "message-consume+dynamic-threadpool-example+prescription";
ThreadPoolParameterInfo parameter = ThreadPoolParameterInfo.builder()
.tenantId("prescription").itemId("dynamic-threadpool-example").tpId("message-consume").build();
Assert.isTrue(testText.equals(ContentUtil.getGroupKey(parameter)));
}
@Test
public void assertGetGroupKeys() {
String testText = "message-consume+dynamic-threadpool-example+prescription";
String groupKey = ContentUtil.getGroupKey("message-consume", "dynamic-threadpool-example", "prescription");
Assert.isTrue(testText.equals(groupKey));
}
}
}

@ -17,5 +17,77 @@
package cn.hippo4j.common.toolkit;
import org.junit.Test;
import java.util.Objects;
public class StringUtilTest {
@Test
public void assertIsEmpty() {
String string = "";
Assert.isTrue(StringUtil.isEmpty(string));
}
@Test
public void assertIsNotEmpty() {
String string = "string";
Assert.isTrue(StringUtil.isNotEmpty(string));
}
@Test
public void emptyToNull() {
String string = "";
Assert.isNull(StringUtil.emptyToNull(string));
}
@Test
public void nullToEmpty() {
String string = "null";
Assert.notEmpty(StringUtil.nullToEmpty(string));
}
@Test
public void isNullOrEmpty() {
String string = "null";
Assert.isTrue(!StringUtil.isNullOrEmpty(string));
}
@Test
public void isBlank() {
String string = "";
Assert.isTrue(StringUtil.isBlank(string));
}
@Test
public void isNotBlank() {
String string = "null";
Assert.isTrue(StringUtil.isNotBlank(string));
}
@Test
public void isAllNotEmpty() {
String strings = "str";
Assert.isTrue(StringUtil.isAllNotEmpty(strings));
}
@Test
public void hasEmpty() {
String strings = "";
Assert.isTrue(StringUtil.hasEmpty(strings));
}
@Test
public void toUnderlineCase() {
String string = "str";
String s = StringUtil.toUnderlineCase(string);
Assert.isTrue(Objects.equals(s, "str"));
}
@Test
public void toSymbolCase() {
String string = "str";
String s = StringUtil.toSymbolCase(string, StringUtil.UNDERLINE);
Assert.isTrue(Objects.equals(s, "str"));
}
}

@ -57,7 +57,7 @@ public class ThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
ByteConvertUtil.getPrintSize(runtimeInfo.getMaxMemory())).toString();
poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%");
poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%");
String ipAddress = hippo4JInetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
String ipAddress = hippo4JInetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
poolRunStateInfo.setHost(ipAddress);
poolRunStateInfo.setMemoryProportion(memoryProportion);
poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory()));

@ -51,7 +51,7 @@ public class IdentifyUtil {
if (StrUtil.isNotBlank(IDENTIFY)) {
return IDENTIFY;
}
String ip = hippo4JInetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
String ip = hippo4JInetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
String port = environment.getProperty("server.port", "8080");
String identification = StrUtil.builder(ip,
":",

@ -58,7 +58,7 @@ public class InetUtils implements Closeable {
this.executorService.shutdown();
}
public HostInfo findFirstNonLoopbackHostInfo() {
public HostInfo findFirstNonLoopBackHostInfo() {
InetAddress address = findFirstNonLoopbackAddress();
if (address != null) {
return convertAddress(address);

@ -14,11 +14,6 @@
</properties>
<dependencies>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>

@ -44,4 +44,9 @@ public class AdapterExecutorProperties {
* Maximum pool size
*/
private Integer maximumPoolSize;
/**
* Nodes, application startup is not affect, change properties is effect
*/
private String nodes;
}

@ -20,9 +20,6 @@ package cn.hippo4j.config.springboot.starter.config;
import java.util.List;
import java.util.Map;
import java.util.List;
import java.util.Map;
import cn.hippo4j.core.config.BootstrapPropertiesInterface;
import cn.hippo4j.config.springboot.starter.parser.ConfigFileTypeEnum;
import lombok.Getter;

@ -17,11 +17,7 @@
package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.config.springboot.starter.refresher.ApolloRefresherHandler;
import cn.hippo4j.config.springboot.starter.refresher.NacosCloudRefresherHandler;
import cn.hippo4j.config.springboot.starter.refresher.NacosRefresherHandler;
import cn.hippo4j.config.springboot.starter.refresher.ZookeeperRefresherHandler;
import cn.hippo4j.config.springboot.starter.refresher.EtcdRefresherHandler;
import cn.hippo4j.config.springboot.starter.refresher.*;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import io.etcd.jetcd.Client;

@ -36,8 +36,8 @@ import cn.hippo4j.message.config.MessageConfiguration;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.Hippo4jSendMessageService;
import cn.hippo4j.springboot.starter.adapter.web.EnableWebAdapter;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -53,6 +53,7 @@ import org.springframework.core.annotation.Order;
* Dynamic thread-pool core auto configuration.
*/
@Configuration
@EnableWebAdapter
@AllArgsConstructor
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@EnableConfigurationProperties(BootstrapConfigProperties.class)

@ -102,4 +102,9 @@ public class ExecutorProperties {
* Notify
*/
private DynamicThreadPoolNotifyProperties notify;
/**
* Nodes, application startup is not affect, change properties is effect
*/
private String nodes;
}

@ -39,4 +39,9 @@ public class WebThreadPoolProperties {
* Keep alive time
*/
private Integer keepAliveTime;
/**
* Nodes, application startup is not affect, change properties is effect
*/
private String nodes;
}

@ -37,13 +37,13 @@ import java.util.concurrent.ExecutorService;
*/
@Slf4j
@RequiredArgsConstructor
public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh, InitializingBean {
public abstract class AbstractConfigThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh, InitializingBean {
protected final BootstrapConfigProperties bootstrapConfigProperties;
protected final ExecutorService dynamicRefreshExecutorService = ThreadPoolBuilder.builder().singlePool("client.dynamic.refresh").build();
public AbstractCoreThreadPoolDynamicRefresh() {
public AbstractConfigThreadPoolDynamicRefresh() {
bootstrapConfigProperties = ApplicationContextHolder.getBean(BootstrapConfigProperties.class);
}
@ -59,7 +59,7 @@ public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPool
if (CollectionUtil.isNotEmpty(newValueChangeMap)) {
Optional.ofNullable(configInfo).ifPresent(each -> each.putAll(newValueChangeMap));
}
BootstrapConfigProperties bindableCoreProperties = BootstrapCorePropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties);
BootstrapConfigProperties bindableCoreProperties = BootstrapConfigPropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties);
ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, bindableCoreProperties));
} catch (Exception ex) {
log.error("Hippo-4J core dynamic refresh failed.", ex);

@ -34,7 +34,7 @@ import java.util.Map;
* Apollo refresher handler.
*/
@Slf4j
public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
public class ApolloRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
private static final String APOLLO_PROPERTY = "${spring.dynamic.thread-pool.apollo.namespace:application}";

@ -38,7 +38,7 @@ import java.util.Map;
/**
* Bootstrap core properties binder adapt.
*/
public class BootstrapCorePropertiesBinderAdapt {
public class BootstrapConfigPropertiesBinderAdapt {
/**
* Bootstrap core properties binder.

@ -36,7 +36,7 @@ import java.util.Objects;
* @description:
*/
@Slf4j
public class EtcdRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
private Client client;

@ -29,7 +29,7 @@ import java.util.concurrent.Executor;
* Nacos cloud refresher handler.
*/
@Slf4j
public class NacosCloudRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
private final NacosConfigManager nacosConfigManager;

@ -30,7 +30,7 @@ import java.util.concurrent.Executor;
* Nacos refresher handler.
*/
@Slf4j
public class NacosRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
@NacosInjected
private ConfigService configService;

@ -39,7 +39,7 @@ import java.util.Map;
* Zookeeper refresher handler.
*/
@Slf4j
public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
private CuratorFramework curatorFramework;

@ -0,0 +1,181 @@
/*
* 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.config.springboot.starter.refresher.event;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.event.EventListener;
import java.util.Arrays;
import java.util.Objects;
/**
* Refresh listener abstract base class.
*/
@Slf4j
public abstract class AbstractRefreshListener<M> implements RefreshListener<Hippo4jConfigDynamicRefreshEvent, M> {
protected static final String ALL = "*";
protected static final String SPOT = "\\.";
protected static final String SEPARATOR = ",";
protected static final String COLON = ":";
/**
* application ip
*/
protected final String[] ipSegment;
/**
* application post
*/
protected String port;
AbstractRefreshListener() {
InetUtils inetUtils = ApplicationContextHolder.getBean(InetUtils.class);
InetUtils.HostInfo loopBackHostInfo = inetUtils.findFirstNonLoopBackHostInfo();
Assert.notNull(loopBackHostInfo, "Unable to get the application IP address");
ipSegment = loopBackHostInfo.getIpAddress().split(SPOT);
}
@EventListener(WebServerInitializedEvent.class)
public void webServerInitializedListener(WebServerInitializedEvent event) {
port = String.valueOf(event.getWebServer().getPort());
}
/**
* Matching nodes<br>
* nodes is ip + port.Get 'nodes' in the new Properties,Compare this with the ip + port of Application.<br>
* support prefix pattern matching. e.g: <br>
* <ul>
* <li>192.168.1.5:* -- Matches all ports of 192.168.1.5</li>
* <li>192.168.1.*:2009 -- Matches 2009 port of 192.168.1.*</li>
* <li>* -- all</li>
* <li>empty -- all</li>
* </ul>
* The format of ip + port is ip : port.
*
* @param properties new Properties
*/
@Override
public boolean match(M properties) {
String nodes = getNodes(properties);
if (StringUtil.isEmpty(nodes) || ALL.equals(nodes)) {
return true;
}
String[] splitNodes = nodes.split(SEPARATOR);
return Arrays.stream(splitNodes)
.distinct()
.map(IpAndPort::build)
.filter(Objects::nonNull)
.anyMatch(i -> i.check(ipSegment, port));
}
/**
* get nodes in new properties
*
* @param properties new properties
* @return nodes in properties
*/
protected String getNodes(M properties) {
return ALL;
}
/**
* ip + port
*/
@Data
protected static class IpAndPort {
private String ip;
private String port;
private String[] propIpSegment;
private IpAndPort(String ip, String port) {
this.ip = ip;
this.port = port;
this.propIpSegment = ip.split(SPOT);
}
public static IpAndPort build(String node) {
if (ALL.equals(node)) {
return new IpAndPort(ALL, ALL);
}
String[] ipPort = node.split(COLON);
if (ipPort.length != 2) {
log.error("The IP address format is error : {}", node);
return null;
}
return new IpAndPort(ipPort[0], ipPort[1]);
}
/**
* check
*
* @param appIpSegment application ip segment
* @param port application port
*/
public boolean check(String[] appIpSegment, String port) {
return checkPort(port) && checkIp(appIpSegment);
}
/**
* check ip
*
* @param appIpSegment application ip segment
*/
protected boolean checkIp(String[] appIpSegment) {
if (ALL.equals(this.ip)) {
return true;
}
boolean flag = true;
for (int i = 0; i < propIpSegment.length && flag; i++) {
String propIp = propIpSegment[i];
String appIp = appIpSegment[i];
flag = contrastSegment(appIp, propIp);
}
return flag;
}
/**
* check port
*
* @param port application port
*/
protected boolean checkPort(String port) {
return contrastSegment(port, this.port);
}
/**
* Check whether the strings are the same
*
* @param appIp appIp
* @param propIp propIp
*/
protected boolean contrastSegment(String appIp, String propIp) {
return ALL.equals(propIp) || appIp.equals(propIp);
}
}
}

@ -25,7 +25,6 @@ import cn.hippo4j.config.springboot.starter.config.AdapterExecutorProperties;
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolAdapterRegister;
import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import java.util.List;
@ -40,7 +39,12 @@ import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfig
*/
@Slf4j
@Order(ADAPTER_EXECUTORS_LISTENER)
public class AdapterExecutorsRefreshListener implements ApplicationListener<Hippo4jConfigDynamicRefreshEvent> {
public class AdapterExecutorsRefreshListener extends AbstractRefreshListener<AdapterExecutorProperties> {
@Override
public String getNodes(AdapterExecutorProperties properties) {
return properties.getNodes();
}
@Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent event) {
@ -52,11 +56,11 @@ public class AdapterExecutorsRefreshListener implements ApplicationListener<Hipp
for (AdapterExecutorProperties each : adapterExecutors) {
String buildKey = each.getMark() + IDENTIFY_SLICER_SYMBOL + each.getThreadPoolKey();
AdapterExecutorProperties adapterExecutorProperties = DynamicThreadPoolAdapterRegister.ADAPTER_EXECUTORS_MAP.get(buildKey);
if (adapterExecutorProperties == null) {
if (adapterExecutorProperties == null || !match(adapterExecutorProperties)) {
continue;
}
if (!Objects.equals(adapterExecutorProperties.getCorePoolSize(), each.getCorePoolSize())
|| !Objects.equals(adapterExecutorProperties.getMaximumPoolSize(), each.getMaximumPoolSize())) {
|| !Objects.equals(adapterExecutorProperties.getMaximumPoolSize(), each.getMaximumPoolSize())) {
threadPoolAdapterMap.forEach((key, val) -> {
if (Objects.equals(val.mark(), each.getMark())) {
val.updateThreadPool(BeanUtil.toBean(each, ThreadPoolAdapterParameter.class));

@ -21,6 +21,7 @@ import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.config.AdapterExecutorProperties;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.config.springboot.starter.notify.CoreNotifyConfigBuilder;
@ -38,7 +39,6 @@ import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import java.util.List;
@ -60,7 +60,7 @@ import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfig
@Slf4j
@RequiredArgsConstructor
@Order(EXECUTORS_LISTENER)
public class DynamicThreadPoolRefreshListener implements ApplicationListener<Hippo4jConfigDynamicRefreshEvent> {
public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<ExecutorProperties> {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
@ -68,13 +68,21 @@ public class DynamicThreadPoolRefreshListener implements ApplicationListener<Hip
private final Hippo4jBaseSendMessageService hippo4jBaseSendMessageService;
@Override
public String getNodes(ExecutorProperties properties) {
return properties.getNodes();
}
@Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent event) {
BootstrapConfigProperties bindableConfigProperties = event.getBootstrapConfigProperties();
List<ExecutorProperties> executors = bindableConfigProperties.getExecutors();
for (ExecutorProperties properties : executors) {
String threadPoolId = properties.getThreadPoolId();
/**
if (!match(properties)) {
continue;
}
/*
* Check whether the notification configuration is consistent, this operation will not trigger the notification.
*/
checkNotifyConsistencyAndReplace(properties);

@ -25,7 +25,6 @@ import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import java.util.List;
@ -37,7 +36,7 @@ import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfig
* Platforms refresh listener.
*/
@Order(PLATFORMS_LISTENER)
public class PlatformsRefreshListener implements ApplicationListener<Hippo4jConfigDynamicRefreshEvent> {
public class PlatformsRefreshListener extends AbstractRefreshListener<ExecutorProperties> {
@Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) {

@ -0,0 +1,31 @@
/*
* 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.config.springboot.starter.refresher.event;
import cn.hippo4j.common.function.Matcher;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
/**
* Refresh listener interface.
* Tevent.
* Mproperties.
*/
public interface RefreshListener<T extends ApplicationEvent, M> extends ApplicationListener<T>, Matcher<M> {
}

@ -25,7 +25,6 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.WebThreadPoolProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import java.util.Objects;
@ -37,7 +36,12 @@ import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfig
*/
@Slf4j
@Order(WEB_EXECUTOR_LISTENER)
public class WebExecutorRefreshListener implements ApplicationListener<Hippo4jConfigDynamicRefreshEvent> {
public class WebExecutorRefreshListener extends AbstractRefreshListener<WebThreadPoolProperties> {
@Override
public String getNodes(WebThreadPoolProperties properties) {
return properties.getNodes();
}
@Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
@ -75,7 +79,7 @@ public class WebExecutorRefreshListener implements ApplicationListener<Hippo4jCo
} else if (bindableCoreProperties.getJetty() != null) {
webThreadPoolProperties = bindableCoreProperties.getJetty();
}
if (webThreadPoolProperties != null) {
if (webThreadPoolProperties != null && match(webThreadPoolProperties)) {
threadPoolParameterInfo = ThreadPoolParameterInfo.builder()
.coreSize(webThreadPoolProperties.getCorePoolSize())
.maximumPoolSize(webThreadPoolProperties.getMaximumPoolSize())

@ -29,7 +29,7 @@ public class CloudCommonIdUtil {
private static final String SEPARATOR = ":";
public static String getClientIpPort(PropertyResolver resolver, InetUtils inetUtils) {
String hostname = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
String hostname = inetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
String port = resolver.getProperty("server.port", "8080");
return combineParts(hostname, SEPARATOR, port);
}
@ -43,7 +43,7 @@ public class CloudCommonIdUtil {
@SneakyThrows
public static String getIpApplicationName(PropertyResolver resolver, InetUtils inetUtils) {
String hostname = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
String hostname = inetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
String appName = resolver.getProperty("spring.application.name");
return combineParts(hostname, SEPARATOR, appName);
}

Loading…
Cancel
Save