forked from fanruan/finekit
richie
5 years ago
5 changed files with 73 additions and 34 deletions
@ -0,0 +1,61 @@
|
||||
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(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.fanruan.api.generic; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-17 |
||||
*/ |
||||
public interface Matcher<T> { |
||||
|
||||
boolean match(T t); |
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.fanruan.api.conf; |
||||
package com.fanruan.api.generic; |
||||
|
||||
/** |
||||
* @author richie |
@ -1,20 +0,0 @@
|
||||
package com.fanruan.api.runtime; |
||||
|
||||
import com.fr.plugin.context.PluginContexts; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-08-30 |
||||
* 插件相关的工具类 |
||||
*/ |
||||
public class PluginKit { |
||||
|
||||
/** |
||||
* 当前插件是否可用(例如:插件授权文件过期时,该犯法会返回false) |
||||
* @return 插件可用则返回true,不可用则返回false |
||||
*/ |
||||
public static boolean isCurrentPluginAvailable() { |
||||
return PluginContexts.currentContext().isAvailable(); |
||||
} |
||||
} |
@ -1,13 +0,0 @@
|
||||
package com.fanruan.api.plugin; |
||||
|
||||
import com.fanruan.api.runtime.PluginKit; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class PluginKitTest { |
||||
@Test |
||||
public void getArray() { |
||||
Assert.assertFalse(PluginKit.isCurrentPluginAvailable()); |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue