This commit is contained in:
@@ -207,7 +207,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
CacheSourceService source = Sncp.createLocalService(resourceName, getExecutor(), CacheSourceService.class, this.sncpAddress, sncpDefaultGroups, sameGroupTransports, diffGroupTransports);
|
CacheSourceService source = Sncp.createLocalService(resourceName, getExecutor(), CacheSourceService.class, this.sncpAddress, sncpDefaultGroups, sameGroupTransports, diffGroupTransports);
|
||||||
CacheStore store = field.getAnnotation(CacheStore.class);
|
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);
|
application.cacheSources.add(source);
|
||||||
regFactory.register(resourceName, CacheSource.class, source);
|
regFactory.register(resourceName, CacheSource.class, source);
|
||||||
field.set(src, source);
|
field.set(src, source);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable {
|
|||||||
|
|
||||||
private Class storeKeyType;
|
private Class storeKeyType;
|
||||||
|
|
||||||
private Class storeValueType;
|
private Type storeValueType;
|
||||||
|
|
||||||
private ScheduledThreadPoolExecutor scheduler;
|
private ScheduledThreadPoolExecutor scheduler;
|
||||||
|
|
||||||
@@ -46,9 +46,15 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable {
|
|||||||
public CacheSourceService() {
|
public CacheSourceService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheSourceService setStoreType(Class storeKeyType, Class storeValueType) {
|
public CacheSourceService setStoreType(Class storeKeyType, Class storeValueType, CacheStore.CacheEntryType entryType) {
|
||||||
this.storeKeyType = storeKeyType;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,10 +65,10 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable {
|
|||||||
if (storeKeyType == null && prop != null) {
|
if (storeKeyType == null && prop != null) {
|
||||||
String storeKeyStr = prop.getValue("store-key-type");
|
String storeKeyStr = prop.getValue("store-key-type");
|
||||||
String storeValueStr = prop.getValue("store-value-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) {
|
if (storeKeyStr != null && storeValueStr != null) {
|
||||||
try {
|
try {
|
||||||
this.storeKeyType = Class.forName(storeKeyStr);
|
this.setStoreType(Class.forName(storeKeyStr), Class.forName(storeValueStr), CacheStore.CacheEntryType.valueOf(storeEntryStr));
|
||||||
this.storeValueType = Class.forName(storeValueStr);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, self.getClass().getSimpleName() + " load key & value store class (" + storeKeyStr + ", " + storeValueStr + ") error", e);
|
logger.log(Level.SEVERE, self.getClass().getSimpleName() + " load key & value store class (" + storeKeyStr + ", " + storeValueStr + ") error", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface CacheStore {
|
public @interface CacheStore {
|
||||||
|
|
||||||
|
public static enum CacheEntryType {
|
||||||
|
OBJECT, SET, LIST;
|
||||||
|
}
|
||||||
|
|
||||||
Class keyType(); //key对应的class
|
Class keyType(); //key对应的class
|
||||||
|
|
||||||
Class valueType(); //value 对应的class
|
Class valueType(); //value 对应的class
|
||||||
|
|
||||||
|
CacheEntryType entryType() default CacheEntryType.OBJECT;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user