Optimize hippo4j core monitoring change logic (#221)

pull/233/head
chen.ma 3 years ago
parent fe0c5895f5
commit 6f4ce12302

@ -34,15 +34,21 @@ import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor; import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecutor;
import cn.hippo4j.core.springboot.starter.monitor.LogMonitorHandler; import cn.hippo4j.core.springboot.starter.monitor.LogMonitorHandler;
import cn.hippo4j.core.springboot.starter.monitor.MetricMonitorHandler; import cn.hippo4j.core.springboot.starter.monitor.MetricMonitorHandler;
import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder;
import cn.hippo4j.core.springboot.starter.refresher.ApolloRefresherHandler; import cn.hippo4j.core.springboot.starter.refresher.ApolloRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosCloudRefresherHandler; import cn.hippo4j.core.springboot.starter.refresher.NacosCloudRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosRefresherHandler; import cn.hippo4j.core.springboot.starter.refresher.NacosRefresherHandler;
import cn.hippo4j.core.springboot.starter.support.DynamicThreadPoolPostProcessor;
import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder;
import cn.hippo4j.core.springboot.starter.refresher.ZookeeperRefresherHandler; import cn.hippo4j.core.springboot.starter.refresher.ZookeeperRefresherHandler;
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.support.DynamicThreadPoolPostProcessor;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.*; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -124,29 +130,29 @@ public class DynamicThreadPoolCoreAutoConfiguration {
@ConditionalOnClass(name = NACOS_CONFIG_KEY) @ConditionalOnClass(name = NACOS_CONFIG_KEY)
@ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY) @ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id") @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id")
public NacosRefresherHandler nacosRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) { public NacosRefresherHandler nacosRefresherHandler() {
return new NacosRefresherHandler(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); return new NacosRefresherHandler(bootstrapCoreProperties);
} }
@Bean @Bean
@ConditionalOnClass(name = NACOS_CONFIG_MANAGER_KEY) @ConditionalOnClass(name = NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id") @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id")
public NacosCloudRefresherHandler nacosCloudRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) { public NacosCloudRefresherHandler nacosCloudRefresherHandler() {
return new NacosCloudRefresherHandler(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); return new NacosCloudRefresherHandler(bootstrapCoreProperties);
} }
@Bean @Bean
@ConditionalOnClass(name = APOLLO_CONFIG_KEY) @ConditionalOnClass(name = APOLLO_CONFIG_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "apollo.namespace") @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "apollo.namespace")
public ApolloRefresherHandler apolloRefresher(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) { public ApolloRefresherHandler apolloRefresher() {
return new ApolloRefresherHandler(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); return new ApolloRefresherHandler(bootstrapCoreProperties);
} }
@Bean @Bean
@ConditionalOnClass(name = ZK_CONFIG_KEY) @ConditionalOnClass(name = ZK_CONFIG_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "zookeeper.zk-connect-str") @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "zookeeper.zk-connect-str")
public ZookeeperRefresherHandler zookeeperRefresher(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) { public ZookeeperRefresherHandler zookeeperRefresher() {
return new ZookeeperRefresherHandler(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); return new ZookeeperRefresherHandler(bootstrapCoreProperties);
} }
@Bean @Bean
@ -163,4 +169,19 @@ public class DynamicThreadPoolCoreAutoConfiguration {
public MetricMonitorHandler hippo4jMetricMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) { public MetricMonitorHandler hippo4jMetricMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) {
return new MetricMonitorHandler(threadPoolRunStateHandler); return new MetricMonitorHandler(threadPoolRunStateHandler);
} }
@Bean
public ExecutorsListener hippo4jExecutorsListener(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler) {
return new ExecutorsListener(threadPoolNotifyAlarmHandler);
}
@Bean
public PlatformsListener hippo4jPlatformsListener() {
return new PlatformsListener();
}
@Bean
public WebExecutorListener hippo4jWebExecutorListener() {
return new WebExecutorListener();
}
} }

