Class HubConnector.CallHandler

  • All Implemented Interfaces:
    ResponseHandler
    Enclosing class:
    HubConnector

    private class HubConnector.CallHandler
    extends java.lang.Object
    implements ResponseHandler
    ResponseHandler which looks after responses made by calls using the call() and callAll() convenience methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.SortedMap tagMap_  
      private java.lang.Thread timeouter_  
    • Constructor Summary

      Constructors 
      Constructor Description
      CallHandler()
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean ownsTag​(java.lang.String tag)
      Indicates whether this handler will process the response with a given message tag.
      private void readyTimeouter()
      Ensures that a thread is running to wake up when the next timeout has (or at least might have) happened.
      void receiveResponse​(HubConnection connection, java.lang.String responderId, java.lang.String msgTag, Response response)
      Processes a response to an earlier message.
      void registerHandler​(java.lang.String tag, ResultHandler handler, int timeout)
      Stores a ResultHandler object which will take delivery of the responses tagged with a given tag.
      private void retireIfDone​(java.lang.String tag, HubConnector.CallItem item)
      Called when a tag/handler entry might be ready to finish with.
      void setRecipients​(java.lang.String tag, java.lang.String[] recipients)
      Set the recipients from which we are expecting responses.
      private void stopTimeouter()
      Stops any current timeout watcher operating on behalf of this handler and tidies up associated resources.
      void unregisterHandler​(java.lang.String tag)
      Unregister a handler for which no responses are expected.
      private void watchTimeouts()
      Runs in a daemon thread to watch out for timeouts that might have occurred.
      • Methods inherited from class java.lang.Object

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

      • tagMap_

        private final java.util.SortedMap tagMap_
      • timeouter_

        private java.lang.Thread timeouter_
    • Constructor Detail

      • CallHandler

        CallHandler()
        Constructor.
    • Method Detail

      • readyTimeouter

        private void readyTimeouter()
        Ensures that a thread is running to wake up when the next timeout has (or at least might have) happened.
      • stopTimeouter

        private void stopTimeouter()
        Stops any current timeout watcher operating on behalf of this handler and tidies up associated resources.
      • watchTimeouts

        private void watchTimeouts()
        Runs in a daemon thread to watch out for timeouts that might have occurred.
      • registerHandler

        public void registerHandler​(java.lang.String tag,
                                    ResultHandler handler,
                                    int timeout)
        Stores a ResultHandler object which will take delivery of the responses tagged with a given tag.
        Parameters:
        tag - message tag identifying send/response
        handler - callback object
        timeout - milliseconds before forcing completion
      • setRecipients

        public void setRecipients​(java.lang.String tag,
                                  java.lang.String[] recipients)
        Set the recipients from which we are expecting responses. Once all are in, the handler can be disposed of.
        Parameters:
        tag - message tag identifying send/response
        recipients - clients expected to reply
      • unregisterHandler

        public void unregisterHandler​(java.lang.String tag)
        Unregister a handler for which no responses are expected.
        Parameters:
        tag - message tag identifying send/response
      • ownsTag

        public boolean ownsTag​(java.lang.String tag)
        Description copied from interface: ResponseHandler
        Indicates whether this handler will process the response with a given message tag.
        Specified by:
        ownsTag in interface ResponseHandler
        Parameters:
        tag - tag with which earlier call was labelled
        Returns:
        true iff this handler wants to process the response labelled with msgTag
      • receiveResponse

        public void receiveResponse​(HubConnection connection,
                                    java.lang.String responderId,
                                    java.lang.String msgTag,
                                    Response response)
        Description copied from interface: ResponseHandler
        Processes a response to an earlier message. Will only be called for msgTag values which return true from ResponseHandler.ownsTag(java.lang.String).
        Specified by:
        receiveResponse in interface ResponseHandler
        Parameters:
        connection - hub connection
        responderId - client id of client sending response
        msgTag - message tag from previous call
        response - response object
      • retireIfDone

        private void retireIfDone​(java.lang.String tag,
                                  HubConnector.CallItem item)
        Called when a tag/handler entry might be ready to finish with.