Code format optimization

pull/805/head
chen.ma 3 years ago
parent a2f02ad9db
commit e2ece1fda0

@ -22,6 +22,7 @@ import cn.hippo4j.common.model.WebIpAndPortInfo;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import lombok.NoArgsConstructor;
import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServer;
import java.util.Arrays; import java.util.Arrays;
@ -29,37 +30,35 @@ import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
/** /**
* Ip and port Holder * Ip and port holder.
*/ */
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public class WebIpAndPortHolder { public class WebIpAndPortHolder {
private static boolean support = false; private static boolean SUPPORT_VERSION = false;
static { static {
try { try {
Class.forName("org.springframework.boot.web.server.WebServer"); Class.forName("org.springframework.boot.web.server.WebServer");
support = true; SUPPORT_VERSION = true;
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
/** /**
* Application ip and application post * Application ip and application post
*/ */
protected static AtomicReference<WebIpAndPortInfo> webIpAndPort = new AtomicReference<>(); protected static AtomicReference<WebIpAndPortInfo> WEB_IP_AND_PORT = new AtomicReference<>();
public static final String ALL = "*"; public static final String ALL = "*";
protected static final String SEPARATOR = ","; protected static final String SEPARATOR = ",";
private WebIpAndPortHolder() {
}
protected static void initIpAndPort() { protected static void initIpAndPort() {
if (!support) { if (!SUPPORT_VERSION) {
return; return;
} }
webIpAndPort.compareAndSet(null, getWebIpAndPortInfo()); WEB_IP_AND_PORT.compareAndSet(null, getWebIpAndPortInfo());
} }
private static WebIpAndPortInfo getWebIpAndPortInfo() { private static WebIpAndPortInfo getWebIpAndPortInfo() {
@ -76,19 +75,19 @@ public class WebIpAndPortHolder {
} }
/** /**
* get WebIpAndPortInfo, If it is null, initialize it * get WebIpAndPortInfo, If it is null, initialize it.
* *
* @return WebIpAndPortInfo * @return Web ip and port info
*/ */
public static WebIpAndPortInfo getWebIpAndPort() { public static WebIpAndPortInfo getWebIpAndPort() {
if (webIpAndPort.get() == null) { if (WEB_IP_AND_PORT.get() == null) {
initIpAndPort(); initIpAndPort();
} }
return WebIpAndPortHolder.webIpAndPort.get(); return WebIpAndPortHolder.WEB_IP_AND_PORT.get();
} }
/** /**
* Check the new properties and instance IP and port * Check the new properties and instance IP and port.
* *
* @param nodes nodes in properties * @param nodes nodes in properties
* @return Whether it meets the conditions * @return Whether it meets the conditions
@ -105,5 +104,4 @@ public class WebIpAndPortHolder {
.filter(Objects::nonNull) .filter(Objects::nonNull)
.anyMatch(each -> each.check(webIpAndPort.getIpSegment(), webIpAndPort.getPort())); .anyMatch(each -> each.check(webIpAndPort.getIpSegment(), webIpAndPort.getPort()));
} }
} }

@ -49,7 +49,6 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -7,7 +7,7 @@
<artifactId>hippo4j-example</artifactId> <artifactId>hippo4j-example</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-config-apollo-spring-boot-1.5-starter-example</artifactId> <artifactId>hippo4j-config-apollo-spring-boot-1x-starter-example</artifactId>
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
@ -37,15 +37,9 @@
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- <dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-starter</artifactId>
<version>${revision}</version>
</dependency>
-->
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-1.5-starter</artifactId> <artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>

@ -23,9 +23,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableDynamicThreadPool @EnableDynamicThreadPool
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.core") @SpringBootApplication(scanBasePackages = "cn.hippo4j.example.core")
public class ConfigApolloSpringBoot15ExampleApplication { public class ConfigApolloSpringBoot1xExampleApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ConfigApolloSpringBoot15ExampleApplication.class, args); SpringApplication.run(ConfigApolloSpringBoot1xExampleApplication.class, args);
} }
} }

@ -21,16 +21,11 @@ spring.dynamic.thread-pool.banner=true
spring.dynamic.thread-pool.check-state-interval=3 spring.dynamic.thread-pool.check-state-interval=3
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
spring.dynamic.thread-pool.notify-platforms[0].secret-key=ac0426a5-c712-474c-9bff-72b8b8f5caff spring.dynamic.thread-pool.notify-platforms[0].token=ac0426a5-c712-474c-9bff-72b8b8f5caff
spring.dynamic.thread-pool.notify-platforms[1].platform=DING
spring.dynamic.thread-pool.notify-platforms[1].secret-key=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
spring.dynamic.thread-pool.notify-platforms[2].platform=LARK
spring.dynamic.thread-pool.notify-platforms[2].secret-key=2cbf2808-3839-4c26-a04d-fd201dd51f9e
spring.dynamic.thread-pool.apollo.namespace=application spring.dynamic.thread-pool.apollo.namespace=application
spring.dynamic.thread-pool.config-file-type=properties spring.dynamic.thread-pool.config-file-type=properties
spring.dynamic.thread-pool.executors[0].active-alarm = 80 spring.dynamic.thread-pool.executors[0].active-alarm = 80
spring.dynamic.thread-pool.executors[0].alarm = true spring.dynamic.thread-pool.executors[0].alarm = true
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true

@ -7,7 +7,7 @@
<artifactId>hippo4j-example</artifactId> <artifactId>hippo4j-example</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-config-nacos-spring-boot-1.5-starter-example</artifactId> <artifactId>hippo4j-config-nacos-spring-boot-1x-starter-example</artifactId>
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
@ -16,7 +16,6 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
@ -47,7 +46,7 @@
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-1.5-starter</artifactId> <artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
@ -67,5 +66,4 @@
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

@ -10,6 +10,10 @@
<artifactId>hippo4j-example</artifactId> <artifactId>hippo4j-example</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<modules> <modules>
<module>hippo4j-example-core</module> <module>hippo4j-example-core</module>
<module>hippo4j-spring-boot-starter-example</module> <module>hippo4j-spring-boot-starter-example</module>
@ -23,11 +27,7 @@
<module>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq-example</module> <module>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq-example</module>
<module>hippo4j-spring-boot-starter-adapter-rocketmq-example</module> <module>hippo4j-spring-boot-starter-adapter-rocketmq-example</module>
<module>hippo4j-config-etcd-spring-boot-starter-example</module> <module>hippo4j-config-etcd-spring-boot-starter-example</module>
<module>hippo4j-config-nacos-spring-boot-1.5-starter-example</module> <module>hippo4j-config-nacos-spring-boot-1x-starter-example</module>
<module>hippo4j-config-apollo-spring-boot-1.5-starter-example</module> <module>hippo4j-config-apollo-spring-boot-1x-starter-example</module>
</modules> </modules>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
</project> </project>

@ -1 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot15x.starter.config.ConfigHandlerConfiguration

@ -2,15 +2,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot</artifactId> <artifactId>hippo4j-spring-boot</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
<modelVersion>4.0.0</modelVersion>
<artifactId>hippo4j-config-spring-boot-1.5-starter</artifactId>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

@ -15,22 +15,22 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.config.springboot15x.starter.config; package cn.hippo4j.config.springboot1x.starter.config;
import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt; import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt;
import cn.hippo4j.config.springboot15x.starter.refresher.SpringBoot15BootstrapConfigPropertiesBinderAdapt; import cn.hippo4j.config.springboot1x.starter.refresher.SpringBoot1xBootstrapConfigPropertiesBinderAdapt;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration /**
public class ConfigHandlerConfiguration { * Config handler auto configuration.
*/
public class ConfigHandlerAutoConfiguration {
@Bean @Bean
@ConditionalOnClass(RelaxedDataBinder.class) @ConditionalOnClass(RelaxedDataBinder.class)
public BootstrapConfigPropertiesBinderAdapt bootstrapConfigPropertiesBinderAdapt() { public BootstrapConfigPropertiesBinderAdapt bootstrapConfigPropertiesBinderAdapt() {
return new SpringBoot15BootstrapConfigPropertiesBinderAdapt(); return new SpringBoot1xBootstrapConfigPropertiesBinderAdapt();
} }
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.config.springboot15x.starter.refresher; package cn.hippo4j.config.springboot1x.starter.refresher;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt; import cn.hippo4j.config.springboot.starter.refresher.BootstrapConfigPropertiesBinderAdapt;
@ -40,15 +40,15 @@ import java.util.Set;
/** /**
* Bootstrap core properties binder adapt. * Bootstrap core properties binder adapt.
*/ */
public class SpringBoot15BootstrapConfigPropertiesBinderAdapt implements ApplicationContextAware, BootstrapConfigPropertiesBinderAdapt { public class SpringBoot1xBootstrapConfigPropertiesBinderAdapt implements ApplicationContextAware, BootstrapConfigPropertiesBinderAdapt {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
/** /**
* Bootstrap core properties binder. * Bootstrap core properties binder.
* *
* @param configInfo * @param configInfo config info
* @param bootstrapConfigProperties * @param bootstrapConfigProperties bootstrap config properties
* @return * @return
*/ */
@Override @Override
@ -56,20 +56,17 @@ public class SpringBoot15BootstrapConfigPropertiesBinderAdapt implements Applica
BootstrapConfigProperties bindableCoreProperties = new BootstrapConfigProperties(); BootstrapConfigProperties bindableCoreProperties = new BootstrapConfigProperties();
RelaxedNames relaxedNames = new RelaxedNames(BootstrapConfigProperties.PREFIX); RelaxedNames relaxedNames = new RelaxedNames(BootstrapConfigProperties.PREFIX);
Set<String> names = getNames(bindableCoreProperties, relaxedNames); Set<String> names = getNames(bindableCoreProperties, relaxedNames);
// 绑定器
Map<String, Object> stringConfigInfo = new HashMap<>(configInfo.size()); Map<String, Object> stringConfigInfo = new HashMap<>(configInfo.size());
configInfo.forEach((key, value) -> stringConfigInfo.put(key.toString(), value)); configInfo.forEach((key, value) -> stringConfigInfo.put(key.toString(), value));
MapPropertySource test = new MapPropertySource("Hippo4j", stringConfigInfo); MapPropertySource test = new MapPropertySource("Hippo4j", stringConfigInfo);
MutablePropertySources propertySources = new MutablePropertySources(); MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(test); propertySources.addFirst(test);
PropertyValues propertyValues = CustomPropertyNamePatternsMatcher.getPropertySourcesPropertyValues(names, propertySources); PropertyValues propertyValues = CustomPropertyNamePatternsMatcher.getPropertySourcesPropertyValues(names, propertySources);
RelaxedDataBinder dataBinder = new RelaxedDataBinder(bindableCoreProperties, BootstrapConfigProperties.PREFIX); RelaxedDataBinder dataBinder = new RelaxedDataBinder(bindableCoreProperties, BootstrapConfigProperties.PREFIX);
dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE); dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
dataBinder.setIgnoreNestedProperties(false); dataBinder.setIgnoreNestedProperties(false);
dataBinder.setIgnoreInvalidFields(false); dataBinder.setIgnoreInvalidFields(false);
dataBinder.setIgnoreUnknownFields(true); dataBinder.setIgnoreUnknownFields(true);
ResourceEditorRegistrar resourceEditorRegistrar = new ResourceEditorRegistrar(applicationContext, applicationContext.getEnvironment()); ResourceEditorRegistrar resourceEditorRegistrar = new ResourceEditorRegistrar(applicationContext, applicationContext.getEnvironment());
resourceEditorRegistrar.registerCustomEditors(dataBinder); resourceEditorRegistrar.registerCustomEditors(dataBinder);
dataBinder.bind(propertyValues); dataBinder.bind(propertyValues);

@ -18,24 +18,30 @@
package org.springframework.boot.bind; package org.springframework.boot.bind;
import org.springframework.beans.PropertyValues; import org.springframework.beans.PropertyValues;
import org.springframework.boot.bind.DefaultPropertyNamePatternsMatcher;
import org.springframework.boot.bind.PropertyNamePatternsMatcher;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.MutablePropertySources;
import java.util.Set; import java.util.Set;
/**
* Custom property name patterns matcher.
*/
public class CustomPropertyNamePatternsMatcher { public class CustomPropertyNamePatternsMatcher {
private static final char[] EXACT_DELIMITERS = {'_', '.', '['}; private static final char[] EXACT_DELIMITERS = {'_', '.', '['};
/**
* Get property sources property values.
*
* @param names
* @param propertySources
* @return
*/
public static PropertyValues getPropertySourcesPropertyValues(Set<String> names, MutablePropertySources propertySources) { public static PropertyValues getPropertySourcesPropertyValues(Set<String> names, MutablePropertySources propertySources) {
PropertyNamePatternsMatcher includes = getPropertyNamePatternsMatcher(names); PropertyNamePatternsMatcher includes = getPropertyNamePatternsMatcher(names);
return new PropertySourcesPropertyValues(propertySources, names, includes, true); return new PropertySourcesPropertyValues(propertySources, names, includes, true);
} }
private static PropertyNamePatternsMatcher getPropertyNamePatternsMatcher(Set<String> names) { private static PropertyNamePatternsMatcher getPropertyNamePatternsMatcher(Set<String> names) {
return new DefaultPropertyNamePatternsMatcher(EXACT_DELIMITERS, true, names); return new DefaultPropertyNamePatternsMatcher(EXACT_DELIMITERS, true, names);
} }
} }

@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot1x.starter.config.ConfigHandlerAutoConfiguration

@ -118,5 +118,4 @@ public class ConfigHandlerConfiguration {
return new PolarisRefresherHandler(configFileService); return new PolarisRefresherHandler(configFileService);
} }
} }
} }

@ -57,9 +57,9 @@ import org.springframework.core.annotation.Order;
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor
@ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnBean(MarkerConfiguration.Marker.class)
@EnableConfigurationProperties(BootstrapConfigProperties.class)
@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@Import({ConfigHandlerConfiguration.class}) @EnableConfigurationProperties(BootstrapConfigProperties.class)
@Import(ConfigHandlerConfiguration.class)
@ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class, LocalLogMonitorConfiguration.class, MicrometerMonitorConfiguration.class}) @ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class, LocalLogMonitorConfiguration.class, MicrometerMonitorConfiguration.class})
public class DynamicThreadPoolAutoConfiguration { public class DynamicThreadPoolAutoConfiguration {

@ -25,7 +25,6 @@ import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.parser.ConfigParserHandler; import cn.hippo4j.config.springboot.starter.parser.ConfigParserHandler;
import cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEvent; import cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEvent;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@ -71,8 +70,8 @@ public abstract class AbstractConfigThreadPoolDynamicRefresh
if (CollectionUtil.isNotEmpty(newValueChangeMap)) { if (CollectionUtil.isNotEmpty(newValueChangeMap)) {
Optional.ofNullable(configInfo).ifPresent(each -> each.putAll(newValueChangeMap)); Optional.ofNullable(configInfo).ifPresent(each -> each.putAll(newValueChangeMap));
} }
BootstrapConfigProperties bindableCoreProperties = bootstrapConfigPropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties); BootstrapConfigProperties binderCoreProperties = bootstrapConfigPropertiesBinderAdapt.bootstrapCorePropertiesBinder(configInfo, bootstrapConfigProperties);
ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, bindableCoreProperties)); ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, binderCoreProperties));
} catch (Exception ex) { } catch (Exception ex) {
log.error("Hippo-4J core dynamic refresh failed.", ex); log.error("Hippo-4J core dynamic refresh failed.", ex);
} }