@ -18,21 +18,17 @@
package cn.hippo4j.core.springboot.starter.refresher; package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.common.api.ThreadPoolDynamicRefresh; import cn.hippo4j.common.api.ThreadPoolDynamicRefresh;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.notify.ThreadPoolNotifyAlarm; import cn.hippo4j.common.notify.ThreadPoolNotifyAlarm;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import cn.hippo4j.core.springboot.starter.event.ThreadPoolDynamicRefreshEvent;
import cn.hippo4j.core.springboot.starter.parser.ConfigParserHandler; import cn.hippo4j.core.springboot.starter.parser.ConfigParserHandler;
import cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEvent;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -44,32 +40,23 @@ import java.util.concurrent.ExecutorService;
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh, InitializingBean, ApplicationContextAware { public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh, InitializingBean {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
protected final BootstrapCoreProperties bootstrapCoreProperties; protected final BootstrapCoreProperties bootstrapCoreProperties;
protected final ExecutorService dynamicRefreshExecutorService = ThreadPoolBuilder.builder().singlePool("client.dynamic.refresh").build(); protected final ExecutorService dynamicRefreshExecutorService = ThreadPoolBuilder.builder().singlePool("client.dynamic.refresh").build();
private ApplicationContext applicationContext;
@Override @Override
public void dynamicRefresh(String content) { public void dynamicRefresh(String content) {
Map<Object, Object> configInfo; Map<Object, Object> configInfo;
try { try {
configInfo = ConfigParserHandler.getInstance().parseConfig(content, bootstrapCoreProperties.getConfigFileType()); configInfo = ConfigParserHandler.getInstance().parseConfig(content, bootstrapCoreProperties.getConfigFileType());
} catch (IOException e) { } catch (Exception ex) {
log.error("dynamic-thread-pool parse config file error, content: {}, fileType: {}", log.error("dynamic-thread-pool parse config file error, content: {}, fileType: {}", content, bootstrapCoreProperties.getConfigFileType(), ex);
content, bootstrapCoreProperties.getConfigFileType(), e);
return; return;
} }
BootstrapCoreProperties bindableCoreProperties = BootstrapCorePropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapCoreProperties); BootstrapCoreProperties bindableCoreProperties = BootstrapCorePropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapCoreProperties);
// web pool ApplicationContextHolder.getInstance().publishEvent(new Hippo4jCoreDynamicRefreshEvent(this, bindableCoreProperties));
ThreadPoolDynamicRefreshEvent event = new ThreadPoolDynamicRefreshEvent(this);
event.setBootstrapCoreProperties(bindableCoreProperties);
applicationContext.publishEvent(event);
} }
/** /**
@ -86,11 +73,4 @@ public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPool
GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm);
}); });
} }
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
} }

@ -17,7 +17,6 @@
package cn.hippo4j.core.springboot.starter.refresher; package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener; import com.ctrip.framework.apollo.ConfigChangeListener;
@ -40,8 +39,8 @@ public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh
@Value(APOLLO_PROPERTY) @Value(APOLLO_PROPERTY)
private String namespace; private String namespace;
public ApolloRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, BootstrapCoreProperties bootstrapCoreProperties) { public ApolloRefresherHandler(BootstrapCoreProperties bootstrapCoreProperties) {
super(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); super(bootstrapCoreProperties);
} }
@Override @Override
@ -49,16 +48,13 @@ public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh
String[] apolloNamespaces = this.namespace.split(","); String[] apolloNamespaces = this.namespace.split(",");
this.namespace = apolloNamespaces[0]; this.namespace = apolloNamespaces[0];
Config config = ConfigService.getConfig(namespace); Config config = ConfigService.getConfig(namespace);
ConfigChangeListener configChangeListener = configChangeEvent -> { ConfigChangeListener configChangeListener = configChangeEvent -> {
ConfigFile configFile = ConfigService.getConfigFile( ConfigFile configFile = ConfigService.getConfigFile(
this.namespace.replaceAll("." + bootstrapCoreProperties.getConfigFileType().getValue(), ""), this.namespace.replaceAll("." + bootstrapCoreProperties.getConfigFileType().getValue(), ""),
ConfigFileFormat.fromString(bootstrapCoreProperties.getConfigFileType().getValue())); ConfigFileFormat.fromString(bootstrapCoreProperties.getConfigFileType().getValue()));
String configInfo = configFile.getContent(); String configInfo = configFile.getContent();
dynamicRefresh(configInfo); dynamicRefresh(configInfo);
}; };
config.addChangeListener(configChangeListener); config.addChangeListener(configChangeListener);
log.info("dynamic-thread-pool refresher, add apollo listener success, namespace: {}", namespace); log.info("dynamic-thread-pool refresher, add apollo listener success, namespace: {}", namespace);
} }

@ -18,7 +18,6 @@
package cn.hippo4j.core.springboot.starter.refresher; package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import com.alibaba.cloud.nacos.NacosConfigManager; import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.config.listener.Listener;
@ -38,16 +37,14 @@ public class NacosCloudRefresherHandler extends AbstractCoreThreadPoolDynamicRef
private final NacosConfigManager nacosConfigManager; private final NacosConfigManager nacosConfigManager;
public NacosCloudRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, public NacosCloudRefresherHandler(BootstrapCoreProperties bootstrapCoreProperties) {
BootstrapCoreProperties bootstrapCoreProperties) { super(bootstrapCoreProperties);
super(threadPoolNotifyAlarmHandler, bootstrapCoreProperties);
nacosConfigManager = ApplicationContextHolder.getBean(NacosConfigManager.class); nacosConfigManager = ApplicationContextHolder.getBean(NacosConfigManager.class);
} }
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos(); Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos();
nacosConfigManager.getConfigService().addListener(nacosConfig.get("data-id"), nacosConfigManager.getConfigService().addListener(nacosConfig.get("data-id"),
nacosConfig.get("group"), new Listener() { nacosConfig.get("group"), new Listener() {

@ -18,7 +18,6 @@
package cn.hippo4j.core.springboot.starter.refresher; package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.config.listener.Listener;
@ -38,9 +37,8 @@ public class NacosRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh
private final ConfigService configService; private final ConfigService configService;
public NacosRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, public NacosRefresherHandler(BootstrapCoreProperties bootstrapCoreProperties) {
BootstrapCoreProperties bootstrapCoreProperties) { super(bootstrapCoreProperties);
super(threadPoolNotifyAlarmHandler, bootstrapCoreProperties);
configService = ApplicationContextHolder.getBean(ConfigService.class); configService = ApplicationContextHolder.getBean(ConfigService.class);
} }

@ -17,7 +17,6 @@
package cn.hippo4j.core.springboot.starter.refresher; package cn.hippo4j.core.springboot.starter.refresher;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -44,8 +43,8 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
private CuratorFramework curatorFramework; private CuratorFramework curatorFramework;
public ZookeeperRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, BootstrapCoreProperties bootstrapCoreProperties) { public ZookeeperRefresherHandler(BootstrapCoreProperties bootstrapCoreProperties) {
super(threadPoolNotifyAlarmHandler, bootstrapCoreProperties); super(bootstrapCoreProperties);
} }
@Override @Override
@ -62,7 +61,6 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
loadNode(nodePath); loadNode(nodePath);
} }
}; };
final CuratorListener curatorListener = (client, curatorEvent) -> { final CuratorListener curatorListener = (client, curatorEvent) -> {
final WatchedEvent watchedEvent = curatorEvent.getWatchedEvent(); final WatchedEvent watchedEvent = curatorEvent.getWatchedEvent();
if (null != watchedEvent) { if (null != watchedEvent) {
@ -76,7 +74,6 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
} }
} }
}; };
curatorFramework.getConnectionStateListenable().addListener(connectionStateListener); curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
curatorFramework.getCuratorListenable().addListener(curatorListener); curatorFramework.getCuratorListenable().addListener(curatorListener);
curatorFramework.start(); curatorFramework.start();
@ -102,10 +99,8 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
content.append(nodeName).append("=").append(value).append("\n"); content.append(nodeName).append("=").append(value).append("\n");
}); });
dynamicRefresh(content.toString()); dynamicRefresh(content.toString());
registerNotifyAlarmManage(); registerNotifyAlarmManage();
} catch (Exception e) { } catch (Exception e) {

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.springboot.starter.event; package cn.hippo4j.core.springboot.starter.refresher.event;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest; import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
@ -33,7 +33,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -44,23 +43,20 @@ import java.util.concurrent.atomic.AtomicLong;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD_POOL_TEXT; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD_POOL_TEXT;
import static cn.hippo4j.core.springboot.starter.event.ThreadPoolDynamicRefreshEventOrder.EXECUTORS_LISTENER; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.EXECUTORS_LISTENER;
/** /**
* @author : wh * Executors listener.
* @date : 2022/5/13 10:06
* @description:
*/ */
@Slf4j @Slf4j
@Component
@RequiredArgsConstructor @RequiredArgsConstructor
@Order(EXECUTORS_LISTENER) @Order(EXECUTORS_LISTENER)
public class ExecutorsListener implements ApplicationListener<ThreadPoolDynamicRefreshEvent> { public class ExecutorsListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler; private final ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler;
@Override @Override
public void onApplicationEvent(ThreadPoolDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties(); BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties();
List<ExecutorProperties> executors = bindableCoreProperties.getExecutors(); List<ExecutorProperties> executors = bindableCoreProperties.getExecutors();
for (ExecutorProperties properties : executors) { for (ExecutorProperties properties : executors) {
@ -90,7 +86,6 @@ public class ExecutorsListener implements ApplicationListener<ThreadPoolDynamicR
log.error("Failed to send changSmartApplicationListenere notice. Message :: {}", ex.getMessage()); log.error("Failed to send changSmartApplicationListenere notice. Message :: {}", ex.getMessage());
} }
} }
} }
/** /**
@ -198,5 +193,4 @@ public class ExecutorsListener implements ApplicationListener<ThreadPoolDynamicR
} }
} }
} }
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.springboot.starter.event; package cn.hippo4j.core.springboot.starter.refresher.event;
import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties;
import lombok.Getter; import lombok.Getter;
@ -23,17 +23,16 @@ import lombok.Setter;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
/** /**
* @author : wh * Hippo4j core dynamic refresh event.
* @date : 2022/5/13 09:49
* @description:
*/ */
public class ThreadPoolDynamicRefreshEvent extends ApplicationEvent { public class Hippo4jCoreDynamicRefreshEvent extends ApplicationEvent {
@Getter @Getter
@Setter @Setter
private BootstrapCoreProperties bootstrapCoreProperties; private BootstrapCoreProperties bootstrapCoreProperties;
public ThreadPoolDynamicRefreshEvent(Object source) { public Hippo4jCoreDynamicRefreshEvent(Object source, BootstrapCoreProperties bootstrapCoreProperties) {
super(source); super(source);
this.bootstrapCoreProperties = bootstrapCoreProperties;
} }
} }

