Browse Source

Merge branch 'master' of Dylan.Liu/finekit into master

master
richie 5 years ago committed by Gogs
parent
commit
141d939c65
  1. 4
      src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java
  2. 5
      src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java
  3. 9
      src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java
  4. 8
      src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java
  5. 49
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  6. 6
      src/main/java/com/fanruan/api/data/ConnectionKit.java
  7. 22
      src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java
  8. 4
      src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java

4
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() {

5
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);

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

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

49
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<? extends Configuration> configType, Runner runner) {
public static void modify(Class<? extends Configuration> configType, final Runner runner) {
Configurations.modify(new WorkerFacade(configType) {
@Override
public void run() {
@ -60,6 +60,26 @@ public class ConfigurationKit {
});
}
/**
* 在一个事务中修改配置
* 支持 configType, configTypes 缓存失效
*
* @param configType 配置类
* @param runner 执行器
* @param configTypes 配置类(所有的配置类都会缓存失效)
*/
public static void modify(final Runner runner, Class<? extends Configuration> configType, Class<? extends Configuration>... configTypes) {
Configurations.modify(new WorkerFacade(configType, configTypes) {
@Override
public void run() {
if (runner != null) {
runner.run();
}
}
});
}
/**
* 在一个事务中修改配置
*
@ -67,7 +87,7 @@ public class ConfigurationKit {
* @param runner 执行器
* @param callBack 事务回调
*/
public static void modify(Class<? extends Configuration> configType, Runner runner, WorkerCallBack callBack) {
public static void modify(Class<? extends Configuration> configType, final Runner runner, WorkerCallBack callBack) {
WorkerFacade facade = new WorkerFacade(configType) {
@Override
public void 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(final Runner runner, WorkerCallBack callBack, Class<? extends Configuration> configType, Class<? extends Configuration>... 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);
}
}

6
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 <T extends Connection> @Nullable T getConnection(@NotNull String name, Class<? extends Connection> type) {
public static <T extends Connection>T getConnection(String name, Class<? extends Connection> type) {
Connection connection = getConnection(name);
if (TypeKit.objectInstanceOf(connection, type)) {
return (T) connection;

22
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);
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 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[]{}));
}
}

4
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[]{}));
}

Loading…
Cancel
Save