use of io.lettuce.core.dynamic.support.ResolvableType in project lettuce-core by lettuce-io.
the class LettuceExtension method findSupplier.
@SuppressWarnings("unchecked")
private static Supplier<Object> findSupplier(Type type) {
ResolvableType requested = ResolvableType.forType(type);
Supplier<?> supplier = SUPPLIERS.stream().filter(it -> {
ResolvableType providedType = ResolvableType.forType(it.getClass()).as(Supplier.class).getGeneric(0);
if (requested.isAssignableFrom(providedType)) {
return true;
}
return false;
}).findFirst().orElseThrow(() -> new NoSuchElementException("Cannot find a factory for " + type));
return (Supplier) supplier;
}
use of io.lettuce.core.dynamic.support.ResolvableType in project lettuce-core by lettuce-io.
the class CommandOutputResolverSupport method isAssignableFrom.
/**
* Overridable hook to check whether {@code selector} can be assigned from the provider type {@code provider}.
* <p>
* This method descends the component type hierarchy and considers primitive/wrapper type conversion.
*
* @param selector must not be {@code null}.
* @param provider must not be {@code null}.
* @return {@code true} if selector can be assigned from its provider type.
*/
protected boolean isAssignableFrom(OutputSelector selector, OutputType provider) {
ResolvableType selectorType = selector.getOutputType();
ResolvableType resolvableType = provider.withCodec(selector.getRedisCodec());
return selectorType.isAssignableFrom(resolvableType);
}
use of io.lettuce.core.dynamic.support.ResolvableType 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);
}
};
}
use of io.lettuce.core.dynamic.support.ResolvableType in project lettuce-core by lettuce-io.
the class OutputRegistryUnitTests method customizedValueOutput.
@Test
void customizedValueOutput() {
OutputType outputComponentType = OutputRegistry.getOutputComponentType(KeyTypedOutput.class);
ResolvableType resolvableType = outputComponentType.withCodec(ByteArrayCodec.INSTANCE);
assertThat(resolvableType.isAssignableFrom(ResolvableType.forClass(byte[].class))).isTrue();
}
use of io.lettuce.core.dynamic.support.ResolvableType in project lettuce-core by lettuce-io.
the class OutputRegistryUnitTests method streamingTypeOfKeyListOuputWithCodecIsAssignableFromListOfString.
@Test
void streamingTypeOfKeyListOuputWithCodecIsAssignableFromListOfString() {
OutputType outputComponentType = OutputRegistry.getStreamingType(ScoredValueListOutput.class);
ResolvableType resolvableType = outputComponentType.withCodec(new StringCodec());
assertThat(resolvableType.isAssignableFrom(ResolvableType.forClassWithGenerics(ScoredValue.class, String.class))).isTrue();
}
Aggregations