Use configuration and constants exist in PolarisRefresherHandler

pull/1470/head
MZR 2 years ago
parent 60fc6fa0b4
commit f9ca95d225

@ -36,13 +36,13 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr
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_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace}";
private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group:dynamic}"; private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group}";
private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name:root/bootstrap.yaml}"; private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name}";
private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type:properties}"; private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type}";
@Value(POLARIS_NAMESPACE) @Value(POLARIS_NAMESPACE)
private String namespace; private String namespace;
@ -71,4 +71,20 @@ 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);
} }
public static String getPolarisNamespace() {
return POLARIS_NAMESPACE;
}
public static String getPolarisFileGroup() {
return POLARIS_FILE_GROUP;
}
public static String getPolarisFileName() {
return POLARIS_FILE_NAME;
}
public static String getPolarisFileType() {
return POLARIS_FILE_TYPE;
}
} }

@ -34,6 +34,11 @@
<artifactId>hippo4j-threadpool-kernel-monitor</artifactId> <artifactId>hippo4j-threadpool-kernel-monitor</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-config-spring-boot-starter</artifactId>
<version>${project.version}</version>
</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>

@ -40,24 +40,16 @@ public class BeforeCheckConfiguration {
private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties"; private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties";
private final String bootstrapConfigPropertiesClassName = "cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties"; private final String bootstrapConfigPropertiesClassName = "cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties";
private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace}"; @Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisNamespace()}")
private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group}";
private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name}";
private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type}";
@Value(POLARIS_NAMESPACE)
private String polarisNamespace; private String polarisNamespace;
@Value(POLARIS_FILE_GROUP) @Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileGroup()}")
private String polarisFileGroup; private String polarisFileGroup;
@Value(POLARIS_FILE_NAME) @Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileName()}")
private String polarisFileName; private String polarisFileName;
@Value(POLARIS_FILE_TYPE) @Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileType()}")
private String polarisFileType; private String polarisFileType;
@Bean @Bean
@ -167,22 +159,22 @@ public class BeforeCheckConfiguration {
if (StringUtil.isBlank(polarisNamespace)) { if (StringUtil.isBlank(polarisNamespace)) {
throw new ConfigEmptyException( throw new ConfigEmptyException(
"Web server maybe fail to start. The dynamic thread pool polaris namespace is empty.", "Web server failed to start. The dynamic thread pool polaris namespace is empty.",
"Please check whether the [spring.dynamic.thread-pool.polaris.namespace] configuration is empty or an empty string."); "Please check whether the [spring.dynamic.thread-pool.polaris.namespace] configuration is empty or an empty string.");
} }
if (StringUtil.isBlank(polarisFileGroup)) { if (StringUtil.isBlank(polarisFileGroup)) {
throw new ConfigEmptyException( throw new ConfigEmptyException(
"Web server maybe fail to start. The dynamic thread pool polaris file group is empty.", "Web server failed to start. The dynamic thread pool polaris file group is empty.",
"Please check whether the [spring.dynamic.thread-pool.polaris.file.group] configuration is empty or an empty string."); "Please check whether the [spring.dynamic.thread-pool.polaris.file.group] configuration is empty or an empty string.");
} }
if (StringUtil.isBlank(polarisFileName)) { if (StringUtil.isBlank(polarisFileName)) {
throw new ConfigEmptyException( throw new ConfigEmptyException(
"Web server maybe fail to start. The dynamic thread pool polaris file name is empty.", "Web server failed to start. The dynamic thread pool polaris file name is empty.",
"Please check whether the [spring.dynamic.thread-pool.polaris.file.name] configuration is empty or an empty string."); "Please check whether the [spring.dynamic.thread-pool.polaris.file.name] configuration is empty or an empty string.");
} }
if (StringUtil.isBlank(polarisFileType)) { if (StringUtil.isBlank(polarisFileType)) {
throw new ConfigEmptyException( throw new ConfigEmptyException(
"Web server maybe fail to start. The dynamic thread pool polaris file type is empty.", "Web server failed to start. The dynamic thread pool polaris file type is empty.",
"Please check whether the [spring.dynamic.thread-pool.polaris.file.type] configuration is empty or an empty string."); "Please check whether the [spring.dynamic.thread-pool.polaris.file.type] configuration is empty or an empty string.");
} }
break; break;

Loading…
Cancel
Save