You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package com.fanruan.api.conf;
|
|
|
|
|
|
|
|
import com.fr.config.ConfigContext;
|
|
|
|
import com.fr.config.Configuration;
|
|
|
|
import com.fr.config.holder.ConfigChangeListener;
|
|
|
|
import com.fr.transaction.Configurations;
|
|
|
|
import com.fr.transaction.ValidateProxy;
|
|
|
|
import com.fr.transaction.WorkerFacade;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author richie
|
|
|
|
* @version 10.0
|
|
|
|
* Created by richie on 2019-08-30
|
|
|
|
* 配置监听管理器
|
|
|
|
*/
|
|
|
|
public class ConfigurationKit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 注册监听配置变化的监听器
|
|
|
|
*
|
|
|
|
* @param listener 监听器
|
|
|
|
*/
|
|
|
|
public static void registerListener(ConfigChangeListener listener) {
|
|
|
|
ValidateProxy.getInstance().getValidateManager().registerListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存配置
|
|
|
|
*
|
|
|
|
* @param type 配置的类型
|
|
|
|
* @param action 保存动作
|
|
|
|
*/
|
|
|
|
public static void modify(Class<? extends Configuration> type, Runner action) {
|
|
|
|
Configurations.modify(new WorkerFacade(type) {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
action.run();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回config实例,且config实例只存在一个
|
|
|
|
* @param configuration Configuration类
|
|
|
|
* @param <T>
|
|
|
|
* @return config实例
|
|
|
|
*/
|
|
|
|
public static <T extends Configuration> T getConfigInstance(final Class<T> configuration) {
|
|
|
|
return ConfigContext.getConfigInstance(configuration);
|
|
|
|
}
|
|
|
|
}
|