Message retriever
The great advantage of a message retriever is that it may store the already retrieved messages - thus implementing an internal message storage in the Place User - and that its way of delivering messages can be controlled by a retrieve policy.
Constructors
AMETASMessageRetriever(AMETASPlaceUser pu, boolean bRecordMessageIDs, AMETASRetrievePolicy rp)
Creates a new message retriever. It requires the access to the Place User in order to access the driver. The boolean flag determines that messages which cannot be deleted after retrieving will not be retrieved again. If set to true, the retriever record the message IDs and discards those messages which it already retrieved. The retrieve policy determines which message comes next on call of getNextMessage.
Methods
AMETASMessage getNextMessage()
Gets the next message, according to the retrieve policy. The message is removed from the internal queue.
AMETASMessage getRecentMessage()
Gets the message recently delivered by getNextMessage. The internal queue remains unchanged.
boolean pushbackLastMessage()
Puts the recent message back onto the head of the input queue. That is, the next call of getNextMessage should deliver the same message again. This method is called by the AMETASSequentialContextProcessor when a MessagePushbackException has been raised.
| If the retrieve policy is
|
Retrieve policy
The interface AMETASRetrievePolicy has only one method and defines one constant:
public interface AMETASRetrievePolicy {
final static int NONE_SELECTED = -1;
int selectMessage(List llMess);
}
|
In order to define a retrieve policy, you have to decide which message comes next, given a list
of messages. This list is created by getting the messages from the post office. If no message is
selected, NONE_SELECTED should be returned (e.g. when the list is empty).
Otherwise, the returned value is the index in the list.
| Your retrieve policy must not change the list which it got from the message retriever, otherwise the sequence of messages could get mixed up, or messages could be lost. |
There is a special implementation, AMETASContextRetrievePolicy.
Constructors
AMETASContextRetrievePolicy(int[] anContextPref)
Creates a new retrieve policy based on an context preference list. This list is passed in the constructor. Contexts which shall have higher preference have a smaller index than contexts with higher index in the integer field.
This policy works as follows: When given a list of currently retrieved messages, it takes the list of contexts to find out which message to deliver. The messages of preferred contexts are delivered at first, preserving their order in the input quere. So if we have a list like
int[] anContextPref = { 1, 3, 2, 10 };
and a message list like
k(2) l(10) m(1) n(2) o(1)
with the receiver contexts in parentheses, the policy will return message m(1) first, then o(1), then k(2), then n(2), and finally l(10). This does not mix up the message sequence defined in the protocol because we have different contexts here. On the contrary, each context keeps the sequence.