From 1f9f0dce03bbab1da0c5feffcb89b3d11901c090 Mon Sep 17 00:00:00 2001 From: weihu Date: Sun, 2 Oct 2022 14:58:51 +0800 Subject: [PATCH] format code --- .../common/function/MatcherFunctionTest.java | 2 +- .../config/ConfigHandlerConfiguration.java | 149 +++++++++--------- .../refresher/PolarisRefresherHandler.java | 85 ++++++---- 3 files changed, 127 insertions(+), 109 deletions(-) diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/function/MatcherFunctionTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/function/MatcherFunctionTest.java index 2a202302..93287ed2 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/function/MatcherFunctionTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/function/MatcherFunctionTest.java @@ -22,7 +22,7 @@ import java.math.BigDecimal; import org.junit.Test; public final class MatcherFunctionTest { - + public static boolean matchTest(Matcher matcher, T value) { return matcher.match(value); } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java index 8cfb4264..a374cb4e 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java @@ -37,79 +37,80 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) public class ConfigHandlerConfiguration { - private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager"; - - private static final String NACOS_DATA_ID_KEY = "nacos.data-id"; - - private static final String APOLLO_NAMESPACE_KEY = "apollo.namespace"; - - private static final String ZOOKEEPER_CONNECT_STR_KEY = "zookeeper.zk-connect-str"; - - private static final String ETCD = "etcd.endpoints"; - - private static final String POLARIS = "config.serverConnector"; - - @RequiredArgsConstructor - @ConditionalOnClass(ConfigService.class) - @ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) - static class EmbeddedNacos { - - public final BootstrapConfigProperties bootstrapConfigProperties; - - @Bean - public NacosRefresherHandler nacosRefresherHandler() { - return new NacosRefresherHandler(bootstrapConfigProperties); - } - } - - @ConditionalOnClass(NacosConfigManager.class) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) - static class EmbeddedNacosCloud { - - @Bean - public NacosCloudRefresherHandler nacosCloudRefresherHandler() { - return new NacosCloudRefresherHandler(); - } - } - - @ConditionalOnClass(com.ctrip.framework.apollo.ConfigService.class) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = APOLLO_NAMESPACE_KEY) - static class EmbeddedApollo { - - @Bean - public ApolloRefresherHandler apolloRefresher() { - return new ApolloRefresherHandler(); - } - } - - @ConditionalOnClass(CuratorFramework.class) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ZOOKEEPER_CONNECT_STR_KEY) - static class EmbeddedZookeeper { - - @Bean - public ZookeeperRefresherHandler zookeeperRefresher() { - return new ZookeeperRefresherHandler(); - } - } - - @ConditionalOnClass(Client.class) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ETCD) - static class EmbeddedEtcd { - - @Bean - public EtcdRefresherHandler etcdRefresher() { - return new EtcdRefresherHandler(); - } - } - - @ConditionalOnClass(ConfigFileService.class) - @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = POLARIS) - static class Polaris { - @Bean - public PolarisRefresherHandler polarisRefresher(ConfigFileService configFileService) { - return new PolarisRefresherHandler(configFileService); - } - } + private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager"; + + private static final String NACOS_DATA_ID_KEY = "nacos.data-id"; + + private static final String APOLLO_NAMESPACE_KEY = "apollo.namespace"; + + private static final String ZOOKEEPER_CONNECT_STR_KEY = "zookeeper.zk-connect-str"; + + private static final String ETCD = "etcd.endpoints"; + + private static final String POLARIS = "config.serverConnector"; + + @RequiredArgsConstructor + @ConditionalOnClass(ConfigService.class) + @ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) + static class EmbeddedNacos { + + public final BootstrapConfigProperties bootstrapConfigProperties; + + @Bean + public NacosRefresherHandler nacosRefresherHandler() { + return new NacosRefresherHandler(bootstrapConfigProperties); + } + } + + @ConditionalOnClass(NacosConfigManager.class) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) + static class EmbeddedNacosCloud { + + @Bean + public NacosCloudRefresherHandler nacosCloudRefresherHandler() { + return new NacosCloudRefresherHandler(); + } + } + + @ConditionalOnClass(com.ctrip.framework.apollo.ConfigService.class) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = APOLLO_NAMESPACE_KEY) + static class EmbeddedApollo { + + @Bean + public ApolloRefresherHandler apolloRefresher() { + return new ApolloRefresherHandler(); + } + } + + @ConditionalOnClass(CuratorFramework.class) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ZOOKEEPER_CONNECT_STR_KEY) + static class EmbeddedZookeeper { + + @Bean + public ZookeeperRefresherHandler zookeeperRefresher() { + return new ZookeeperRefresherHandler(); + } + } + + @ConditionalOnClass(Client.class) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ETCD) + static class EmbeddedEtcd { + + @Bean + public EtcdRefresherHandler etcdRefresher() { + return new EtcdRefresherHandler(); + } + } + + @ConditionalOnClass(ConfigFileService.class) + @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = POLARIS) + static class Polaris { + + @Bean + public PolarisRefresherHandler polarisRefresher(ConfigFileService configFileService) { + return new PolarisRefresherHandler(configFileService); + } + } } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java index 4be903fd..c2825ed2 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java @@ -1,3 +1,20 @@ +/* + * 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; import java.util.Map; @@ -20,49 +37,49 @@ import org.springframework.beans.factory.annotation.Value; @RequiredArgsConstructor public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { - private final ConfigFileService configFileService; - - private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace:dev}"; + private final ConfigFileService configFileService; - private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group:dynamic}"; + private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace:dev}"; - private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name:root/bootstrap.yaml}"; + private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group:dynamic}"; - private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type:properties}"; + private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name:root/bootstrap.yaml}"; - @Value(POLARIS_NAMESPACE) - private String namespace; + private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type:properties}"; - @Value(POLARIS_FILE_GROUP) - private String fileGroup; + @Value(POLARIS_NAMESPACE) + private String namespace; - @Value(POLARIS_FILE_NAME) - private String fileName; + @Value(POLARIS_FILE_GROUP) + private String fileGroup; + @Value(POLARIS_FILE_NAME) + private String fileName; - @Override - public String getProperties() { - ConfigKVFile configFile = getConfigKVFile(); - configFile.getContent(); - return configFile.getContent(); - } + @Override + public String getProperties() { + ConfigKVFile configFile = getConfigKVFile(); + configFile.getContent(); + return configFile.getContent(); + } - @Override - public void afterPropertiesSet() { - ConfigKVFile configFile = getConfigKVFile(); - configFile.addChangeListener((ConfigKVFileChangeListener) event -> { - String content = configFile.getContent(); - Map newChangeValueMap = Maps.newHashMap(); - for (String key : event.changedKeys()) { - ConfigPropertyChangeInfo changeInfo = event.getChangeInfo(key); - newChangeValueMap.put(key, changeInfo.getNewValue()); - } - dynamicRefresh(content, newChangeValueMap); - }); - } + @Override + public void afterPropertiesSet() { + ConfigKVFile configFile = getConfigKVFile(); + configFile.addChangeListener((ConfigKVFileChangeListener) event -> { + String content = configFile.getContent(); + Map newChangeValueMap = Maps.newHashMap(); + for (String key : event.changedKeys()) { + ConfigPropertyChangeInfo changeInfo = event.getChangeInfo(key); + newChangeValueMap.put(key, changeInfo.getNewValue()); + } + dynamicRefresh(content, newChangeValueMap); + }); + } - private ConfigKVFile getConfigKVFile() { - return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); - } + private ConfigKVFile getConfigKVFile() { + return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) + : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); + } }