change: 配置新增一层文件型配置抽象.
This commit is contained in:
@@ -103,6 +103,11 @@ public abstract class AbstractConfiguration implements Configuration {
|
|||||||
printDetails();
|
printDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 载入配置信息请加锁
|
* 载入配置信息请加锁
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.serliunx.ddns.config;
|
package com.serliunx.ddns.config;
|
||||||
|
|
||||||
|
import com.serliunx.ddns.core.Priority;
|
||||||
import com.serliunx.ddns.core.Refreshable;
|
import com.serliunx.ddns.core.Refreshable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -7,7 +8,7 @@ import com.serliunx.ddns.core.Refreshable;
|
|||||||
* @author SerLiunx
|
* @author SerLiunx
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public interface Configuration extends Refreshable {
|
public interface Configuration extends Refreshable, Priority {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取整数
|
* 获取整数
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.serliunx.ddns.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public abstract class FileConfiguration extends AbstractConfiguration {
|
||||||
|
|
||||||
|
protected final String path;
|
||||||
|
|
||||||
|
public FileConfiguration(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,15 +16,19 @@ import java.util.Set;
|
|||||||
* @author SerLiunx
|
* @author SerLiunx
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class PropertiesConfiguration extends AbstractConfiguration {
|
public class PropertiesConfiguration extends FileConfiguration {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesConfiguration.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesConfiguration.class);
|
||||||
|
|
||||||
private final String path;
|
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
public PropertiesConfiguration(String path) {
|
public PropertiesConfiguration(String path) {
|
||||||
this.path = path;
|
super(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,7 +39,12 @@ public final class SystemConstants {
|
|||||||
/**
|
/**
|
||||||
* properties配置文件名称
|
* properties配置文件名称
|
||||||
*/
|
*/
|
||||||
public static final String PROPERTIES_FILE = "settings.properties";
|
public static final String CONFIG_PROPERTIES_FILE = "settings.properties";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* yaml配置文件名称
|
||||||
|
*/
|
||||||
|
public static final String CONFIG_YAML_FILE = "settings.yml";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志配置文件名称
|
* 日志配置文件名称
|
||||||
@@ -69,5 +74,10 @@ public final class SystemConstants {
|
|||||||
/**
|
/**
|
||||||
* 用户目录下的.properties配置文件
|
* 用户目录下的.properties配置文件
|
||||||
*/
|
*/
|
||||||
public static final String USER_SETTINGS_PROPERTIES_PATH = USER_DIR + File.separator + PROPERTIES_FILE;
|
public static final String USER_SETTINGS_PROPERTIES_PATH = USER_DIR + File.separator + CONFIG_PROPERTIES_FILE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户目录下的.yml配置文件
|
||||||
|
*/
|
||||||
|
public static final String USER_SETTINGS_YAML_PATH = USER_DIR + File.separator + CONFIG_YAML_FILE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ public abstract class AbstractInstanceContext implements InstanceContext, Multip
|
|||||||
Set<Instance> builtInstances = buildInstances(instances);
|
Set<Instance> builtInstances = buildInstances(instances);
|
||||||
|
|
||||||
instanceMap = builtInstances.stream().collect(Collectors.toMap(Instance::getName, i -> i));
|
instanceMap = builtInstances.stream().collect(Collectors.toMap(Instance::getName, i -> i));
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}finally {
|
} finally {
|
||||||
instanceLock.unlock();
|
instanceLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public final class SystemInitializer implements Refreshable, Clearable {
|
|||||||
log.info("程序正在初始化, 请稍候.");
|
log.info("程序正在初始化, 请稍候.");
|
||||||
|
|
||||||
// 释放配置文件
|
// 释放配置文件
|
||||||
releaseResource(SystemConstants.PROPERTIES_FILE);
|
releaseResource(SystemConstants.CONFIG_PROPERTIES_FILE);
|
||||||
|
|
||||||
// 刷新配置信息
|
// 刷新配置信息
|
||||||
configuration.refresh();
|
configuration.refresh();
|
||||||
|
|||||||
Reference in New Issue
Block a user