use of io.lettuce.core.dynamic.parameter.ExecutionSpecificParameters in project lettuce-core by lettuce-io.
the class AsyncExecutableCommand method dispatchCommand.
protected Object dispatchCommand(Object[] arguments, RedisCommand<Object, Object, Object> command) throws InterruptedException, java.util.concurrent.ExecutionException {
AsyncCommand<Object, Object, Object> asyncCommand = new AsyncCommand<>(command);
if (commandMethod.isFutureExecution()) {
RedisCommand<Object, Object, Object> dispatched = connection.dispatch(asyncCommand);
if (dispatched instanceof AsyncCommand) {
return dispatched;
}
return asyncCommand;
}
connection.dispatch(asyncCommand);
Duration timeout = connection.getTimeout();
if (commandMethod.getParameters() instanceof ExecutionSpecificParameters) {
ExecutionSpecificParameters executionSpecificParameters = (ExecutionSpecificParameters) commandMethod.getParameters();
if (executionSpecificParameters.hasTimeoutIndex()) {
Timeout timeoutArg = (Timeout) arguments[executionSpecificParameters.getTimeoutIndex()];
if (timeoutArg != null) {
timeout = timeoutArg.getTimeout();
}
}
}
Futures.await(timeout, asyncCommand);
return asyncCommand.get();
}
use of io.lettuce.core.dynamic.parameter.ExecutionSpecificParameters in project lettuce-core by lettuce-io.
the class BatchExecutableCommandLookupStrategy method resolveCommandMethod.
@Override
public ExecutableCommand resolveCommandMethod(CommandMethod method, RedisCommandsMetadata metadata) {
LettuceAssert.isTrue(!method.isReactiveExecution(), () -> String.format("Command method %s not supported by this command lookup strategy", method));
ExecutionSpecificParameters parameters = (ExecutionSpecificParameters) method.getParameters();
if (parameters.hasTimeoutIndex()) {
throw new IllegalArgumentException(String.format("Timeout and batching is not supported, offending command method %s ", method));
}
if (isForceFlush(method)) {
return new ExecutableCommand() {
@Override
public Object execute(Object[] parameters) throws ExecutionException, InterruptedException {
BatchExecutableCommand.synchronize(batcher.flush(), connection);
return null;
}
@Override
public CommandMethod getCommandMethod() {
return method;
}
};
}
if (method.isFutureExecution() || SYNCHRONOUS_RETURN_TYPES.contains(method.getReturnType().getRawClass())) {
CommandFactory commandFactory = super.resolveCommandFactory(method, metadata);
return new BatchExecutableCommand(method, commandFactory, batcher, connection);
}
throw new IllegalArgumentException(String.format("Batching command method %s must declare either a Future or void return type", method));
}
Aggregations