From 83d05bf21da701e924a18b3eed3717674e148744 Mon Sep 17 00:00:00 2001 From: shining-stars-lk <1031900093@qq.com> Date: Thu, 8 Sep 2022 14:24:59 +0800 Subject: [PATCH] Optimizing configuration logic --- .../DynamicThreadPoolAutoConfiguration.java | 5 ++- .../starter/adapter/web/EnableWebAdapter.java | 29 ----------------- .../web/WebAdapterConfigurationSelector.java | 31 ------------------- .../DynamicThreadPoolAutoConfiguration.java | 12 ++++--- 4 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/EnableWebAdapter.java delete mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfigurationSelector.java diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 18cb3163..5a055ad6 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -36,7 +36,7 @@ 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 cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration; import lombok.AllArgsConstructor; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -53,11 +53,10 @@ import org.springframework.core.annotation.Order; * Dynamic thread-pool core auto configuration. */ @Configuration -@EnableWebAdapter @AllArgsConstructor @ConditionalOnBean(MarkerConfiguration.Marker.class) @EnableConfigurationProperties(BootstrapConfigProperties.class) -@ImportAutoConfiguration({UtilAutoConfiguration.class, MessageConfiguration.class}) +@ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class}) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @Import({ ConfigHandlerConfiguration.EmbeddedNacos.class, ConfigHandlerConfiguration.EmbeddedNacosCloud.class, diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/EnableWebAdapter.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/EnableWebAdapter.java deleted file mode 100644 index b47cca8d..00000000 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/EnableWebAdapter.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.springboot.starter.adapter.web; - -import org.springframework.context.annotation.Import; - -import java.lang.annotation.*; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Import(WebAdapterConfigurationSelector.class) -public @interface EnableWebAdapter { -} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfigurationSelector.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfigurationSelector.java deleted file mode 100644 index 96871012..00000000 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfigurationSelector.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.springboot.starter.adapter.web; - -import org.springframework.context.annotation.DeferredImportSelector; -import org.springframework.core.annotation.Order; -import org.springframework.core.type.AnnotationMetadata; - -@Order -public class WebAdapterConfigurationSelector implements DeferredImportSelector { - - @Override - public String[] selectImports(AnnotationMetadata importingClassMetadata) { - return new String[]{WebAdapterConfiguration.class.getName()}; - } -} \ No newline at end of file diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index d7c18e45..df4bab57 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -35,11 +35,15 @@ 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 cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration; import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController; import cn.hippo4j.springboot.starter.controller.WebThreadPoolController; import cn.hippo4j.springboot.starter.controller.WebThreadPoolRunStateController; -import cn.hippo4j.springboot.starter.core.*; +import cn.hippo4j.springboot.starter.core.BaseThreadDetailStateHandler; +import cn.hippo4j.springboot.starter.core.ClientWorker; +import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig; +import cn.hippo4j.springboot.starter.core.ServerThreadPoolDynamicRefresh; +import cn.hippo4j.springboot.starter.core.ThreadPoolAdapterRegister; import cn.hippo4j.springboot.starter.event.ApplicationContentPostProcessor; import cn.hippo4j.springboot.starter.monitor.ReportingEventExecutor; import cn.hippo4j.springboot.starter.monitor.collect.RunTimeInfoCollector; @@ -67,12 +71,12 @@ import org.springframework.core.env.ConfigurableEnvironment; * Dynamic thread-pool auto-configuration. */ @Configuration -@EnableWebAdapter @AllArgsConstructor @ConditionalOnBean(MarkerConfiguration.Marker.class) @EnableConfigurationProperties(BootstrapProperties.class) @ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") -@ImportAutoConfiguration({HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class}) +@ImportAutoConfiguration({WebAdapterConfiguration.class, HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, + UtilAutoConfiguration.class}) public class DynamicThreadPoolAutoConfiguration { private final BootstrapProperties properties;