Package org.astrogrid.samp.client
Class ClientTracker
- java.lang.Object
-
- org.astrogrid.samp.client.AbstractMessageHandler
-
- org.astrogrid.samp.client.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 suppliedTrackedClientSetobject. 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classClientTracker.ClientOperationDescribes an operation to be performed on a TrackedClient object which is already part of this tracker's model.private static classClientTracker.OperationQueueData structure for holding ClientOperation objects which (may) need to be applied in the future.private static classClientTracker.TrackedClientClient implementation used to populate internal data structures.
-
Field Summary
Fields Modifier and Type Field Description private java.util.MapclientMap_private TrackedClientSetclientSet_private static java.util.logging.Loggerlogger_private static java.lang.StringMETADATA_MTYPEprivate ClientTracker.OperationQueueopQueue_private static intQUEUE_TIMEprivate static java.lang.StringREGISTER_MTYPEprivate static java.lang.StringSUBSCRIPTIONS_MTYPEprivate static java.lang.String[]TRACKED_MTYPESprivate static java.lang.StringUNREGISTER_MTYPE
-
Constructor Summary
Constructors Constructor Description ClientTracker(TrackedClientSet clientSet)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all clients from the list.voidinitialise(HubConnection connection)Initialises this tracker from a hub connection.private voidperformClientOperation(ClientTracker.ClientOperation op, HubConnection connection)Performs an operation on a ClientOperation object.java.util.MapprocessCall(HubConnection connection, java.lang.String senderId, Message message)Implements message processing.-
Methods inherited from class org.astrogrid.samp.client.AbstractMessageHandler
createResponse, getSubscriptions, receiveCall, receiveNotification, setSubscriptions
-
-
-
-
Field Detail
-
clientSet_
private final TrackedClientSet clientSet_
-
clientMap_
private final java.util.Map clientMap_
-
opQueue_
private final ClientTracker.OperationQueue opQueue_
-
logger_
private static final java.util.logging.Logger logger_
-
QUEUE_TIME
private static final int QUEUE_TIME
- See Also:
- Constant Field Values
-
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:AbstractMessageHandlerImplements message processing. Implementations should normally return a map which contains thesamp.resultpart 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, ifAbstractMessageHandler.createResponse(java.util.Map)is overridden, the return value semantics may be different.- Specified by:
processCallin classAbstractMessageHandler- Parameters:
connection- hub connectionsenderId- public ID of sender clientmessage- message with MType this handler is subscribed to- Returns:
- result of handling this message; exact semantics determined
by
createResponseimplementation
-
performClientOperation
private void performClientOperation(ClientTracker.ClientOperation op, HubConnection connection)
Performs an operation on a ClientOperation object.- Parameters:
op- client operationconnection- hub connection
-
-