diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java index 19a8c8e8e..14e7bc179 100644 --- a/src/org/redkale/boot/NodeServer.java +++ b/src/org/redkale/boot/NodeServer.java @@ -207,7 +207,7 @@ public abstract class NodeServer { } CacheSourceService source = Sncp.createLocalService(resourceName, getExecutor(), CacheSourceService.class, this.sncpAddress, sncpDefaultGroups, sameGroupTransports, diffGroupTransports); CacheStore store = field.getAnnotation(CacheStore.class); - if (store != null) source.setStoreType(store.keyType(), store.valueType()); + if (store != null) source.setStoreType(store.keyType(), store.valueType(), store.entryType()); application.cacheSources.add(source); regFactory.register(resourceName, CacheSource.class, source); field.set(src, source); diff --git a/src/org/redkale/service/CacheSourceService.java b/src/org/redkale/service/CacheSourceService.java index 28b3cb252..952e0d1ec 100644 --- a/src/org/redkale/service/CacheSourceService.java +++ b/src/org/redkale/service/CacheSourceService.java @@ -33,7 +33,7 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { private Class storeKeyType; - private Class storeValueType; + private Type storeValueType; private ScheduledThreadPoolExecutor scheduler; @@ -46,9 +46,15 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { public CacheSourceService() { } - public CacheSourceService setStoreType(Class storeKeyType, Class storeValueType) { + public CacheSourceService setStoreType(Class storeKeyType, Class storeValueType, CacheStore.CacheEntryType entryType) { this.storeKeyType = storeKeyType; - this.storeValueType = storeValueType; + if (entryType == CacheStore.CacheEntryType.SET) { + this.storeValueType = TypeToken.createParameterizedType(null, CopyOnWriteArraySet.class, storeValueType); + } else if (entryType == CacheStore.CacheEntryType.LIST) { + this.storeValueType = TypeToken.createParameterizedType(null, CopyOnWriteArrayList.class, storeValueType); + } else { + this.storeValueType = storeValueType; + } return this; } @@ -59,10 +65,10 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { if (storeKeyType == null && prop != null) { String storeKeyStr = prop.getValue("store-key-type"); String storeValueStr = prop.getValue("store-value-type"); + String storeEntryStr = prop.getValue("store-entry-type", CacheStore.CacheEntryType.OBJECT.name()).toUpperCase(); if (storeKeyStr != null && storeValueStr != null) { try { - this.storeKeyType = Class.forName(storeKeyStr); - this.storeValueType = Class.forName(storeValueStr); + this.setStoreType(Class.forName(storeKeyStr), Class.forName(storeValueStr), CacheStore.CacheEntryType.valueOf(storeEntryStr)); } catch (Exception e) { logger.log(Level.SEVERE, self.getClass().getSimpleName() + " load key & value store class (" + storeKeyStr + ", " + storeValueStr + ") error", e); } diff --git a/src/org/redkale/source/CacheStore.java b/src/org/redkale/source/CacheStore.java index dd4f60f7e..cc53d2bf5 100644 --- a/src/org/redkale/source/CacheStore.java +++ b/src/org/redkale/source/CacheStore.java @@ -20,7 +20,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; @Retention(RUNTIME) public @interface CacheStore { + public static enum CacheEntryType { + OBJECT, SET, LIST; + } + Class keyType(); //key对应的class Class valueType(); //value 对应的class + + CacheEntryType entryType() default CacheEntryType.OBJECT; }