Package fr.dyade.aaa.agent
Class MessageSoftList
- java.lang.Object
-
- fr.dyade.aaa.agent.MessageSoftList
-
public class MessageSoftList extends Object
This class holds a list ofMessage, waiting to be sent. After sending one message it is marked as sent, which means it is kept until its acknowledgment. Once acknowledged, the message is deleted.
This list can hold an acknowledgment message, which is always the first one to be sent if present.
If the list is marked as persistent, messages are encapsulated byMessageSoftRefin order to be garbaged from memory if necessary.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classMessageSoftList.MessageComparatorA comparator to keep list sorted by message stamp.(package private) static classMessageSoftList.MessageSoftComparatorA comparator to keep list sorted by message stamp when using soft references.private static classMessageSoftList.MessageSoftIteratorAn iterator returning the messages when going through a collection ofMessageSoftRef.
-
Field Summary
Fields Modifier and Type Field Description private MessageackCurrent ack message which will be sent in priority.private static booleanDEBUGprivate LoggerloggerLogger for the instance.private SortedSetmsgSentlistThe list of sent messages waiting to be acknowledged.private SortedSetmsgToSendlistThe list of messages waiting to be sent.private booleanpersistentTells if messages are persisted on disk and can be garbaged from memory.
-
Constructor Summary
Constructors Constructor Description MessageSoftList(String name, boolean persistent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMessage(Message msg)Adds a message at the end of the list.voiddeleteMessagesUpTo(int stamp)Iterates over messages waiting for an acknowledge to delete the ones which have a stamp inferior or equal to the given one.MessagegetAck()Returns the acknowledge waiting to be sent if present.MessagegetFirst()Returns the first non expired message waiting to be sent.private voidremoveExpired(Message msg)Removes the expired message, if needed an ExpiredNot is sent to the deadNotificationAgentId specified.private voidremoveExpired(MessageSoftRef msgRef)Removes the expired message, if needed an ExpiredNot is sent to the deadNotificationAgentId specified.voidreset()Resets all messages waiting for an acknowledge: they are placed back at the beginning of the list respecting their stamp order.
Furthermore, expired messages are removed from the list.private MessageselectFirst()intsentSize()Returns the number of messages waiting for an ack.voidsetAck(Message ack)Sets the next ack to send.voidsetSent(Message msg)Mark specified message as sent (ie waiting for an ack).IteratortoSendIterator()Returns an iterator over the messages waiting to be sent.inttoSendSize()Returns the number of messages waiting to be sent.StringtoString()
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
-
logger
private Logger logger
Logger for the instance.
-
ack
private Message ack
Current ack message which will be sent in priority.
-
msgToSendlist
private SortedSet msgToSendlist
The list of messages waiting to be sent.
-
msgSentlist
private SortedSet msgSentlist
The list of sent messages waiting to be acknowledged.
-
persistent
private final boolean persistent
Tells if messages are persisted on disk and can be garbaged from memory.
-
-
Constructor Detail
-
MessageSoftList
public MessageSoftList(String name, boolean persistent)
-
-
Method Detail
-
addMessage
public void addMessage(Message msg)
Adds a message at the end of the list. UsesetAck(Message)if you want to add an ack to the list.- Parameters:
msg- the message to add.
-
getAck
public Message getAck()
Returns the acknowledge waiting to be sent if present.- Returns:
- current acknowledge waiting to be sent, or null if there is none.
-
getFirst
public Message getFirst()
Returns the first non expired message waiting to be sent. It can be an acknowledge.- Returns:
- the next message to send or null if there is none.
-
selectFirst
private Message selectFirst()
-
removeExpired
private void removeExpired(MessageSoftRef msgRef)
Removes the expired message, if needed an ExpiredNot is sent to the deadNotificationAgentId specified.- Parameters:
msgRef- The message to remove.
-
removeExpired
private void removeExpired(Message msg)
Removes the expired message, if needed an ExpiredNot is sent to the deadNotificationAgentId specified.- Parameters:
msg- The message to remove.
-
deleteMessagesUpTo
public void deleteMessagesUpTo(int stamp) throws IOExceptionIterates over messages waiting for an acknowledge to delete the ones which have a stamp inferior or equal to the given one.- Parameters:
stamp- the stamp of the last message acked.- Throws:
IOException- an error occurs.
-
setAck
public void setAck(Message ack)
Sets the next ack to send.- Parameters:
ack- the acknowledge to send.
-
toSendIterator
public Iterator toSendIterator()
Returns an iterator over the messages waiting to be sent.- Returns:
- an iterator over the messages waiting to be sent.
-
reset
public void reset()
Resets all messages waiting for an acknowledge: they are placed back at the beginning of the list respecting their stamp order.
Furthermore, expired messages are removed from the list.
-
toSendSize
public int toSendSize()
Returns the number of messages waiting to be sent.- Returns:
- the number of messages waiting to be sent.
-
setSent
public void setSent(Message msg)
Mark specified message as sent (ie waiting for an ack). The given message must be the next one to be sent, returned bygetFirst().- Parameters:
msg- the message which have been sent.
-
sentSize
public int sentSize()
Returns the number of messages waiting for an ack.- Returns:
- the number of messages waiting for an ack.
-
-