Class ReplyFutureMap<T>

  • Type Parameters:
    T - the type of successful reply

    public final class ReplyFutureMap<T>
    extends Object
    Orchestrate message sender and receiver using CompletableFuture for asynchronous request-reply communication.
    • Constructor Detail

      • ReplyFutureMap

        public ReplyFutureMap()
    • Method Detail

      • beforeRequest

        public CompletableFuture<T> beforeRequest​(long id)
        Called by message sender, just before a new request is sent. Note that this method should be used *before* actual message sending. Otherwise onSuccessMessage can be called before putting new future to requestIdToFuture.
        Parameters:
        id - the request id
        Returns:
        a CompletableFuture for the reply
      • onSuccessMessage

        public void onSuccessMessage​(long id,
                                     T successMessage)
        Called by message receiver, for a successful reply message.
        Parameters:
        id - the request id
        successMessage - the reply message
      • onFailure

        public void onFailure​(long id,
                              Throwable ex)
        Called for a failure in request-reply communication.
        Parameters:
        id - the request id
        ex - throwable exception