From 66406e81ce64cda9079a1997ba024a0534434402 Mon Sep 17 00:00:00 2001 From: lucky 8 <1031900093@qq.com> Date: Sat, 16 Jul 2022 13:00:35 +0800 Subject: [PATCH 1/7] Fixed Hystrix adaptation issues --- .../cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index 28b23e31..0b28b345 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -81,7 +81,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL @Override public List getThreadPoolStates() { List threadPoolAdapterStates = new ArrayList<>(); - HYSTRIX_CONSUME_EXECUTOR.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(String.valueOf(val)))); + HYSTRIX_CONSUME_EXECUTOR.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(kel))); return threadPoolAdapterStates; } From 0d47ad3a7e6df26c01157988ffa98e25025c0046 Mon Sep 17 00:00:00 2001 From: lucky 8 <1031900093@qq.com> Date: Sun, 17 Jul 2022 10:32:39 +0800 Subject: [PATCH 2/7] Add additional refresh registration tasks --- .../java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java | 7 +++++++ .../cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java | 5 +++++ .../hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java | 5 +++++ .../cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java | 5 +++++ .../adapter/rabbitmq/RabbitMQThreadPoolAdapter.java | 5 +++++ .../adapter/rocketmq/RocketMQThreadPoolAdapter.java | 5 +++++ .../kafka/SpringCloudStreamKafkaThreadPoolAdapter.java | 5 +++++ .../SpringCloudStreamRocketMQThreadPoolAdapter.java | 5 +++++ 8 files changed, 42 insertions(+) diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java index 20b39602..b6135d29 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java @@ -55,4 +55,11 @@ public interface ThreadPoolAdapter { * @return */ boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter); + + /** + * Additional refresh registration tasks + * + * @return + */ + void extraRefreshRegister(); } diff --git a/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java index 609b3607..6da0cdbf 100644 --- a/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java @@ -115,4 +115,9 @@ public class DubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis log.error("Failed to get Dubbo {}.X protocol thread pool", is2xVersion ? "2" : "3", ex); } } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index 0b28b345..93e434c0 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -163,4 +163,9 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL } } } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java index e27ced8a..249decb6 100644 --- a/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java @@ -49,4 +49,9 @@ public class KafkaThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis public void onApplicationEvent(ApplicationStartedEvent event) { } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java index 6595a0b4..dd0717cd 100644 --- a/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java @@ -114,4 +114,9 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application } } } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java index bb3517f1..c63e8cd3 100644 --- a/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java @@ -108,4 +108,9 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application } } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java index 4cc49356..ff659f62 100644 --- a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java @@ -56,4 +56,9 @@ public class SpringCloudStreamKafkaThreadPoolAdapter implements ThreadPoolAdapte public void onApplicationEvent(ApplicationStartedEvent event) { } + + @Override + public void extraRefreshRegister() { + + } } diff --git a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java index 14dc3db2..76fc74bd 100644 --- a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java @@ -122,4 +122,9 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda log.error("Failed to get input-bindings thread pool.", ex); } } + + @Override + public void extraRefreshRegister() { + + } } From 5a195cf6500263e4379475d2b4f11fb95f433971 Mon Sep 17 00:00:00 2001 From: lucky 8 <1031900093@qq.com> Date: Sun, 17 Jul 2022 10:37:33 +0800 Subject: [PATCH 3/7] Example Modify the hystrix scheduled task interval --- .../cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java index 3f81dbff..daa9db75 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java @@ -28,7 +28,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; @Slf4j public class ThreadPoolAdapterScheduler { - private static final int TASK_INTERVAL_SECONDS = 2; + private static final int TASK_INTERVAL_SECONDS = 10; private final ScheduledExecutorService scheduler; From 853714e5e2fd898cd361274bc6b68b0b2386114a Mon Sep 17 00:00:00 2001 From: lucky 8 <1031900093@qq.com> Date: Sun, 17 Jul 2022 12:03:08 +0800 Subject: [PATCH 4/7] Optimized adaptation --- .../adapter/base/ThreadPoolAdapter.java | 7 ----- .../base/ThreadPoolAdapterExtraHandle.java | 29 ------------------- .../adapter/dubbo/DubboThreadPoolAdapter.java | 5 ---- .../hystrix/HystrixThreadPoolAdapter.java | 5 ---- .../adapter/kafka/KafkaThreadPoolAdapter.java | 5 ---- .../rabbitmq/RabbitMQThreadPoolAdapter.java | 5 ---- .../rocketmq/RocketMQThreadPoolAdapter.java | 5 ---- ...ringCloudStreamKafkaThreadPoolAdapter.java | 5 ---- ...gCloudStreamRocketMQThreadPoolAdapter.java | 5 ---- 9 files changed, 71 deletions(-) delete mode 100644 hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java index b6135d29..20b39602 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java @@ -55,11 +55,4 @@ public interface ThreadPoolAdapter { * @return */ boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter); - - /** - * Additional refresh registration tasks - * - * @return - */ - void extraRefreshRegister(); } diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java deleted file mode 100644 index a6cde2e7..00000000 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.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.adapter.base; - -import java.util.Map; - -/** - * Thread Pool Adapter Extra Handle - **/ -@FunctionalInterface -public interface ThreadPoolAdapterExtraHandle { - - void execute(Map map); -} diff --git a/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java index 6da0cdbf..609b3607 100644 --- a/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java @@ -115,9 +115,4 @@ public class DubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis log.error("Failed to get Dubbo {}.X protocol thread pool", is2xVersion ? "2" : "3", ex); } } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index 93e434c0..0b28b345 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -163,9 +163,4 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL } } } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java index 249decb6..e27ced8a 100644 --- a/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java @@ -49,9 +49,4 @@ public class KafkaThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis public void onApplicationEvent(ApplicationStartedEvent event) { } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java index dd0717cd..6595a0b4 100644 --- a/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java @@ -114,9 +114,4 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application } } } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java index c63e8cd3..bb3517f1 100644 --- a/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java @@ -108,9 +108,4 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application } } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java index ff659f62..4cc49356 100644 --- a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-kafka/src/main/java/cn/hippo4j/adapter/springcloud/stream/kafka/SpringCloudStreamKafkaThreadPoolAdapter.java @@ -56,9 +56,4 @@ public class SpringCloudStreamKafkaThreadPoolAdapter implements ThreadPoolAdapte public void onApplicationEvent(ApplicationStartedEvent event) { } - - @Override - public void extraRefreshRegister() { - - } } diff --git a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java index 76fc74bd..14dc3db2 100644 --- a/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-spring-cloud-stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java @@ -122,9 +122,4 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda log.error("Failed to get input-bindings thread pool.", ex); } } - - @Override - public void extraRefreshRegister() { - - } } From 974991ac32b2ff24307adeecad5b56f1a140796a Mon Sep 17 00:00:00 2001 From: lucky 8 <1031900093@qq.com> Date: Sun, 17 Jul 2022 12:27:06 +0800 Subject: [PATCH 5/7] Optimization of adaptation --- .../base/ThreadPoolAdapterRegisterAction.java | 12 ++++++ .../hystrix/HystrixThreadPoolAdapter.java | 15 +++++-- .../core/ThreadPoolAdapterRegister.java | 39 +++++++++++-------- 3 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java new file mode 100644 index 00000000..0728e619 --- /dev/null +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java @@ -0,0 +1,12 @@ +package cn.hippo4j.adapter.base; + + +import java.util.Map; + +/** + * Provide registration for each adaptation + */ +public interface ThreadPoolAdapterRegisterAction { + + void adapterRegister(Map threadPoolAdapterMap); +} diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index 0b28b345..a4a422eb 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -17,10 +17,8 @@ package cn.hippo4j.adapter.hystrix; -import cn.hippo4j.adapter.base.ThreadPoolAdapter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; -import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.adapter.base.*; +import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.CollectionUtil; import com.google.common.collect.Maps; import com.netflix.hystrix.HystrixThreadPool; @@ -106,6 +104,15 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL @Override public void onApplicationEvent(ApplicationStartedEvent event) { + //Periodically update the Hystrix thread pool + HystrixThreadPoolRefresh(); + //Periodically refresh registration + ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction = ApplicationContextHolder.getBean(ThreadPoolAdapterRegisterAction.class); + Map map = (Map)ApplicationContextHolder.getBeansOfType(this.getClass()); + threadPoolAdapterRegisterAction.adapterRegister(map); + } + + public void HystrixThreadPoolRefresh(){ ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); HystrixThreadPoolRefreshTask hystrixThreadPoolRefreshTask = new HystrixThreadPoolRefreshTask(scheduler, taskIntervalSeconds); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java index 21798532..650fcfee 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java @@ -17,10 +17,7 @@ package cn.hippo4j.springboot.starter.core; -import cn.hippo4j.adapter.base.ThreadPoolAdapter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig; -import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.adapter.base.*; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.web.base.Result; @@ -52,7 +49,7 @@ import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_PATH; @Slf4j @AllArgsConstructor @RequiredArgsConstructor -public class ThreadPoolAdapterRegister implements ApplicationRunner { +public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolAdapterRegisterAction { private final HttpAgent httpAgent; @@ -64,19 +61,14 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { private final ThreadPoolAdapterScheduler threadPoolAdapterScheduler; - private List cacheConfigList = Lists.newArrayList(); + @Override public void run(ApplicationArguments args) throws Exception { - - ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); - int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); - ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds); - scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS); + register(); } - public List getThreadPoolAdapterCacheConfigs() { - Map threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class); + public List getThreadPoolAdapterCacheConfigs(Map threadPoolAdapterMap) { List cacheConfigList = Lists.newArrayList(); threadPoolAdapterMap.forEach((key, val) -> { List threadPoolStates = val.getThreadPoolStates(); @@ -110,25 +102,40 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { } public void register() { - List threadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs(); + Map threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class); + List threadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs(threadPoolAdapterMap); doRegister(threadPoolAdapterCacheConfigs); } + @Override + public void adapterRegister(Map threadPoolAdapterMap) { + ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); + int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); + ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds, threadPoolAdapterMap); + scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS); + } + class ThreadPoolAdapterRegisterTask implements Runnable { private ScheduledExecutorService scheduler; private int taskIntervalSeconds; - public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds) { + Map threadPoolAdapterMap; + + private List cacheConfigList = Lists.newArrayList(); + + public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds, + Map threadPoolAdapterMap) { this.scheduler = scheduler; this.taskIntervalSeconds = taskIntervalSeconds; + this.threadPoolAdapterMap = threadPoolAdapterMap; } @Override public void run() { try { - List newThreadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs(); + List newThreadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs(threadPoolAdapterMap); boolean registerFlag = compareThreadPoolAdapterCacheConfigs(newThreadPoolAdapterCacheConfigs, cacheConfigList); From a57945dd0de8005576dde0b6c3a502de85582eaf Mon Sep 17 00:00:00 2001 From: lukuan Date: Sun, 17 Jul 2022 12:41:33 +0800 Subject: [PATCH 6/7] add comment --- .../adapter/base/ThreadPoolAdapterRegisterAction.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java index 0728e619..5ca7bd7b 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java @@ -8,5 +8,10 @@ import java.util.Map; */ public interface ThreadPoolAdapterRegisterAction { + /** + * adapterRegister + * @param threadPoolAdapterMap + * @return + */ void adapterRegister(Map threadPoolAdapterMap); } From 2437723d3fc06946f52f236ff0f8305b3ce81a48 Mon Sep 17 00:00:00 2001 From: lukuan Date: Sun, 17 Jul 2022 13:45:46 +0800 Subject: [PATCH 7/7] Optimize the logic of the adaptation module --- .../base/ThreadPoolAdapterRegisterAction.java | 18 +++++++++++++++++- .../hystrix/HystrixThreadPoolAdapter.java | 9 +++++---- .../core/ThreadPoolAdapterRegister.java | 14 ++++++-------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java index 5ca7bd7b..c92123f6 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterRegisterAction.java @@ -1,5 +1,21 @@ -package cn.hippo4j.adapter.base; +/* + * 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.adapter.base; import java.util.Map; diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index a4a422eb..3b1a3eb7 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -104,15 +104,16 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL @Override public void onApplicationEvent(ApplicationStartedEvent event) { - //Periodically update the Hystrix thread pool + // Periodically update the Hystrix thread pool HystrixThreadPoolRefresh(); - //Periodically refresh registration + // Periodically refresh registration ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction = ApplicationContextHolder.getBean(ThreadPoolAdapterRegisterAction.class); - Map map = (Map)ApplicationContextHolder.getBeansOfType(this.getClass()); + Map beansOfType = ApplicationContextHolder.getBeansOfType(this.getClass()); + Map map = Maps.newHashMap(beansOfType); threadPoolAdapterRegisterAction.adapterRegister(map); } - public void HystrixThreadPoolRefresh(){ + public void HystrixThreadPoolRefresh() { ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); HystrixThreadPoolRefreshTask hystrixThreadPoolRefreshTask = new HystrixThreadPoolRefreshTask(scheduler, taskIntervalSeconds); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java index 650fcfee..cbe154ca 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java @@ -48,7 +48,6 @@ import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_PATH; */ @Slf4j @AllArgsConstructor -@RequiredArgsConstructor public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolAdapterRegisterAction { private final HttpAgent httpAgent; @@ -61,8 +60,6 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolA private final ThreadPoolAdapterScheduler threadPoolAdapterScheduler; - - @Override public void run(ApplicationArguments args) throws Exception { register(); @@ -70,10 +67,11 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolA public List getThreadPoolAdapterCacheConfigs(Map threadPoolAdapterMap) { List cacheConfigList = Lists.newArrayList(); - threadPoolAdapterMap.forEach((key, val) -> { + for (Map.Entry threadPoolAdapterEntry : threadPoolAdapterMap.entrySet()) { + ThreadPoolAdapter val = threadPoolAdapterEntry.getValue(); List threadPoolStates = val.getThreadPoolStates(); - if (CollectionUtil.isEmpty(threadPoolStates)) { - return; + if (CollectionUtil.isEmpty(threadPoolStates) || threadPoolStates.size() == 0) { + continue; } ThreadPoolAdapterCacheConfig cacheConfig = new ThreadPoolAdapterCacheConfig(); cacheConfig.setMark(val.mark()); @@ -84,12 +82,12 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolA cacheConfig.setClientAddress(clientAddress); cacheConfig.setThreadPoolAdapterStates(threadPoolStates); cacheConfigList.add(cacheConfig); - }); + } return cacheConfigList; } public void doRegister(List cacheConfigList) { - if (CollectionUtil.isNotEmpty(cacheConfigList)) { + if (CollectionUtil.isNotEmpty(cacheConfigList) && cacheConfigList.size() > 0) { try { Result result = httpAgent.httpPost(REGISTER_ADAPTER_PATH, cacheConfigList); if (!result.isSuccess()) {