/** * Sends the given {@code command} and waits for its execution to complete, or until the waiting thread is * interrupted. * * @param command The command to send * @param <R> The expected type of return value * @return The result of the command handler execution * @throws org.axonframework.commandhandling.CommandExecutionException when command execution threw a checked * exception */ @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); }
/** * Sends the given {@code command} and waits for its execution to complete, or until the given * {@code timeout} has expired, or the waiting thread is interrupted. * <p/> * When the timeout occurs, or the thread is interrupted, this method returns {@code null}. * * @param command The command to send * @param timeout The maximum time to wait * @param unit The time unit of the timeout argument * @param <R> The expected type of return value * @return The result of the command handler execution * @throws org.axonframework.commandhandling.CommandExecutionException when command execution threw a checked * exception */ @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command, long timeout, TimeUnit unit) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(timeout, unit); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); }
/** * Sends the given {@code command} and waits for its execution to complete, or until the waiting thread is * interrupted. * * @param command The command to send * @param <R> The expected type of return value * @return The result of the command handler execution * * @throws org.axonframework.commandhandling.CommandExecutionException when command execution threw a checked * exception */ @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); }
/** * Sends the given {@code command} and waits for its execution to complete, or until the given * {@code timeout} has expired, or the waiting thread is interrupted. * <p/> * When the timeout occurs, or the thread is interrupted, this method returns {@code null}. * * @param command The command to send * @param timeout The maximum time to wait * @param unit The time unit of the timeout argument * @param <R> The expected type of return value * @return The result of the command handler execution * * @throws org.axonframework.commandhandling.CommandExecutionException when command execution threw a checked * exception */ @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command, long timeout, TimeUnit unit) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(timeout, unit); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); }