From 8e226b30396d50631293c8c95343148bc220ca5e Mon Sep 17 00:00:00 2001 From: "Dylan.Liu" Date: Thu, 27 Feb 2020 17:07:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=BD=BF=E5=A4=9A=E4=B8=AA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20=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); + } + } From 4199182e20aeb4c55f07ff08292c01d1939628ed Mon Sep 17 00:00:00 2001 From: "Dylan.Liu" Date: Thu, 23 Apr 2020 20:16:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A0=20jira=20=E4=BB=BB=E5=8A=A1=20fin?= =?UTF-8?q?ekit=20=E9=80=82=E9=85=8D=E7=8A=B6=E6=80=81=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=8E=A5=E5=8F=A3=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../state/BaseRedisCollectionsClient.java | 4 ++-- .../api/cluster/state/BaseRedisStore.java | 5 +++-- .../api/cluster/state/FineJedisPoolKit.java | 9 +++++---- .../api/cluster/state/StandAloneJedisKit.java | 8 ++++---- .../cluster/state/FineJedisPoolKitTest.java | 20 +++++++++---------- .../cluster/state/StandAloneJedisKitTest.java | 4 ++-- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java b/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java index ca75924..4c79368 100644 --- a/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java +++ b/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java @@ -1,6 +1,6 @@ package com.fanruan.api.cluster.state; -import com.fr.collections.cluster.client.RedisCollectionsClient; +import com.fr.collections.cluster.client.StoreCollectionsClient; import com.fr.collections.config.redis.RedisCollectionConfig; /** @@ -9,7 +9,7 @@ import com.fr.collections.config.redis.RedisCollectionConfig; * @version 10.0 * Created by Dylan.Liu on 2019/12/3 */ -public class BaseRedisCollectionsClient extends RedisCollectionsClient { +public class BaseRedisCollectionsClient extends StoreCollectionsClient { public BaseRedisCollectionsClient() { diff --git a/src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java b/src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java index b4c47a8..e9b5ab5 100644 --- a/src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java +++ b/src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java @@ -1,6 +1,7 @@ package com.fanruan.api.cluster.state; -import com.fr.store.RedisStore; + +import com.fr.store.StateStore; /** * Redis Store @@ -8,7 +9,7 @@ import com.fr.store.RedisStore; * @version 10.0 * Created by Dylan.Liu on 2019/12/3 */ -public class BaseRedisStore extends RedisStore { +public class BaseRedisStore extends StateStore { public BaseRedisStore(String tableNamePrefix, int expireStateRemoveInterval) { super(tableNamePrefix, expireStateRemoveInterval); diff --git a/src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java b/src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java index eb848d0..c4b5884 100644 --- a/src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java +++ b/src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java @@ -1,7 +1,8 @@ package com.fanruan.api.cluster.state; -import com.fr.store.impl.redis.accessor.FineJedisPool; -import com.fr.store.impl.redis.accessor.FineJedisWrapper; + +import com.fr.store.impl.accessor.FineStorePool; +import com.fr.store.impl.accessor.FineStoreWrapper; /** * @author Dylan.Liu @@ -14,8 +15,8 @@ public class FineJedisPoolKit { * 设置提供真实资源的 Jedis 包装对象 * @param jedisWrapper Jedis 包装对象 */ - public static void setRealClient(FineJedisWrapper jedisWrapper) { + public static void setRealClient(FineStoreWrapper jedisWrapper) { - FineJedisPool.getInstance().setRealClient(jedisWrapper); + FineStorePool.getInstance().setRealClient(jedisWrapper); } } diff --git a/src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java b/src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java index 02aea54..900d3eb 100644 --- a/src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java +++ b/src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java @@ -1,7 +1,7 @@ package com.fanruan.api.cluster.state; -import com.fr.store.impl.redis.accessor.FineJedis; -import com.fr.store.impl.redis.accessor.StandAloneJedis; +import com.fr.store.impl.accessor.FineStore; +import com.fr.store.impl.accessor.StandAloneStore; import com.fr.third.redis.clients.jedis.Jedis; /** @@ -16,11 +16,11 @@ public class StandAloneJedisKit { * @param jedis Jedis 资源 * @return 单机版 Jedis Api集合 */ - public static FineJedis createStandAloneJedis(Jedis jedis) { + public static FineStore createStandAloneJedis(Jedis jedis) { if (jedis == null) { throw new NullPointerException("jedis is null"); } - return new StandAloneJedis(jedis); + return new StandAloneStore(jedis); } } diff --git a/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java b/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java index c0cbd17..f64c325 100644 --- a/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java +++ b/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java @@ -1,8 +1,8 @@ package com.fanruan.api.cluster.state; -import com.fr.store.impl.redis.accessor.FineJedis; -import com.fr.store.impl.redis.accessor.FineJedisPool; -import com.fr.store.impl.redis.accessor.FineJedisWrapper; +import com.fr.store.impl.accessor.FineStore; +import com.fr.store.impl.accessor.FineStorePool; +import com.fr.store.impl.accessor.FineStoreWrapper; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; @@ -21,10 +21,10 @@ public class FineJedisPoolKitTest { @Test public void TestSetRealClient() { - FineJedisPoolKit.setRealClient(new FineJedisWrapper() { + FineJedisPoolKit.setRealClient(new FineStoreWrapper() { @Override - public FineJedis getResource() { + public FineStore getResource() { return null; } @@ -33,16 +33,16 @@ public class FineJedisPoolKitTest { } }); - Assert.assertNull(FineJedisPool.getInstance().getResource()); + Assert.assertNull(FineStorePool.getInstance().getResource()); - FineJedis mockFineJedis = mock(FineJedis.class); + FineStore mockFineJedis = mock(FineStore.class); expect(mockFineJedis.type(anyObject())).andReturn("TestFineJedis"); EasyMock.replay(mockFineJedis); - FineJedisPoolKit.setRealClient(new FineJedisWrapper() { + FineJedisPoolKit.setRealClient(new FineStoreWrapper() { @Override - public FineJedis getResource() { + public FineStore getResource() { return mockFineJedis; } @@ -51,7 +51,7 @@ public class FineJedisPoolKitTest { } }); - Assert.assertEquals("TestFineJedis", FineJedisPool.getInstance().getResource().type(new byte[]{})); + Assert.assertEquals("TestFineJedis", FineStorePool.getInstance().getResource().type(new byte[]{})); } } \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java b/src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java index 61fcb52..dd74611 100644 --- a/src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java +++ b/src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java @@ -1,6 +1,6 @@ package com.fanruan.api.cluster.state; -import com.fr.store.impl.redis.accessor.FineJedis; +import com.fr.store.impl.accessor.FineStore; import com.fr.third.redis.clients.jedis.Jedis; import org.easymock.EasyMock; import org.junit.Assert; @@ -24,7 +24,7 @@ public class StandAloneJedisKitTest { expect(mockJedis.type(anyObject(byte[].class))).andReturn("test_echo"); EasyMock.replay(mockJedis); - FineJedis standAloneJedis = StandAloneJedisKit.createStandAloneJedis(mockJedis); + FineStore standAloneJedis = StandAloneJedisKit.createStandAloneJedis(mockJedis); Assert.assertEquals("test_echo", standAloneJedis.type(new byte[]{})); } From 5419aded99ca04270b675105b62d2dbcf237c57d Mon Sep 17 00:00:00 2001 From: "Dylan.Liu" Date: Thu, 23 Apr 2020 20:45:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=97=A0=20jira=20=E4=BB=BB=E5=8A=A1=20,?= =?UTF-8?q?=20=E9=80=82=E9=85=8D=201.7=20=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fanruan/api/conf/ConfigurationKit.java | 8 ++++---- src/main/java/com/fanruan/api/data/ConnectionKit.java | 6 ++---- .../fanruan/api/cluster/state/FineJedisPoolKitTest.java | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fanruan/api/conf/ConfigurationKit.java b/src/main/java/com/fanruan/api/conf/ConfigurationKit.java index b4bbacf..30706ed 100644 --- a/src/main/java/com/fanruan/api/conf/ConfigurationKit.java +++ b/src/main/java/com/fanruan/api/conf/ConfigurationKit.java @@ -49,7 +49,7 @@ public class ConfigurationKit { * @param configType 配置类 * @param runner 执行器 */ - public static void modify(Class configType, Runner runner) { + public static void modify(Class configType, final Runner runner) { Configurations.modify(new WorkerFacade(configType) { @Override public void run() { @@ -68,7 +68,7 @@ public class ConfigurationKit { * @param runner 执行器 * @param configTypes 配置类(所有的配置类都会缓存失效) */ - public static void modify(Runner runner, Class configType, Class... configTypes) { + public static void modify(final Runner runner, Class configType, Class... configTypes) { Configurations.modify(new WorkerFacade(configType, configTypes) { @Override public void run() { @@ -87,7 +87,7 @@ public class ConfigurationKit { * @param runner 执行器 * @param callBack 事务回调 */ - public static void modify(Class configType, Runner runner, WorkerCallBack callBack) { + public static void modify(Class configType, final Runner runner, WorkerCallBack callBack) { WorkerFacade facade = new WorkerFacade(configType) { @Override public void run() { @@ -111,7 +111,7 @@ public class ConfigurationKit { * @param callBack 事务回调 * @param configTypes 配置类(所有的配置类都会缓存失效) */ - public static void modify(Runner runner, WorkerCallBack callBack, Class configType, Class... configTypes) { + public static void modify(final Runner runner, WorkerCallBack callBack, Class configType, Class... configTypes) { WorkerFacade facade = new WorkerFacade(configType, configTypes) { @Override public void run() { diff --git a/src/main/java/com/fanruan/api/data/ConnectionKit.java b/src/main/java/com/fanruan/api/data/ConnectionKit.java index 1715ae8..14511c8 100644 --- a/src/main/java/com/fanruan/api/data/ConnectionKit.java +++ b/src/main/java/com/fanruan/api/data/ConnectionKit.java @@ -4,8 +4,6 @@ import com.fanruan.api.util.TypeKit; import com.fr.data.impl.Connection; import com.fr.data.impl.NameDatabaseConnection; import com.fr.file.ConnectionConfig; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -20,7 +18,7 @@ public class ConnectionKit { * @param name 名字 * @return 数据连接 */ - public static @Nullable Connection getConnection(@NotNull String name) { + public static Connection getConnection(String name) { return ConnectionConfig.getInstance().getConnection(name); } @@ -31,7 +29,7 @@ public class ConnectionKit { * @param type 类型 * @return 数据连接 */ - public static @Nullable T getConnection(@NotNull String name, Class type) { + public static T getConnection(String name, Class type) { Connection connection = getConnection(name); if (TypeKit.objectInstanceOf(connection, type)) { return (T) connection; diff --git a/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java b/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java index f64c325..02c82ee 100644 --- a/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java +++ b/src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java @@ -35,8 +35,8 @@ public class FineJedisPoolKitTest { }); Assert.assertNull(FineStorePool.getInstance().getResource()); - FineStore mockFineJedis = mock(FineStore.class); - expect(mockFineJedis.type(anyObject())).andReturn("TestFineJedis"); + final FineStore mockFineJedis = mock(FineStore.class); + expect(mockFineJedis.type((byte[]) anyObject())).andReturn("TestFineJedis"); EasyMock.replay(mockFineJedis); FineJedisPoolKit.setRealClient(new FineStoreWrapper() {