优化PropertiesAgent.init接口参数

This commit is contained in:
Redkale
2022-11-25 16:55:27 +08:00
parent a68d63d2be
commit 53d35fa02f
2 changed files with 24 additions and 6 deletions

View File

@@ -807,13 +807,15 @@ public final class Application {
}
}
for (PropertiesAgentProvider provider : InstanceProvider.sort(providers)) {
long s = System.currentTimeMillis();
this.propertiesAgent = provider.createInstance();
this.resourceFactory.inject(this.propertiesAgent);
if (compileMode) {
this.propertiesAgent.compile(propertiesConf);
} else {
this.propertiesAgent.init(resourceFactory, appProperties, propertiesConf);
this.propertiesAgent.init(resourceFactory, appProperties, sourceProperties, propertiesConf);
}
logger.info("PropertiesAgent (type = " + this.propertiesAgent.getClass().getSimpleName() + ") init in " + (System.currentTimeMillis() - s) + " ms");
break;
}
}

View File

@@ -42,11 +42,12 @@ public abstract class PropertiesAgent {
/**
* 初始化配置源配置项需要写入appProperties并监听配置项的变化
*
* @param factory 依赖注入资源工厂
* @param appProperties 全局property.开头的配置项
* @param conf 节点配置
* @param factory 依赖注入资源工厂
* @param appProperties 全局property.开头的配置项
* @param sourceProperties 全局source数据源的配置
* @param conf 节点配置
*/
public abstract void init(ResourceFactory factory, Properties appProperties, AnyValue conf);
public abstract void init(ResourceFactory factory, Properties appProperties, Properties sourceProperties, AnyValue conf);
/**
* 销毁动作
@@ -56,6 +57,21 @@ public abstract class PropertiesAgent {
public abstract void destroy(AnyValue conf);
protected String getKeyResourceName(String key) {
return key.startsWith("system.property.") || key.startsWith("property.") ? key : ("property." + key);
return key.startsWith("redkale.")
|| key.startsWith("property.")
|| key.startsWith("system.property.")
|| key.startsWith("mimetype.property.") ? key : ("property." + key);
}
protected void putProperties(Properties appProperties, Properties sourceProperties, Properties newProps) {
newProps.forEach((k, v) -> putProperties(appProperties, sourceProperties, k.toString(), v));
}
protected void putProperties(Properties appProperties, Properties sourceProperties, String key, Object value) {
if (key.startsWith("redkale.datasource.") || key.startsWith("redkale.datasource[")
|| key.startsWith("redkale.cachesource.") || key.startsWith("redkale.cachesource[")) {
sourceProperties.put(key, value);
}
appProperties.put(key, value);
}
}