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.SortedMaptagMap_private java.lang.Threadtimeouter_
-
Constructor Summary
Constructors Constructor Description CallHandler()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanownsTag(java.lang.String tag)Indicates whether this handler will process the response with a given message tag.private voidreadyTimeouter()Ensures that a thread is running to wake up when the next timeout has (or at least might have) happened.voidreceiveResponse(HubConnection connection, java.lang.String responderId, java.lang.String msgTag, Response response)Processes a response to an earlier message.voidregisterHandler(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 voidretireIfDone(java.lang.String tag, HubConnector.CallItem item)Called when a tag/handler entry might be ready to finish with.voidsetRecipients(java.lang.String tag, java.lang.String[] recipients)Set the recipients from which we are expecting responses.private voidstopTimeouter()Stops any current timeout watcher operating on behalf of this handler and tidies up associated resources.voidunregisterHandler(java.lang.String tag)Unregister a handler for which no responses are expected.private voidwatchTimeouts()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:ResponseHandlerIndicates whether this handler will process the response with a given message tag.- Specified by:
ownsTagin 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:ResponseHandlerProcesses a response to an earlier message. Will only be called formsgTagvalues which returntruefromResponseHandler.ownsTag(java.lang.String).- Specified by:
receiveResponsein 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.
-
-