From f269919329c5cb387dd1ebcaab4d6a2f235a6358 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 16 Jul 2018 12:04:03 +0300 Subject: [PATCH] Fixed - Redis response hangs if LiveObject stored as nested object. --- .../java/org/redisson/RedissonLiveObjectService.java | 9 +++++++++ .../java/org/redisson/misc/RedissonObjectFactory.java | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java index 5c5bbab13..0e0bf7572 100644 --- a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java +++ b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java @@ -127,6 +127,15 @@ public class RedissonLiveObjectService implements RLiveObjectService { return providerCache.get(resolverClass); } + public T createLiveObject(Class entityClass, K id) { + try { + return instantiateLiveObject(getProxyClass(entityClass), id); + } catch (Exception ex) { + unregisterClass(entityClass); + throw ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex); + } + } + @Override public T get(Class entityClass, K id) { try { diff --git a/redisson/src/main/java/org/redisson/misc/RedissonObjectFactory.java b/redisson/src/main/java/org/redisson/misc/RedissonObjectFactory.java index 23f751373..d18849cea 100644 --- a/redisson/src/main/java/org/redisson/misc/RedissonObjectFactory.java +++ b/redisson/src/main/java/org/redisson/misc/RedissonObjectFactory.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.redisson.RedissonLiveObjectService; import org.redisson.RedissonReference; import org.redisson.api.RLiveObject; import org.redisson.api.RLiveObjectService; @@ -106,12 +107,13 @@ public class RedissonObjectFactory { ReferenceCodecProvider codecProvider = redisson.getConfig().getReferenceCodecProvider(); if (type != null) { if (ClassUtils.isAnnotationPresent(type, REntity.class)) { - RLiveObjectService liveObjectService = redisson.getLiveObjectService(); + RedissonLiveObjectService liveObjectService = (RedissonLiveObjectService) redisson.getLiveObjectService(); REntity anno = ClassUtils.getAnnotation(type, REntity.class); NamingScheme ns = anno.namingScheme() .getDeclaredConstructor(Codec.class) .newInstance(codecProvider.getCodec(anno, type)); - return (T) liveObjectService.get(type, ns.resolveId(rr.getKeyName())); + Object id = ns.resolveId(rr.getKeyName()); + return (T) liveObjectService.createLiveObject(type, id); } List> interfaces = Arrays.asList(type.getInterfaces()); for (Class iType : interfaces) {