@ -15,19 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.springboot.starter.event; package cn.hippo4j.core.springboot.starter.refresher.event;
/** /**
* @author : wh * Hippo4j core dynamic refresh event order.
* @date : 2022/5/13 10:25
* @description:
*/ */
public interface ThreadPoolDynamicRefreshEventOrder { public interface Hippo4jCoreDynamicRefreshEventOrder {
Integer WEB_EXECUTOR_LISTENER = 0; int WEB_EXECUTOR_LISTENER = 0;
Integer PLATFORMS_LISTENER = 1; int PLATFORMS_LISTENER = 1;
Integer EXECUTORS_LISTENER = 2;
int EXECUTORS_LISTENER = 2;
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.springboot.starter.event; package cn.hippo4j.core.springboot.starter.refresher.event;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.notify.HippoBaseSendMessageService; import cn.hippo4j.common.notify.HippoBaseSendMessageService;
@ -27,25 +27,20 @@ import cn.hippo4j.core.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder; import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.hippo4j.core.springboot.starter.event.ThreadPoolDynamicRefreshEventOrder.PLATFORMS_LISTENER; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.PLATFORMS_LISTENER;
/** /**
* @author : wh * Platforms listener.
* @date : 2022/5/13 10:03
* @description:
*/ */
@Component
@Order(PLATFORMS_LISTENER) @Order(PLATFORMS_LISTENER)
public class PlatformsListener implements ApplicationListener<ThreadPoolDynamicRefreshEvent> { public class PlatformsListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
@Override @Override
public void onApplicationEvent(ThreadPoolDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties(); BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties();
List<ExecutorProperties> executors = bindableCoreProperties.getExecutors(); List<ExecutorProperties> executors = bindableCoreProperties.getExecutors();
for (ExecutorProperties executor : executors) { for (ExecutorProperties executor : executors) {
@ -59,6 +54,5 @@ public class PlatformsListener implements ApplicationListener<ThreadPoolDynamicR
wrapper.setInitFlag(Boolean.TRUE); wrapper.setInitFlag(Boolean.TRUE);
} }
} }
} }
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.springboot.starter.event; package cn.hippo4j.core.springboot.starter.refresher.event;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.model.ThreadPoolParameter; import cn.hippo4j.common.model.ThreadPoolParameter;
@ -27,29 +27,24 @@ import cn.hippo4j.core.springboot.starter.config.WebThreadPoolProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.Objects; import java.util.Objects;
import static cn.hippo4j.core.springboot.starter.event.ThreadPoolDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER; import static cn.hippo4j.core.springboot.starter.refresher.event.Hippo4jCoreDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER;
/** /**
* @author : wh * Web executor listener.
* @date : 2022/5/13 09:53
* @description:
*/ */
@Slf4j @Slf4j
@Component
@Order(WEB_EXECUTOR_LISTENER) @Order(WEB_EXECUTOR_LISTENER)
public class WebExecutorListener implements ApplicationListener<ThreadPoolDynamicRefreshEvent> { public class WebExecutorListener implements ApplicationListener<Hippo4jCoreDynamicRefreshEvent> {
@Override @Override
public void onApplicationEvent(ThreadPoolDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(Hippo4jCoreDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties(); BootstrapCoreProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapCoreProperties();
boolean isNullFlag = bindableCoreProperties.getJetty() == null boolean isNullFlag = bindableCoreProperties.getJetty() == null
|| bindableCoreProperties.getUndertow() == null && bindableCoreProperties.getUndertow() == null
|| bindableCoreProperties.getTomcat() == null; && bindableCoreProperties.getTomcat() == null;
if (isNullFlag) { if (isNullFlag) {
return; return;
} }
Loading…
Cancel
Save