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 ofCallableClient
which handles thereceiveReply
method. 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'scall
andcallAll
methods, 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 boolean
allowTagReuse_
private HubConnection
connection_
private java.util.Map
replyMap_
private java.util.Set
sentSet_
-
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.String
call(java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg)
Performs acall
method on this collector's hub connection.java.util.Map
callAll(java.lang.String msgTag, java.util.Map msg)
Performs acallAll
method on this collector's hub connection.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.Response
getReply(java.lang.String responderId, java.lang.String msgTag)
Gets the reply to a message sent earlier usingcall
orcallAll
.int
getReplyCount()
Returns the total number of unretrieved replies so far collected by this object.void
receiveResponse(java.lang.String responderId, java.lang.String msgTag, Response response)
Receives a response to a message previously sent by this client.void
setAllowTagReuse(boolean allow)
Determines whether clients are permitted to reuse tags for different messages.Response
waitForReply(java.lang.String responderId, java.lang.String msgTag)
Waits for a reply to a message sent earlier usingcall
orcallAll
.-
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 SampException
Performs acall
method on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, themsgTag
must 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 SampException
Performs acallAll
method on this collector's hub connection. Additional internal state is updated. Although it is legal as far as SAMP goes, themsgTag
must 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:CallableClient
Receives a response to a message previously sent by this client.- Specified by:
receiveResponse
in 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 usingcall
orcallAll
. 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 usingcall
orcallAll
. 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
-
-