@ -21,7 +21,17 @@ import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import java.util.Map; import java.util.Map;
/**
* Bootstrap config properties binder adapt.
*/
public interface BootstrapConfigPropertiesBinderAdapt { public interface BootstrapConfigPropertiesBinderAdapt {
/**
* Bootstrap core properties binder.
*
* @param configInfo dynamic thread pool configuration
* @param bootstrapConfigProperties bootstrap config properties
* @return
*/
BootstrapConfigProperties bootstrapCorePropertiesBinder(Map<Object, Object> configInfo, BootstrapConfigProperties bootstrapConfigProperties); BootstrapConfigProperties bootstrapCorePropertiesBinder(Map<Object, Object> configInfo, BootstrapConfigProperties bootstrapConfigProperties);
} }

@ -43,5 +43,4 @@ public class DefaultBootstrapConfigPropertiesBinderAdapt implements BootstrapCon
Binder binder = new Binder(sources); Binder binder = new Binder(sources);
return binder.bind(BootstrapConfigProperties.PREFIX, Bindable.ofInstance(bootstrapConfigProperties)).get(); return binder.bind(BootstrapConfigProperties.PREFIX, Bindable.ofInstance(bootstrapConfigProperties)).get();
} }
} }

@ -31,9 +31,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
* @author : wh * Etcd refresher handler.
* @date : 2022/8/30 17:59
* @description:
*/ */
@Slf4j @Slf4j
public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
@ -57,7 +55,6 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
Map<String, String> etcd = bootstrapConfigProperties.getEtcd(); Map<String, String> etcd = bootstrapConfigProperties.getEtcd();
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET)); Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
initClient(etcd, charset); initClient(etcd, charset);
String key = etcd.get(KEY); String key = etcd.get(KEY);
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get(); GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
KeyValue keyValue = getResponse.getKvs().get(0); KeyValue keyValue = getResponse.getKvs().get(0);
@ -70,8 +67,7 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
String key = etcd.get(KEY); String key = etcd.get(KEY);
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET)); Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
initClient(etcd, charset); initClient(etcd, charset);
// TODO Currently only supports json
// todo Currently only supports json
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get(); GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
KeyValue keyValue = getResponse.getKvs().get(0); KeyValue keyValue = getResponse.getKvs().get(0);
if (Objects.isNull(keyValue)) { if (Objects.isNull(keyValue)) {
@ -111,7 +107,7 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
* @param charset charset * @param charset charset
*/ */
private void initClient(Map<String, String> etcd, Charset charset) { private void initClient(Map<String, String> etcd, Charset charset) {
// todo // TODO
if (Objects.isNull(client)) { if (Objects.isNull(client)) {
String user = etcd.get(USER); String user = etcd.get(USER);
String password = etcd.get(PASSWORD); String password = etcd.get(PASSWORD);
@ -123,5 +119,4 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
.build() : clientBuilder.build(); .build() : clientBuilder.build();
} }
} }
} }

