abstract class ReplyCollector extends java.lang.Object implements CallableClient
CallableClient
which handles the
receiveReply
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's call
and callAll
methods, rather than directly on the HubConnection
,
to ensure that the internal state stays correct.Modifier and Type | Field and Description |
---|---|
private boolean |
allowTagReuse_ |
private HubConnection |
connection_ |
private java.util.Map |
replyMap_ |
private java.util.Set |
sentSet_ |
Constructor and Description |
---|
ReplyCollector(HubConnection connection)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
call(java.lang.String recipientId,
java.lang.String msgTag,
java.util.Map msg)
Performs a
call method on this collector's hub connection. |
java.util.Map |
callAll(java.lang.String msgTag,
java.util.Map msg)
Performs a
callAll 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
using
call or callAll . |
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
using
call or callAll . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
receiveCall, receiveNotification
private final HubConnection connection_
private final java.util.Set sentSet_
private final java.util.Map replyMap_
private boolean allowTagReuse_
public ReplyCollector(HubConnection connection)
connection
- hub connectionallowTagReuse
- if true clients may reuse tags;
if false any such attempt generates an exceptionpublic void setAllowTagReuse(boolean allow)
allow
- whether to allow tag reusepublic java.lang.String call(java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg) throws SampException
call
method on this collector's hub connection.
Additional internal state is updated.
Although it is legal as far as SAMP goes, the msgTag
must not be one which was used earlier for the same recipient.recipientId
- public-id of client to receive messagemsgTag
- arbitrary string tagging this message for caller's
benefitmsg
- Message
-like mapSampException
public java.util.Map callAll(java.lang.String msgTag, java.util.Map msg) throws SampException
callAll
method on this collector's
hub connection.
Additional internal state is updated.
Although it is legal as far as SAMP goes, the msgTag
must not be one which was used for an earlier broadcast.msgTag
- arbitrary string tagging this message for caller's
benefitmsg
- Message
-like mapSampException
public void receiveResponse(java.lang.String responderId, java.lang.String msgTag, Response response)
CallableClient
receiveResponse
in interface CallableClient
responderId
- public ID of responding clientmsgTag
- client-defined tag labelling previously-sent messageresponse
- returned response objectpublic int getReplyCount()
public Response waitForReply(java.lang.String responderId, java.lang.String msgTag)
call
or callAll
.
Blocks until such a response is received.responderId
- client ID of client providing responsemsgTag
- tag which was used to send the messagepublic Response getReply(java.lang.String responderId, java.lang.String msgTag)
call
or callAll
.
Does not block; if no such response has been received so far,
returns null.responderId
- client ID of client providing responsemsgTag
- tag which was used to send the messageprivate static java.lang.Object createKey(java.lang.String recipientId, java.lang.String msgTag)
recipientId
- recipient IDmsgTag
- message tag