/** * Wrap the given {@code delegate} in an InvocationHandler that returns null when the * {@code delegate} * throws an InterruptedException. * * @param delegate The delegate to invoke, potentially throwing an InterruptedException when invoked * @param <R> The response type of the command handler * @return an InvocationHandler that wraps returns null when an InterruptedException is thrown */ protected <R> InvocationHandler<R> wrapToReturnNullOnInterrupted(final InvocationHandler<R> delegate) { return new NullOnInterrupted<>(delegate); }
@Override public Builder dispatchInterceptors( MessageDispatchInterceptor<? super CommandMessage<?>>... dispatchInterceptors) { super.dispatchInterceptors(dispatchInterceptors); return this; }
@Override public Builder commandBus(CommandBus commandBus) { super.commandBus(commandBus); return this; }
@Override public R invoke(Object proxy, Method invokedMethod, Object[] args) throws Exception { try { return delegate.invoke(proxy, invokedMethod, args); } catch (TimeoutException timeout) { return null; } } }
/** * Initializes a {@link DispatchOnInvocationHandler} as specified through this Builder. * * @return a {@link DispatchOnInvocationHandler} as specified through this Builder */ public DispatchOnInvocationHandler build() { return new DispatchOnInvocationHandler(this); } }
/** * Wraps the given {@code delegate} and waits for the result in the Future to become available. No explicit * timeout is provided for the waiting. * * @param delegate The delegate to invoke, returning a Future * @param <R> The result of the command handler * @return the result of the Future, either a return value or an exception */ protected <R> InvocationHandler<R> wrapToWaitForResult(final InvocationHandler<CompletableFuture<R>> delegate) { return new WaitForResult<>(delegate); }
/** * Initializes a {@link GatewayInvocationHandler} as specified through this Builder. * * @return a {@link GatewayInvocationHandler} as specified through this Builder */ public GatewayInvocationHandler build() { return new GatewayInvocationHandler(this); } }
/** * Wrap the given {@code delegate} in an InvocationHandler that returns null when the * {@code delegate} throws a TimeoutException. * * @param delegate The delegate to invoke, potentially throwing a TimeoutException when invoked * @param <R> The response type of the command handler * @return an InvocationHandler that wraps returns null when a TimeoutException is thrown */ protected <R> InvocationHandler<R> wrapToReturnNullOnTimeout(final InvocationHandler<R> delegate) { return new NullOnTimeout<>(delegate); }
@Override public Builder retryScheduler(RetryScheduler retryScheduler) { super.retryScheduler(retryScheduler); return this; }
@Override public Builder commandBus(CommandBus commandBus) { super.commandBus(commandBus); return this; }
/** * Instantiate a Builder to be able to create a {@link DefaultCommandGateway}. * <p> * The {@code dispatchInterceptors} are defaulted to an empty list. * The {@link CommandBus} is a <b>hard requirements</b> and as such should be provided. * * @return a Builder to be able to create a {@link DefaultCommandGateway} */ public static Builder builder() { return new Builder(); }
@Override public Registration registerDispatchInterceptor( MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor) { return super.registerDispatchInterceptor(dispatchInterceptor); }
/** * Instantiate a Builder to be able to create a {@link GatewayInvocationHandler}. * <p> * The {@code dispatchInterceptors} are defaulted to an empty list. * The {@link CommandBus} is a <b>hard requirements</b> and as such should be provided. * * @return a Builder to be able to create a {@link GatewayInvocationHandler} */ public static Builder builder() { return new Builder(); }
@Override public R invoke(Object proxy, Method invokedMethod, Object[] args) throws Exception { delegate.invoke(proxy, invokedMethod, args); return null; } }
@Override public Builder dispatchInterceptors( List<MessageDispatchInterceptor<? super CommandMessage<?>>> dispatchInterceptors) { super.dispatchInterceptors(dispatchInterceptors); return this; }
@Override public Builder commandBus(CommandBus commandBus) { super.commandBus(commandBus); return this; }
@Override public Builder retryScheduler(RetryScheduler retryScheduler) { super.retryScheduler(retryScheduler); return this; }
@Override public Builder dispatchInterceptors( MessageDispatchInterceptor<? super CommandMessage<?>>... dispatchInterceptors) { super.dispatchInterceptors(dispatchInterceptors); return this; }
@Override public Builder commandBus(CommandBus commandBus) { super.commandBus(commandBus); return this; }
@Override public Builder dispatchInterceptors( List<MessageDispatchInterceptor<? super CommandMessage<?>>> dispatchInterceptors) { super.dispatchInterceptors(dispatchInterceptors); return this; }