Class ReplyFutureMap<T>

  • Type Parameters:
    T - the type of successful reply

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

      Constructors 
      Constructor Description
      ReplyFutureMap()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<T> beforeRequest​(long id)
      Called by message sender, just before a new request is sent.
      void onFailure​(long id, java.lang.Throwable ex)
      Called for a failure in request-reply communication.
      void onSuccessMessage​(long id, T successMessage)
      Called by message receiver, for a successful reply message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReplyFutureMap

        public ReplyFutureMap()
    • Method Detail

      • beforeRequest

        public java.util.concurrent.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,
                              java.lang.Throwable ex)
        Called for a failure in request-reply communication.
        Parameters:
        id - the request id
        ex - throwable exception