format code

pull/754/head
weihu 3 years ago
parent 04e1c05fd9
commit 1f9f0dce03

@ -37,79 +37,80 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
public class ConfigHandlerConfiguration { public class ConfigHandlerConfiguration {
private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager"; 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 NACOS_DATA_ID_KEY = "nacos.data-id";
private static final String APOLLO_NAMESPACE_KEY = "apollo.namespace"; 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 ZOOKEEPER_CONNECT_STR_KEY = "zookeeper.zk-connect-str";
private static final String ETCD = "etcd.endpoints"; private static final String ETCD = "etcd.endpoints";
private static final String POLARIS = "config.serverConnector"; private static final String POLARIS = "config.serverConnector";
@RequiredArgsConstructor @RequiredArgsConstructor
@ConditionalOnClass(ConfigService.class) @ConditionalOnClass(ConfigService.class)
@ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY) @ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY)
static class EmbeddedNacos { static class EmbeddedNacos {
public final BootstrapConfigProperties bootstrapConfigProperties; public final BootstrapConfigProperties bootstrapConfigProperties;
@Bean @Bean
public NacosRefresherHandler nacosRefresherHandler() { public NacosRefresherHandler nacosRefresherHandler() {
return new NacosRefresherHandler(bootstrapConfigProperties); return new NacosRefresherHandler(bootstrapConfigProperties);
} }
} }
@ConditionalOnClass(NacosConfigManager.class) @ConditionalOnClass(NacosConfigManager.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = NACOS_DATA_ID_KEY)
static class EmbeddedNacosCloud { static class EmbeddedNacosCloud {
@Bean @Bean
public NacosCloudRefresherHandler nacosCloudRefresherHandler() { public NacosCloudRefresherHandler nacosCloudRefresherHandler() {
return new NacosCloudRefresherHandler(); return new NacosCloudRefresherHandler();
} }
} }
@ConditionalOnClass(com.ctrip.framework.apollo.ConfigService.class) @ConditionalOnClass(com.ctrip.framework.apollo.ConfigService.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = APOLLO_NAMESPACE_KEY) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = APOLLO_NAMESPACE_KEY)
static class EmbeddedApollo { static class EmbeddedApollo {
@Bean @Bean
public ApolloRefresherHandler apolloRefresher() { public ApolloRefresherHandler apolloRefresher() {
return new ApolloRefresherHandler(); return new ApolloRefresherHandler();
} }
} }
@ConditionalOnClass(CuratorFramework.class) @ConditionalOnClass(CuratorFramework.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ZOOKEEPER_CONNECT_STR_KEY) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ZOOKEEPER_CONNECT_STR_KEY)
static class EmbeddedZookeeper { static class EmbeddedZookeeper {
@Bean @Bean
public ZookeeperRefresherHandler zookeeperRefresher() { public ZookeeperRefresherHandler zookeeperRefresher() {
return new ZookeeperRefresherHandler(); return new ZookeeperRefresherHandler();
} }
} }
@ConditionalOnClass(Client.class) @ConditionalOnClass(Client.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ETCD) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = ETCD)
static class EmbeddedEtcd { static class EmbeddedEtcd {
@Bean @Bean
public EtcdRefresherHandler etcdRefresher() { public EtcdRefresherHandler etcdRefresher() {
return new EtcdRefresherHandler(); return new EtcdRefresherHandler();
} }
} }
@ConditionalOnClass(ConfigFileService.class) @ConditionalOnClass(ConfigFileService.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = POLARIS) @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, name = POLARIS)
static class Polaris { static class Polaris {
@Bean
public PolarisRefresherHandler polarisRefresher(ConfigFileService configFileService) { @Bean
return new PolarisRefresherHandler(configFileService); public PolarisRefresherHandler polarisRefresher(ConfigFileService configFileService) {
} return new PolarisRefresherHandler(configFileService);
} }
}
} }

@ -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; package cn.hippo4j.config.springboot.starter.refresher;
import java.util.Map; import java.util.Map;
@ -20,49 +37,49 @@ import org.springframework.beans.factory.annotation.Value;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
private final ConfigFileService configFileService; private final ConfigFileService configFileService;
private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace:dev}";
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 static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type:properties}";
private String namespace;
@Value(POLARIS_FILE_GROUP) @Value(POLARIS_NAMESPACE)
private String fileGroup; private String namespace;
@Value(POLARIS_FILE_NAME) @Value(POLARIS_FILE_GROUP)
private String fileName; private String fileGroup;
@Value(POLARIS_FILE_NAME)
private String fileName;
@Override @Override
public String getProperties() { public String getProperties() {
ConfigKVFile configFile = getConfigKVFile(); ConfigKVFile configFile = getConfigKVFile();
configFile.getContent(); configFile.getContent();
return configFile.getContent(); return configFile.getContent();
} }
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
ConfigKVFile configFile = getConfigKVFile(); ConfigKVFile configFile = getConfigKVFile();
configFile.addChangeListener((ConfigKVFileChangeListener) event -> { configFile.addChangeListener((ConfigKVFileChangeListener) event -> {
String content = configFile.getContent(); String content = configFile.getContent();
Map<String, Object> newChangeValueMap = Maps.newHashMap(); Map<String, Object> newChangeValueMap = Maps.newHashMap();
for (String key : event.changedKeys()) { for (String key : event.changedKeys()) {
ConfigPropertyChangeInfo changeInfo = event.getChangeInfo(key); ConfigPropertyChangeInfo changeInfo = event.getChangeInfo(key);
newChangeValueMap.put(key, changeInfo.getNewValue()); newChangeValueMap.put(key, changeInfo.getNewValue());
} }
dynamicRefresh(content, newChangeValueMap); dynamicRefresh(content, newChangeValueMap);
}); });
} }
private ConfigKVFile getConfigKVFile() { private ConfigKVFile getConfigKVFile() {
return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName)
} : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName);
}
} }

Loading…
Cancel
Save