cached包重命名
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -13,17 +13,17 @@ import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cache.Cached;
|
||||
import org.redkale.cached.Cached;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.Range;
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheInstance implements Service {
|
||||
public class CachedInstance implements Service {
|
||||
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
private CachedManager cacheManager;
|
||||
|
||||
// 修改远程缓存的key值
|
||||
public void updateName(String code, Map<String, Long> map) {
|
||||
@@ -80,7 +80,7 @@ public class CacheInstance implements Service {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
public CachedManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cache.spi.CacheAsmMethodBoost;
|
||||
import org.redkale.cache.spi.CacheManagerService;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.cached.spi.CachedAsmMethodBoost;
|
||||
import org.redkale.cached.spi.CachedManagerService;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.net.AsyncGroup;
|
||||
import org.redkale.net.client.ClientAddress;
|
||||
@@ -21,18 +21,18 @@ import org.redkale.util.Environment;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheInstanceTest {
|
||||
public class CachedInstanceTest {
|
||||
|
||||
private static ResourceFactory resourceFactory;
|
||||
|
||||
private static CacheManagerService manager;
|
||||
private static CachedManagerService manager;
|
||||
|
||||
private static ResourceFactory resourceFactory2;
|
||||
|
||||
private static CacheManagerService manager2;
|
||||
private static CachedManagerService manager2;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CacheInstanceTest test = new CacheInstanceTest();
|
||||
CachedInstanceTest test = new CachedInstanceTest();
|
||||
init();
|
||||
test.run1();
|
||||
test.run2();
|
||||
@@ -45,30 +45,30 @@ public class CacheInstanceTest {
|
||||
remoteSource.init(null);
|
||||
resourceFactory = ResourceFactory.create();
|
||||
resourceFactory.register(new Environment());
|
||||
manager = CacheManagerService.create(remoteSource);
|
||||
manager = CachedManagerService.create(remoteSource);
|
||||
manager.init(null);
|
||||
resourceFactory.register("", CacheManager.class, manager);
|
||||
resourceFactory.register("", CachedManager.class, manager);
|
||||
|
||||
resourceFactory2 = ResourceFactory.create();
|
||||
resourceFactory2.register(new Environment());
|
||||
manager2 = CacheManagerService.create(remoteSource);
|
||||
manager2 = CachedManagerService.create(remoteSource);
|
||||
manager2.init(null);
|
||||
resourceFactory2.register("", CacheManager.class, manager2);
|
||||
resourceFactory2.register("", CachedManager.class, manager2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
Class<CacheInstance> serviceClass = CacheInstance.class;
|
||||
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass);
|
||||
CacheAsmMethodBoost boost2 = new CacheAsmMethodBoost(false, serviceClass);
|
||||
Class<CachedInstance> serviceClass = CachedInstance.class;
|
||||
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
|
||||
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
|
||||
SncpRpcGroups grous = new SncpRpcGroups();
|
||||
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CacheInstance instance = Sncp.createLocalService(
|
||||
CachedInstance instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
resourceFactory.inject(instance);
|
||||
CacheInstance instance2 = Sncp.createLocalService(
|
||||
CachedInstance instance2 = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
|
||||
resourceFactory2.inject(instance2);
|
||||
System.out.println(instance.getName2());
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.cache.spi.CacheManagerService;
|
||||
import org.redkale.cached.spi.CachedManagerService;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheManagerTest {
|
||||
public class CachedManagerTest {
|
||||
|
||||
private static CacheManagerService manager;
|
||||
private static CachedManagerService manager;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CacheManagerTest test = new CacheManagerTest();
|
||||
CachedManagerTest test = new CachedManagerTest();
|
||||
init();
|
||||
test.run1();
|
||||
test.run2();
|
||||
@@ -28,7 +28,7 @@ public class CacheManagerTest {
|
||||
public static void init() throws Exception {
|
||||
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
|
||||
remoteSource.init(null);
|
||||
manager = CacheManagerService.create(remoteSource);
|
||||
manager = CachedManagerService.create(remoteSource);
|
||||
manager.init(null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,39 +11,39 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.cache.spi.CacheAction;
|
||||
import org.redkale.cache.spi.DynForCache;
|
||||
import org.redkale.cached.spi.CachedAction;
|
||||
import org.redkale.net.sncp.Sncp.SncpDyn;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.RedkaleException;
|
||||
import org.redkale.util.ThrowSupplier;
|
||||
import org.redkale.cached.spi.DynForCached;
|
||||
|
||||
@Resource(name = "")
|
||||
@SncpDyn(remote = false, type = CacheInstance.class)
|
||||
@ResourceType(CacheInstance.class)
|
||||
public class _DynLocalCacheInstance extends CacheInstance {
|
||||
@SncpDyn(remote = false, type = CachedInstance.class)
|
||||
@ResourceType(CachedInstance.class)
|
||||
public class _DynLocalCacheInstance extends CachedInstance {
|
||||
|
||||
private AnyValue _redkale_conf;
|
||||
|
||||
private String _redkale_mq;
|
||||
|
||||
private CacheAction _redkale_getNameCacheAction1;
|
||||
private CachedAction _redkale_getNameCacheAction1;
|
||||
|
||||
private CacheAction _redkale_getInfoCacheAction2;
|
||||
private CachedAction _redkale_getInfoCacheAction2;
|
||||
|
||||
private CacheAction _redkale_getNameAsyncCacheAction3;
|
||||
private CachedAction _redkale_getNameAsyncCacheAction3;
|
||||
|
||||
private CacheAction _redkale_getInfo2AsyncCacheAction4;
|
||||
private CachedAction _redkale_getInfo2AsyncCacheAction4;
|
||||
|
||||
private CacheAction _redkale_getName2AsyncCacheAction5;
|
||||
private CachedAction _redkale_getName2AsyncCacheAction5;
|
||||
|
||||
private CacheAction _redkale_getInfoAsyncCacheAction6;
|
||||
private CachedAction _redkale_getInfoAsyncCacheAction6;
|
||||
|
||||
private CacheAction _redkale_getName2CacheAction7;
|
||||
private CachedAction _redkale_getName2CacheAction7;
|
||||
|
||||
public _DynLocalCacheInstance() {}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getNameCacheAction1",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -60,7 +60,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfoCacheAction2",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -68,17 +68,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public File getInfo(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
public File getInfo(CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<File> supplier = () -> this.getInfo_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoCacheAction2.get(supplier);
|
||||
}
|
||||
|
||||
private File getInfo_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfo(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getNameAsyncCacheAction3",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -95,7 +95,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getNameAsync();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfo2AsyncCacheAction4",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -104,7 +104,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier =
|
||||
() -> this.getInfo2Async_afterCache(bean, id, idList, files);
|
||||
@@ -112,12 +112,12 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
}
|
||||
|
||||
private CompletableFuture<Map<String, Integer>> getInfo2Async_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
return super.getInfo2Async(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getName2AsyncCacheAction5",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -134,7 +134,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName2Async();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfoAsyncCacheAction6",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -143,17 +143,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<File> getInfoAsync(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<CompletableFuture<File>> supplier = () -> this.getInfoAsync_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoAsyncCacheAction6.get(supplier, bean, id, idList, files);
|
||||
}
|
||||
|
||||
private CompletableFuture<File> getInfoAsync_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfoAsync(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getName2CacheAction7",
|
||||
hash = "",
|
||||
key = "name",
|
||||
Reference in New Issue
Block a user