Browse Source

配置监听+错误的插件类

master
richie 5 years ago
parent
commit
e8fff9d7c3
  1. 61
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  2. 11
      src/main/java/com/fanruan/api/generic/Matcher.java
  3. 2
      src/main/java/com/fanruan/api/generic/Runner.java
  4. 20
      src/main/java/com/fanruan/api/runtime/PluginKit.java
  5. 13
      src/test/java/com/fanruan/api/plugin/PluginKitTest.java

61
src/main/java/com/fanruan/api/conf/ConfigurationKit.java

@ -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();
}
}
});
}
}

11
src/main/java/com/fanruan/api/generic/Matcher.java

@ -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);
}

2
src/main/java/com/fanruan/api/conf/Runner.java → src/main/java/com/fanruan/api/generic/Runner.java

@ -1,4 +1,4 @@
package com.fanruan.api.conf;
package com.fanruan.api.generic;
/**
* @author richie

20
src/main/java/com/fanruan/api/runtime/PluginKit.java

@ -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();
}
}

13
src/test/java/com/fanruan/api/plugin/PluginKitTest.java

@ -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…
Cancel
Save