@ -32,6 +32,7 @@ import java.util.concurrent.Executor;
public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
static final String DATA_ID = "data-id"; static final String DATA_ID = "data-id";
static final String GROUP = "group"; static final String GROUP = "group";
private final NacosConfigManager nacosConfigManager; private final NacosConfigManager nacosConfigManager;

@ -17,7 +17,6 @@
package cn.hippo4j.config.springboot.starter.refresher; package cn.hippo4j.config.springboot.starter.refresher;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import com.alibaba.cloud.nacos.NacosConfigProperties; import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.annotation.NacosInjected; import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.ConfigService;
@ -34,6 +33,7 @@ import java.util.concurrent.Executor;
public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
static final String DATA_ID = "data-id"; static final String DATA_ID = "data-id";
static final String GROUP = "group"; static final String GROUP = "group";
@NacosInjected @NacosInjected

@ -29,9 +29,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
*@author : wh * Polaris refresher handler.
*@date : 2022/10/1 15:24
*@description:
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh { public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
@ -80,5 +78,4 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr
return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName)
: configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName);
} }
} }

@ -15,6 +15,6 @@
<module>hippo4j-spring-boot-starter</module> <module>hippo4j-spring-boot-starter</module>
<module>hippo4j-spring-boot-starter-adapter</module> <module>hippo4j-spring-boot-starter-adapter</module>
<module>hippo4j-spring-boot-starter-monitor</module> <module>hippo4j-spring-boot-starter-monitor</module>
<module>hippo4j-config-spring-boot-1.5-starter</module> <module>hippo4j-config-spring-boot-1x-starter</module>
</modules> </modules>
</project> </project>

Loading…
Cancel
Save