/** * Initializes a {@link DefaultCommandGateway} as specified through this Builder. * * @return a {@link DefaultCommandGateway} as specified through this Builder */ public DefaultCommandGateway build() { return new DefaultCommandGateway(this); } }
@ConditionalOnMissingBean @Bean public CommandGateway commandGateway(CommandBus commandBus) { return DefaultCommandGateway.builder().commandBus(commandBus).build(); }
/** * 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(); }
@Override public <R> CompletableFuture<R> send(Object command) { FutureCallback<Object, R> callback = new FutureCallback<>(); send(command, new FailureLoggingCallback<>(logger, callback)); CompletableFuture<R> result = new CompletableFuture<>(); callback.exceptionally(GenericCommandResultMessage::asCommandResultMessage) .thenAccept(r -> { try { if (r.isExceptional()) { result.completeExceptionally(r.exceptionResult()); } else { result.complete(r.getPayload()); } } catch (Exception e) { result.completeExceptionally(e); } }); return result; }
@Override public <R> CompletableFuture<R> send(Object command) { FutureCallback<Object, R> callback = new FutureCallback<>(); send(command, new FailureLoggingCallback<>(logger, callback)); return callback; } }
/** * Returns the CommandGateway used to send commands to command handlers. * * @param commandBus the command bus to be used by the gateway * @return the CommandGateway used to send commands to command handlers */ @NoBeanOfType(CommandGateway.class) @Bean public CommandGateway commandGateway(CommandBus commandBus) { return DefaultCommandGateway.builder().commandBus(commandBus).build(); }
/** * Initializes a {@link DefaultCommandGateway} as specified through this Builder. * * @return a {@link DefaultCommandGateway} as specified through this Builder */ public DefaultCommandGateway build() { return new DefaultCommandGateway(this); } }
/** * 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, Object> futureCallback = new FutureCallback<>(); send(command, futureCallback); return (R) futureCallback.getResult(); }
/** * Returns a {@link DefaultCommandGateway} that will use the configuration's {@link CommandBus} to dispatch * commands. * * @param config The configuration that supplies the command bus. * @return The default command gateway. */ protected CommandGateway defaultCommandGateway(Configuration config) { return DefaultCommandGateway.builder().commandBus(config.commandBus()).build(); }
@Override public DefaultCommandGateway get() { return new DefaultCommandGateway(commandBus); } }
/** * 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, Object> futureCallback = new FutureCallback<>(); send(command, futureCallback); return (R) futureCallback.getResult(timeout, unit); }
/** * Creates an instance of the AnnotatedSagaTestFixture to test sagas of the given {@code sagaType}. * * @param sagaType The type of saga under test */ @SuppressWarnings({"unchecked"}) public SagaTestFixture(Class<T> sagaType) { this.sagaType = sagaType; eventScheduler = new StubEventScheduler(); deadlineManager = new StubDeadlineManager(); eventBus = SimpleEventBus.builder().build(); sagaStore = new InMemorySagaStore(); registeredResources.add(eventBus); commandBus = new RecordingCommandBus(); registeredResources.add(commandBus); registeredResources.add(eventScheduler); registeredResources.add(deadlineManager); registeredResources.add(DefaultCommandGateway.builder().commandBus(commandBus).build()); fixtureExecutionResult = new FixtureExecutionResultImpl<>(sagaStore, eventScheduler, deadlineManager, eventBus, commandBus, sagaType, fieldFilters); handlerDefinition = ClasspathHandlerDefinition.forClass(sagaType); }
@Bean public CommandGateway commandGateway(CommandBus commandBus) { return new DefaultCommandGateway(commandBus); }
/** * 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(); }
@Override public <R> CompletableFuture<R> send(Object command) { FutureCallback<Object, R> callback = new FutureCallback<>(); send(command, new FailureLoggingCallback<>(logger, callback)); return callback.thenApply(Message::getPayload); }
final Thread testThread = Thread.currentThread(); commandGateway = DefaultCommandGateway.builder() .commandBus(commandBus) .retryScheduler(retryScheduler)
/** * Returns a {@link DefaultCommandGateway} that will use the configuration's {@link CommandBus} to dispatch * commands. * * @param config The configuration that supplies the command bus. * @return The default command gateway. */ protected CommandGateway defaultCommandGateway(Configuration config) { return new DefaultCommandGateway(config.commandBus()); }
public void testCommandBusDispatchInterceptorMetaDataIsNotPreservedOnRetry() { final Thread testThread = Thread.currentThread(); commandGateway = DefaultCommandGateway.builder() .commandBus(commandBus) .retryScheduler(retryScheduler)