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 suppliedTrackedClientSet
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ClientTracker.ClientOperation
Describes an operation to be performed on a TrackedClient object which is already part of this tracker's model.private static class
ClientTracker.OperationQueue
Data structure for holding ClientOperation objects which (may) need to be applied in the future.private static class
ClientTracker.TrackedClient
Client implementation used to populate internal data structures.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map
clientMap_
private TrackedClientSet
clientSet_
private static java.util.logging.Logger
logger_
private static java.lang.String
METADATA_MTYPE
private ClientTracker.OperationQueue
opQueue_
private static int
QUEUE_TIME
private static java.lang.String
REGISTER_MTYPE
private static java.lang.String
SUBSCRIPTIONS_MTYPE
private static java.lang.String[]
TRACKED_MTYPES
private static java.lang.String
UNREGISTER_MTYPE
-
Constructor Summary
Constructors Constructor Description ClientTracker(TrackedClientSet clientSet)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all clients from the list.void
initialise(HubConnection connection)
Initialises this tracker from a hub connection.private void
performClientOperation(ClientTracker.ClientOperation op, HubConnection connection)
Performs an operation on a ClientOperation object.java.util.Map
processCall(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:AbstractMessageHandler
Implements message processing. Implementations should normally return a map which contains thesamp.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, ifAbstractMessageHandler.createResponse(java.util.Map)
is overridden, the return value semantics may be different.- Specified by:
processCall
in 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
createResponse
implementation
-
performClientOperation
private void performClientOperation(ClientTracker.ClientOperation op, HubConnection connection)
Performs an operation on a ClientOperation object.- Parameters:
op
- client operationconnection
- hub connection
-
-