Search in sources :

Example 6 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project lettuce-core by lettuce-io.

the class OutputRegistry method getStreamingType.

/**
 * Retrieve {@link OutputType} for a {@link StreamingOutput} type.
 *
 * @param commandOutputClass
 * @return
 */
@SuppressWarnings("rawtypes")
static OutputType getStreamingType(Class<? extends CommandOutput> commandOutputClass) {
    ClassTypeInformation<? extends CommandOutput> classTypeInformation = ClassTypeInformation.from(commandOutputClass);
    TypeInformation<?> superTypeInformation = classTypeInformation.getSuperTypeInformation(StreamingOutput.class);
    if (superTypeInformation == null) {
        return null;
    }
    List<TypeInformation<?>> typeArguments = superTypeInformation.getTypeArguments();
    return new OutputType(commandOutputClass, typeArguments.get(0), true) {

        @Override
        public ResolvableType withCodec(RedisCodec<?, ?> codec) {
            TypeInformation<?> typeInformation = ClassTypeInformation.from(codec.getClass());
            ResolvableType resolvableType = ResolvableType.forType(commandOutputClass, new CodecVariableTypeResolver(typeInformation));
            while (resolvableType != ResolvableType.NONE) {
                ResolvableType[] interfaces = resolvableType.getInterfaces();
                for (ResolvableType resolvableInterface : interfaces) {
                    if (resolvableInterface.getRawClass().equals(StreamingOutput.class)) {
                        return resolvableInterface.getGeneric(0);
                    }
                }
                resolvableType = resolvableType.getSuperType();
            }
            throw new IllegalStateException();
        }
    };
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) ResolvableType(io.lettuce.core.dynamic.support.ResolvableType) ClassTypeInformation(io.lettuce.core.dynamic.support.ClassTypeInformation) TypeInformation(io.lettuce.core.dynamic.support.TypeInformation)

Aggregations

RedisCodec (io.lettuce.core.codec.RedisCodec)6 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)3 StringCodec (io.lettuce.core.codec.StringCodec)3 Futures (io.lettuce.core.internal.Futures)3 LettuceAssert (io.lettuce.core.internal.LettuceAssert)3 CommandExpiryWriter (io.lettuce.core.protocol.CommandExpiryWriter)3 CommandHandler (io.lettuce.core.protocol.CommandHandler)3 DefaultEndpoint (io.lettuce.core.protocol.DefaultEndpoint)3 PushHandler (io.lettuce.core.protocol.PushHandler)3 PubSubCommandHandler (io.lettuce.core.pubsub.PubSubCommandHandler)3 PubSubEndpoint (io.lettuce.core.pubsub.PubSubEndpoint)3 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)3 StatefulRedisPubSubConnectionImpl (io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl)3 ClientResources (io.lettuce.core.resource.ClientResources)3 InternalLogger (io.netty.util.internal.logging.InternalLogger)3 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)3 SocketAddress (java.net.SocketAddress)3 Duration (java.time.Duration)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3