forked from fanruan/finekit
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.
62 lines
1.7 KiB
62 lines
1.7 KiB
6 years ago
|
package com.fanruan.api.conf;
|
||
|
|
||
|
import com.fanruan.api.generic.Matcher;
|
||
|
import com.fanruan.api.generic.Runner;
|
||
|
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-09-17
|
||
|
* 配置管理工具类
|
||
|
*/
|
||
|
public class ConfigurationKit {
|
||
|
|
||
|
/**
|
||
|
* 兼容配置缓存失效
|
||
|
*
|
||
|
* @param matcher 匹配器
|
||
|
* @param runner 匹配后执行的动作
|
||
|
*/
|
||
|
public static void listenCacheChange(final Matcher<Class<? extends Configuration>> matcher, final Runner runner) {
|
||
|
ValidateProxy.getInstance().getValidateManager().registerListener(new ConfigChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public boolean accept(Class<? extends Configuration> clazz) {
|
||
|
if (matcher == null) {
|
||
|
return true;
|
||
|
}
|
||
|
return matcher.match(clazz);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void change() {
|
||
|
if (matcher != null) {
|
||
|
runner.run();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 在一个事务中修改配置
|
||
|
*
|
||
|
* @param configType 配置类
|
||
|
* @param runner 执行器
|
||
|
*/
|
||
|
public static void modify(Class<? extends Configuration> configType, Runner runner) {
|
||
|
Configurations.modify(new WorkerFacade(configType) {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
if (runner != null) {
|
||
|
runner.run();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|