From 6af30bca914860765f198671b02c25ba53b9df1c Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Sat, 20 Jul 2019 16:11:56 +0300 Subject: [PATCH] RLiveObject should implement RExpirable --- .../redisson/RedissonLiveObjectService.java | 7 +------ .../java/org/redisson/api/RLiveObject.java | 20 +------------------ .../core/LiveObjectInterceptor.java | 10 +--------- .../redisson/liveobject/misc/ClassUtils.java | 3 ++- 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java index 9e7db3aa4..9d86c9495 100644 --- a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java +++ b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java @@ -751,7 +751,7 @@ public class RedissonLiveObjectService implements RLiveObjectService { } Class proxied = builder.method(ElementMatchers.isDeclaredBy( - Introspectior.getTypeDescription(RLiveObject.class)) + ElementMatchers.anyOf(RLiveObject.class, RExpirable.class, RObject.class)) .and(ElementMatchers.isGetter().or(ElementMatchers.isSetter()) .or(ElementMatchers.named("isPhantom")) .or(ElementMatchers.named("delete")))) @@ -773,11 +773,6 @@ public class RedissonLiveObjectService implements RLiveObjectService { .or(ElementMatchers.named("set")))) .intercept(MethodDelegation.to(FieldAccessorInterceptor.class)) - .method(ElementMatchers.isDeclaredBy(RObject.class) - .or(ElementMatchers.isDeclaredBy(RObjectAsync.class))) - .intercept(MethodDelegation.to(RObjectInterceptor.class)) - .implement(RObject.class) - .method(ElementMatchers.isDeclaredBy(RExpirable.class) .or(ElementMatchers.isDeclaredBy(RExpirableAsync.class))) .intercept(MethodDelegation.to(RExpirableInterceptor.class)) diff --git a/redisson/src/main/java/org/redisson/api/RLiveObject.java b/redisson/src/main/java/org/redisson/api/RLiveObject.java index e487d9f6c..37b2174ca 100644 --- a/redisson/src/main/java/org/redisson/api/RLiveObject.java +++ b/redisson/src/main/java/org/redisson/api/RLiveObject.java @@ -19,7 +19,7 @@ package org.redisson.api; * * @author Rui Gu (https://github.com/jackygurui) */ -public interface RLiveObject { +public interface RLiveObject extends RExpirable { /** * Returns the value of the field that has the RId annotation. @@ -38,22 +38,4 @@ public interface RLiveObject { */ void setLiveObjectId(Object liveObjectId); - /** - * Returns true if this object holds no other values apart from the field - * annotated with RId. This involves in invoking the isExist() method on the - * underlying RMap. Since the field with RId annotation is encoded in the - * name of the underlying RMap, so to ensure the map exist in redis, set a - * non null value to any of the other fields. - * - * @return true is object exists - * @see org.redisson.api.RMap - */ - boolean isExists(); - - /** - * Deletes the underlying RMap. - * @return true if object deleted successfully - */ - boolean delete(); - } diff --git a/redisson/src/main/java/org/redisson/liveobject/core/LiveObjectInterceptor.java b/redisson/src/main/java/org/redisson/liveobject/core/LiveObjectInterceptor.java index f677df17f..4d00c2d08 100644 --- a/redisson/src/main/java/org/redisson/liveobject/core/LiveObjectInterceptor.java +++ b/redisson/src/main/java/org/redisson/liveobject/core/LiveObjectInterceptor.java @@ -121,14 +121,6 @@ public class LiveObjectInterceptor { return namingScheme.resolveId(map.getName()); } - if ("getLiveObjectLiveMap".equals(method.getName())) { - return map; - } - - if ("isExists".equals(method.getName())) { - return map.isExists(); - } - if ("delete".equals(method.getName())) { FieldList fields = Introspectior.getFieldsWithAnnotation(me.getClass().getSuperclass(), RIndex.class); RBatch batch = redisson.createBatch(); @@ -146,7 +138,7 @@ public class LiveObjectInterceptor { return deleteFuture.getNow() > 0; } - throw new NoSuchMethodException(); + return method.invoke(map, args); } private String getMapKey(Object id) { diff --git a/redisson/src/main/java/org/redisson/liveobject/misc/ClassUtils.java b/redisson/src/main/java/org/redisson/liveobject/misc/ClassUtils.java index 64af4ec97..3b1cf5d9e 100644 --- a/redisson/src/main/java/org/redisson/liveobject/misc/ClassUtils.java +++ b/redisson/src/main/java/org/redisson/liveobject/misc/ClassUtils.java @@ -54,6 +54,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.redisson.api.RLiveObject; import org.redisson.api.RObject; import org.redisson.cache.LRUCacheMap; @@ -142,7 +143,7 @@ public class ClassUtils { private static Iterable> getClassHierarchy(Class clazz) { // Don't descend into hierarchy for RObjects - if (Arrays.asList(clazz.getInterfaces()).contains(RObject.class)) { + if (Arrays.asList(clazz.getInterfaces()).contains(RLiveObject.class)) { return Collections.>singleton(clazz); } List> classes = new ArrayList>();