From 8e226b30396d50631293c8c95343148bc220ca5e Mon Sep 17 00:00:00 2001 From: "Dylan.Liu" Date: Thu, 27 Feb 2020 17:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=BD=BF=E5=A4=9A=E4=B8=AA=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=A4=B1=E6=95=88=E7=9A=84=20modify=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/conf/ConfigurationKit.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/com/fanruan/api/conf/ConfigurationKit.java b/src/main/java/com/fanruan/api/conf/ConfigurationKit.java index 6f7ccb1..b4bbacf 100644 --- a/src/main/java/com/fanruan/api/conf/ConfigurationKit.java +++ b/src/main/java/com/fanruan/api/conf/ConfigurationKit.java @@ -60,6 +60,26 @@ public class ConfigurationKit { }); } + /** + * 在一个事务中修改配置 + * 支持 让 configType, configTypes 缓存失效 + * + * @param configType 配置类 + * @param runner 执行器 + * @param configTypes 配置类(所有的配置类都会缓存失效) + */ + public static void modify(Runner runner, Class configType, Class... configTypes) { + Configurations.modify(new WorkerFacade(configType, configTypes) { + @Override + public void run() { + if (runner != null) { + runner.run(); + } + } + }); + } + + /** * 在一个事务中修改配置 * @@ -81,4 +101,29 @@ public class ConfigurationKit { } Configurations.modify(facade); } + + /** + * 在一个事务中修改配置 + * 支持 让 configType, configTypes 失效 + * + * @param configType 配置类 + * @param runner 执行器 + * @param callBack 事务回调 + * @param configTypes 配置类(所有的配置类都会缓存失效) + */ + public static void modify(Runner runner, WorkerCallBack callBack, Class configType, Class... configTypes) { + WorkerFacade facade = new WorkerFacade(configType, configTypes) { + @Override + public void run() { + if (runner != null) { + runner.run(); + } + } + }; + if (callBack != null) { + facade.addCallBack(callBack); + } + Configurations.modify(facade); + } + }