TReplyMessage
- type of the reply message that this receiver acceptspublic final class ReplyReceiver<TReplyMessage extends ReplyMessage> extends java.lang.Object implements Receiver
Receiver
for receiving reply messages.
This class is automatically created and maintained by MessageDispatcher
.
It is returned by sendMessageWaitReply
method
and getter methods can be used to receive the responses (or wait for them).Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
log
Logger
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptMessage(Message msg,
boolean allowSuperclass)
The
Receiver interface method. |
static <E extends ReplyMessage> |
cast(ReplyReceiver<?> receiver,
java.lang.Class<? extends E> replyMessageClass)
Cast a given
ReplyReceiver to a correct generic type. |
TReplyMessage |
getFirstReply()
Returns the first received reply message.
|
int |
getRemainingCount()
Returns the number of replies still pending.
|
java.util.List<TReplyMessage> |
getReplies()
Returns all reply messages gathered by this reply receiver.
|
java.util.List<TReplyMessage> |
getReplies(long timeout)
Returns all reply messages gathered by this reply receiver so far.
|
boolean |
isFinished()
Returns true if the reply waiting is finished.
|
boolean |
isReadyToRemove()
Return true if this receiver is ready to be deregistered from the list of waiting receivers.
|
java.lang.String |
toString()
Returns a string representation of this reply receiver.
|
public static <E extends ReplyMessage> ReplyReceiver<E> cast(ReplyReceiver<?> receiver, java.lang.Class<? extends E> replyMessageClass)
ReplyReceiver
to a correct generic type.
The receiver's reply class is checked so this cast is type-safe.E
- the reply messages that the cast receiver waits forreceiver
- the receiver to castreplyMessageClass
- the class of the reply messages that the cast receiver waits forpublic int getRemainingCount()
public boolean isFinished()
public boolean isReadyToRemove()
public boolean acceptMessage(Message msg, boolean allowSuperclass)
Receiver
interface method.
This receiver accepts (i.e. returns true) only reply messages (with specified class) and only if it is not finished yet.
This method is called by MessageDispatcher
when new message arrives.acceptMessage
in interface Receiver
msg
- the message offered for acceptanceallowSuperclass
- this receiver only receives message if this parameter is falsepublic java.util.List<TReplyMessage> getReplies(long timeout) throws java.lang.InterruptedException
isFinished()
or getRemainingCount()
methods should be called
in order to check the completeness.timeout
- number of miliseconds to wait for replies arrival. If zero is specified,
this method will wait until all reply messages arrive (or forever if something bad happens).java.lang.InterruptedException
- if the thread was interrupted while waiting for message arrivalpublic java.util.List<TReplyMessage> getReplies() throws java.lang.InterruptedException
java.lang.InterruptedException
- if the thread was interrupted while waiting for message arrivalpublic TReplyMessage getFirstReply()
public java.lang.String toString()
toString
in class java.lang.Object