format code

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

@ -22,7 +22,7 @@ import java.math.BigDecimal;
import org.junit.Test;
public final class MatcherFunctionTest {
public static <T> boolean matchTest(Matcher<T> matcher, T value) {
return matcher.match(value);
}

@ -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);
}
}
}

@ -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<String, Object> 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<String, Object> 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);
}
}

Loading…
Cancel
Save