Class ClientTracker

  • All Implemented Interfaces:
    MessageHandler

    class ClientTracker
    extends AbstractMessageHandler
    Message handler which watches hub event messages to keep track of what clients are currently registered and what their attributes are on behalf of the hub. The results are stored in an externally supplied TrackedClientSet object. This class tries its best to handle complications arising from the fact that calls concerning a client may arrive out of order (for instance declareMetadata before registration or after unregistration).
    Since:
    16 Jul 2008
    Author:
    Mark Taylor, Laurent Bourges
    • Field Detail

      • clientMap_

        private final java.util.Map clientMap_
      • logger_

        private static final java.util.logging.Logger logger_
      • REGISTER_MTYPE

        private static final java.lang.String REGISTER_MTYPE
      • UNREGISTER_MTYPE

        private static final java.lang.String UNREGISTER_MTYPE
      • METADATA_MTYPE

        private static final java.lang.String METADATA_MTYPE
      • SUBSCRIPTIONS_MTYPE

        private static final java.lang.String SUBSCRIPTIONS_MTYPE
      • TRACKED_MTYPES

        private static final java.lang.String[] TRACKED_MTYPES
    • Constructor Detail

      • ClientTracker

        public ClientTracker​(TrackedClientSet clientSet)
        Constructor.
        Parameters:
        clientSet - object used to record registered clients and their attributes
    • Method Detail

      • clear

        public void clear()
        Removes all clients from the list.
      • initialise

        public void initialise​(HubConnection connection)
                        throws SampException
        Initialises this tracker from a hub connection. It is interrogated to find the current list of registered clients and their attributes.
        Parameters:
        connection - hub connection; may be null for no connection
        Throws:
        SampException
      • processCall

        public java.util.Map processCall​(HubConnection connection,
                                         java.lang.String senderId,
                                         Message message)
        Description copied from class: AbstractMessageHandler
        Implements message processing. Implementations should normally return a map which contains the samp.result part of the call response, that is the MType-specific return value name->value map. As a special case, returning null is equivalent to returning an empty map. However, if AbstractMessageHandler.createResponse(java.util.Map) is overridden, the return value semantics may be different.
        Specified by:
        processCall in class AbstractMessageHandler
        Parameters:
        connection - hub connection
        senderId - public ID of sender client
        message - message with MType this handler is subscribed to
        Returns:
        result of handling this message; exact semantics determined by createResponse implementation
      • performClientOperation

        private void performClientOperation​(ClientTracker.ClientOperation op,
                                            HubConnection connection)
        Performs an operation on a ClientOperation object.
        Parameters:
        op - client operation
        connection - hub connection