Search in sources :

Example 1 with CodecProvider

use of org.redisson.codec.CodecProvider in project redisson by redisson.

the class RedissonObjectFactory method fromReference.

public static <T> T fromReference(RedissonReactiveClient redisson, RedissonReference rr, Class<?> expected) throws Exception {
    Class<? extends Object> type = rr.getReactiveType();
    CodecProvider codecProvider = redisson.getConfig().getCodecProvider();
    /**
         * Live Object from reference in reactive client is not supported yet.
         */
    if (type != null) {
        List<Class<?>> interfaces = Arrays.asList(type.getInterfaces());
        for (Class<?> iType : interfaces) {
            if (builders.containsKey(iType)) {
                // user cache to speed up things a little.
                Method builder = builders.get(iType).get(isDefaultCodec(rr));
                return (T) (isDefaultCodec(rr) ? builder.invoke(redisson, rr.getKeyName()) : builder.invoke(redisson, rr.getKeyName(), codecProvider.getCodec(rr.getCodecType())));
            }
        }
    }
    throw new ClassNotFoundException("No RObjectReactive is found to match class type of " + rr.getReactiveTypeName() + " with codec type of " + rr.getCodecName());
}
Also used : CodecProvider(org.redisson.codec.CodecProvider) Method(java.lang.reflect.Method)

Example 2 with CodecProvider

use of org.redisson.codec.CodecProvider in project redisson by redisson.

the class RedissonObjectFactory method fromReference.

public static <T> T fromReference(RedissonClient redisson, RedissonReference rr) throws Exception {
    Class<? extends Object> type = rr.getType();
    CodecProvider codecProvider = redisson.getConfig().getCodecProvider();
    if (type != null) {
        if (type.isAnnotationPresent(REntity.class)) {
            RLiveObjectService liveObjectService = redisson.getLiveObjectService();
            REntity anno = type.getAnnotation(REntity.class);
            NamingScheme ns = anno.namingScheme().getDeclaredConstructor(Codec.class).newInstance(codecProvider.getCodec(anno, type));
            return (T) liveObjectService.get(type, ns.resolveId(rr.getKeyName()));
        }
        List<Class<?>> interfaces = Arrays.asList(type.getInterfaces());
        for (Class<?> iType : interfaces) {
            if (builders.containsKey(iType)) {
                // user cache to speed up things a little.
                Method builder = builders.get(iType).get(isDefaultCodec(rr));
                return (T) (isDefaultCodec(rr) ? builder.invoke(redisson, rr.getKeyName()) : builder.invoke(redisson, rr.getKeyName(), codecProvider.getCodec(rr.getCodecType())));
            }
        }
    }
    throw new ClassNotFoundException("No RObject is found to match class type of " + rr.getTypeName() + " with codec type of " + rr.getCodecName());
}
Also used : CodecProvider(org.redisson.codec.CodecProvider) Codec(org.redisson.client.codec.Codec) REntity(org.redisson.api.annotation.REntity) NamingScheme(org.redisson.liveobject.resolver.NamingScheme) Method(java.lang.reflect.Method) RLiveObjectService(org.redisson.api.RLiveObjectService)

Aggregations

Method (java.lang.reflect.Method)2 CodecProvider (org.redisson.codec.CodecProvider)2 RLiveObjectService (org.redisson.api.RLiveObjectService)1 REntity (org.redisson.api.annotation.REntity)1 Codec (org.redisson.client.codec.Codec)1 NamingScheme (org.redisson.liveobject.resolver.NamingScheme)1