Search in sources :

Example 1 with ClassTypeInformation

use of io.lettuce.core.dynamic.support.ClassTypeInformation in project lettuce-core by lettuce-io.

the class OutputRegistry method getOutputComponentType.

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

        @Override
        public ResolvableType withCodec(RedisCodec<?, ?> codec) {
            TypeInformation<?> typeInformation = ClassTypeInformation.from(codec.getClass());
            ResolvableType resolvableType = ResolvableType.forType(commandOutputClass, new CodecVariableTypeResolver(typeInformation));
            while (!resolvableType.getRawClass().equals(CommandOutput.class)) {
                resolvableType = resolvableType.getSuperType();
            }
            return resolvableType.getGeneric(2);
        }
    };
}
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)

Example 2 with ClassTypeInformation

use of io.lettuce.core.dynamic.support.ClassTypeInformation 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)2 ClassTypeInformation (io.lettuce.core.dynamic.support.ClassTypeInformation)2 ResolvableType (io.lettuce.core.dynamic.support.ResolvableType)2 TypeInformation (io.lettuce.core.dynamic.support.TypeInformation)2