@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass().isAssignableFrom(getClass())) {
try {
return method.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
CommandMethodMapping mapper = commandMappers.get(method);
Preconditions.checkState(mapper != null, "No mapper found for method %s", method);
try {
return commandOutChannel.apply(mapper.mapArguments(args))
.thenApply(result -> result.orElse(null))
.get(timeoutMs, MILLISECONDS);
} catch (ExecutionException e) {
throw new CommandExecutionException(e.getCause());
} catch (InterruptedException | TimeoutException e) {
throw new CommandExecutionException(e);
}
}
}