Package org.astrogrid.samp.test
Class ReplyCollector
- java.lang.Object
-
- org.astrogrid.samp.test.ReplyCollector
-
- All Implemented Interfaces:
CallableClient
- Direct Known Subclasses:
HubTester.TestCallableClient
abstract class ReplyCollector extends java.lang.Object implements CallableClient
Partial implementation ofCallableClientwhich handles thereceiveReplymethod. This takes care of matching up replies with calls and is intended for use with test classes. Some assertions are made within this class to check that replies match with messages sent. Call-type messages must be sent using this object'scallandcallAllmethods, rather than directly on theHubConnection, to ensure that the internal state stays correct.- Since:
- 18 Jul 2008
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowTagReuse_private HubConnectionconnection_private java.util.MapreplyMap_private java.util.SetsentSet_
-
Constructor Summary
Constructors Constructor Description ReplyCollector(HubConnection connection)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcall(java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg)Performs acallmethod on this collector's hub connection.java.util.MapcallAll(java.lang.String msgTag, java.util.Map msg)Performs acallAllmethod on this collector's hub connection.private static java.lang.ObjectcreateKey(java.lang.String recipientId, java.lang.String msgTag)Returns an opaque object suitable for use as a map key based on a recipient ID and message tag.ResponsegetReply(java.lang.String responderId, java.lang.String msgTag)Gets the reply to a message sent earlier usingcallorcallAll.intgetReplyCount()Returns the total number of unretrieved replies so far collected by this object.voidreceiveResponse(java.lang.String responderId, java.lang.String msgTag, Response response)Receives a response to a message previously sent by this client.voidsetAllowTagReuse(boolean allow)Determines whether clients are permitted to reuse tags for different messages.ResponsewaitForReply(java.lang.String responderId, java.lang.String msgTag)Waits for a reply to a message sent earlier usingcallorcallAll.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.astrogrid.samp.client.CallableClient
receiveCall, receiveNotification
-
-
-
-
Field Detail
-
connection_
private final HubConnection connection_
-
sentSet_
private final java.util.Set sentSet_
-
replyMap_
private final java.util.Map replyMap_
-
allowTagReuse_
private boolean allowTagReuse_
-
-
Constructor Detail
-
ReplyCollector
public ReplyCollector(HubConnection connection)
Constructor.- Parameters:
connection- hub connectionallowTagReuse- if true clients may reuse tags; if false any such attempt generates an exception
-
-
Method Detail
-
setAllowTagReuse
public void setAllowTagReuse(boolean allow)
Determines whether clients are permitted to reuse tags for different messages. If true, any such attempt generates an exception.- Parameters:
allow- whether to allow tag reuse
-
call
public java.lang.String call(java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg) throws SampExceptionPerforms acallmethod on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, themsgTagmust not be one which was used earlier for the same recipient.- Parameters:
recipientId- public-id of client to receive messagemsgTag- arbitrary string tagging this message for caller's benefitmsg-Message-like map- Returns:
- message ID
- Throws:
SampException
-
callAll
public java.util.Map callAll(java.lang.String msgTag, java.util.Map msg) throws SampExceptionPerforms acallAllmethod on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, themsgTagmust not be one which was used for an earlier broadcast.- Parameters:
msgTag- arbitrary string tagging this message for caller's benefitmsg-Message-like map- Returns:
- message ID
- Throws:
SampException
-
receiveResponse
public void receiveResponse(java.lang.String responderId, java.lang.String msgTag, Response response)Description copied from interface:CallableClientReceives a response to a message previously sent by this client.- Specified by:
receiveResponsein interfaceCallableClient- Parameters:
responderId- public ID of responding clientmsgTag- client-defined tag labelling previously-sent messageresponse- returned response object
-
getReplyCount
public int getReplyCount()
Returns the total number of unretrieved replies so far collected by this object.- Returns:
- reply count
-
waitForReply
public Response waitForReply(java.lang.String responderId, java.lang.String msgTag)
Waits for a reply to a message sent earlier usingcallorcallAll. Blocks until such a response is received.- Parameters:
responderId- client ID of client providing responsemsgTag- tag which was used to send the message- Returns:
- response
-
getReply
public Response getReply(java.lang.String responderId, java.lang.String msgTag)
Gets the reply to a message sent earlier usingcallorcallAll. Does not block; if no such response has been received so far, returns null.- Parameters:
responderId- client ID of client providing responsemsgTag- tag which was used to send the message- Returns:
- response
-
createKey
private static java.lang.Object createKey(java.lang.String recipientId, java.lang.String msgTag)Returns an opaque object suitable for use as a map key based on a recipient ID and message tag.- Parameters:
recipientId- recipient IDmsgTag- message tag
-
-