Class ReplyCollector

  • All Implemented Interfaces:
    CallableClient
    Direct Known Subclasses:
    HubTester.TestCallableClient

    abstract class ReplyCollector
    extends java.lang.Object
    implements CallableClient
    Partial implementation of CallableClient which handles the receiveReply method. This takes care of matching up replies with calls and is intended for use with test classes. Some assertions are made within this class to check that replies match with messages sent. Call-type messages must be sent using this object's call and callAll methods, rather than directly on the HubConnection, to ensure that the internal state stays correct.
    Since:
    18 Jul 2008
    Author:
    Mark Taylor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String call​(java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg)
      Performs a call method on this collector's hub connection.
      java.util.Map callAll​(java.lang.String msgTag, java.util.Map msg)
      Performs a callAll method on this collector's hub connection.
      private static java.lang.Object createKey​(java.lang.String recipientId, java.lang.String msgTag)
      Returns an opaque object suitable for use as a map key based on a recipient ID and message tag.
      Response getReply​(java.lang.String responderId, java.lang.String msgTag)
      Gets the reply to a message sent earlier using call or callAll.
      int getReplyCount()
      Returns the total number of unretrieved replies so far collected by this object.
      void receiveResponse​(java.lang.String responderId, java.lang.String msgTag, Response response)
      Receives a response to a message previously sent by this client.
      void setAllowTagReuse​(boolean allow)
      Determines whether clients are permitted to reuse tags for different messages.
      Response waitForReply​(java.lang.String responderId, java.lang.String msgTag)
      Waits for a reply to a message sent earlier using call or callAll.
      • Methods inherited from class java.lang.Object

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

      • sentSet_

        private final java.util.Set sentSet_
      • replyMap_

        private final java.util.Map replyMap_
      • allowTagReuse_

        private boolean allowTagReuse_
    • Constructor Detail

      • ReplyCollector

        public ReplyCollector​(HubConnection connection)
        Constructor.
        Parameters:
        connection - hub connection
        allowTagReuse - if true clients may reuse tags; if false any such attempt generates an exception
    • Method Detail

      • setAllowTagReuse

        public void setAllowTagReuse​(boolean allow)
        Determines whether clients are permitted to reuse tags for different messages. If true, any such attempt generates an exception.
        Parameters:
        allow - whether to allow tag reuse
      • call

        public java.lang.String call​(java.lang.String recipientId,
                                     java.lang.String msgTag,
                                     java.util.Map msg)
                              throws SampException
        Performs a call method on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, the msgTag must not be one which was used earlier for the same recipient.
        Parameters:
        recipientId - public-id of client to receive message
        msgTag - arbitrary string tagging this message for caller's benefit
        msg - Message-like map
        Returns:
        message ID
        Throws:
        SampException
      • callAll

        public java.util.Map callAll​(java.lang.String msgTag,
                                     java.util.Map msg)
                              throws SampException
        Performs a callAll method on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, the msgTag must not be one which was used for an earlier broadcast.
        Parameters:
        msgTag - arbitrary string tagging this message for caller's benefit
        msg - Message-like map
        Returns:
        message ID
        Throws:
        SampException
      • receiveResponse

        public void receiveResponse​(java.lang.String responderId,
                                    java.lang.String msgTag,
                                    Response response)
        Description copied from interface: CallableClient
        Receives a response to a message previously sent by this client.
        Specified by:
        receiveResponse in interface CallableClient
        Parameters:
        responderId - public ID of responding client
        msgTag - client-defined tag labelling previously-sent message
        response - returned response object
      • getReplyCount

        public int getReplyCount()
        Returns the total number of unretrieved replies so far collected by this object.
        Returns:
        reply count
      • waitForReply

        public Response waitForReply​(java.lang.String responderId,
                                     java.lang.String msgTag)
        Waits for a reply to a message sent earlier using call or callAll. Blocks until such a response is received.
        Parameters:
        responderId - client ID of client providing response
        msgTag - tag which was used to send the message
        Returns:
        response
      • getReply

        public Response getReply​(java.lang.String responderId,
                                 java.lang.String msgTag)
        Gets the reply to a message sent earlier using call or callAll. Does not block; if no such response has been received so far, returns null.
        Parameters:
        responderId - client ID of client providing response
        msgTag - tag which was used to send the message
        Returns:
        response
      • createKey

        private static java.lang.Object createKey​(java.lang.String recipientId,
                                                  java.lang.String msgTag)
        Returns an opaque object suitable for use as a map key based on a recipient ID and message tag.
        Parameters:
        recipientId - recipient ID
        msgTag - message tag