Package org.astrogrid.samp.client
Class HubConnector.CallHandler
- java.lang.Object
-
- org.astrogrid.samp.client.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.
-
-
-
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/responsehandler
- callback objecttimeout
- 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/responserecipients
- 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 interfaceResponseHandler
- 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 formsgTag
values which returntrue
fromResponseHandler.ownsTag(java.lang.String)
.- Specified by:
receiveResponse
in interfaceResponseHandler
- Parameters:
connection
- hub connectionresponderId
- client id of client sending responsemsgTag
- message tag from previous callresponse
- 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.
-
-