From 4366f9fad1b2881e63667fdc720d826b5fac774d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E7=A7=B0?= Date: Wed, 26 Oct 2022 09:55:26 +0800 Subject: [PATCH] Code optimization (#847) --- .../starter/config/BootstrapProperties.java | 6 ++-- .../config/DiscoveryConfiguration.java | 2 +- .../DynamicThreadPoolAutoConfiguration.java | 9 +++-- .../config/HttpClientConfiguration.java | 34 ------------------- .../springboot/starter/core/CacheData.java | 5 --- .../springboot/starter/core/ClientWorker.java | 2 -- .../springboot/starter/core/Listener.java | 4 +-- .../core/ThreadPoolSubscribeCallback.java | 2 +- .../starter/monitor/collect/Collector.java | 2 +- .../notify/ServerNotifyConfigBuilder.java | 1 - 10 files changed, 15 insertions(+), 52 deletions(-) delete mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/HttpClientConfiguration.java diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java index da16b335..d2d37461 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/BootstrapProperties.java @@ -35,17 +35,17 @@ public class BootstrapProperties implements BootstrapPropertiesInterface { public static final String PREFIX = "spring.dynamic.thread-pool"; /** - * Username. + * Username */ private String username; /** - * Password. + * Password */ private String password; /** - * Server addr + * Server address */ private String serverAddr; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DiscoveryConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DiscoveryConfiguration.java index 737ab8a0..0449b241 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DiscoveryConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DiscoveryConfiguration.java @@ -38,7 +38,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE; /** - * Dynamic threadPool discovery config. + * Dynamic thread-pool discovery config. */ @AllArgsConstructor public class DiscoveryConfiguration { 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 df4bab57..5d39572b 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 @@ -53,6 +53,7 @@ import cn.hippo4j.springboot.starter.notify.ServerNotifyConfigBuilder; import cn.hippo4j.springboot.starter.remote.HttpAgent; import cn.hippo4j.springboot.starter.remote.HttpScheduledHealthCheck; import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; +import cn.hippo4j.springboot.starter.remote.ServerHttpAgent; import cn.hippo4j.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor; import lombok.AllArgsConstructor; @@ -75,8 +76,7 @@ import org.springframework.core.env.ConfigurableEnvironment; @ConditionalOnBean(MarkerConfiguration.Marker.class) @EnableConfigurationProperties(BootstrapProperties.class) @ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") -@ImportAutoConfiguration({WebAdapterConfiguration.class, HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, - UtilAutoConfiguration.class}) +@ImportAutoConfiguration({WebAdapterConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class}) public class DynamicThreadPoolAutoConfiguration { private final BootstrapProperties properties; @@ -210,4 +210,9 @@ public class DynamicThreadPoolAutoConfiguration { public ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) { return new ThreadPoolNotifyAlarmHandler(hippo4jSendMessageService); } + + @Bean + public HttpAgent httpAgent(BootstrapProperties properties) { + return new ServerHttpAgent(properties); + } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/HttpClientConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/HttpClientConfiguration.java deleted file mode 100644 index eba69fe2..00000000 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/HttpClientConfiguration.java +++ /dev/null @@ -1,34 +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.config; - -import cn.hippo4j.springboot.starter.remote.HttpAgent; -import cn.hippo4j.springboot.starter.remote.ServerHttpAgent; -import org.springframework.context.annotation.Bean; - -/** - * Http client config. - */ -public class HttpClientConfiguration { - - @Bean - @SuppressWarnings("all") - public HttpAgent httpAgent(BootstrapProperties properties) { - return new ServerHttpAgent(properties); - } -} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java index c4d393b8..acd88ef2 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java @@ -45,14 +45,9 @@ public class CacheData { public final String threadPoolId; - @Setter - private int taskId; - @Setter private volatile boolean isInitializing = true; - private volatile long localConfigLastModified; - private final CopyOnWriteArrayList listeners; public CacheData(String tenantId, String itemId, String threadPoolId) { diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java index aa997763..0e30e6a2 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java @@ -245,8 +245,6 @@ public class ClientWorker { } catch (Exception ex) { log.error("Cache Data Error. Service Unavailable: {}", ex.getMessage()); } - int taskId = cacheMap.size() / CONFIG_LONG_POLL_TIMEOUT; - cacheData.setTaskId(taskId); lastCacheData = cacheData; } return lastCacheData; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/Listener.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/Listener.java index f1f8b880..36c7bb6e 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/Listener.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/Listener.java @@ -27,14 +27,14 @@ public interface Listener { /** * Get executor. * - * @return + * @return executor */ Executor getExecutor(); /** * Receive config info. * - * @param configInfo + * @param configInfo config info */ void receiveConfigInfo(String configInfo); } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolSubscribeCallback.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolSubscribeCallback.java index 121314e9..3bff89c4 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolSubscribeCallback.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolSubscribeCallback.java @@ -25,7 +25,7 @@ public interface ThreadPoolSubscribeCallback { /** * Callback. * - * @param config + * @param config config info */ void callback(String config); } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/Collector.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/Collector.java index 3fe5da50..b1e7f5c4 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/Collector.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/Collector.java @@ -27,7 +27,7 @@ public interface Collector { /** * Collect message. * - * @return + * @return message */ Message collectMessage(); } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java index 53ec96fb..8aeedb98 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java @@ -80,7 +80,6 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder { String resultDataStr = JSONUtil.toJSONString(result.getData()); List resultData = JSONUtil.parseArray(resultDataStr, ThreadPoolNotifyDTO.class); resultData.forEach(each -> resultMap.put(each.getNotifyKey(), each.getNotifyList())); - resultMap.forEach((key, val) -> val.stream().filter(each -> Objects.equals("ALARM", each.getType())) .forEach(each -> alarmControlHandler.initCacheAndLock(each.getTpId(), each.getPlatform(), each.getInterval()))); }