Package fr.dyade.aaa.agent
Class MessageSoftRef
- java.lang.Object
-
- fr.dyade.aaa.agent.MessageSoftRef
-
public final class MessageSoftRef extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classMessageSoftRef.TransactionError
-
Field Summary
Fields Modifier and Type Field Description private AgentIddeadNotAgentIdThe agent responsible of treating the notification when it expires.private static booleanDEBUGprivate longexpirationThe expiration date of the notification hold by the message, if any.private static Loggerloggerprivate StringmessageIdIf the notification is stored independently of its containing message, messageId contains the persistent name of this notification.private StringnameName for persistent message, used to retrieve garbaged message from persistent storage.private MessagerefReference for transient message, used to pin non persistent in memory.private SoftReference<Message>softRefThe SoftReference to the message, which permits to the message to be garbaged in response to memory demand.private intstampThe stamp of the referenced message.
-
Constructor Summary
Constructors Constructor Description MessageSoftRef(Message msg)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Deletes the message in persistent storage.AgentIdgetDeadNotAgentId()Returns the agent responsible of treating the notification when it expires.MessagegetMessage()Returns this reference message's referent.intgetStamp()Returns the stamp of the message backed by this MessageSoftRef, without reloading it if it has been swapped.booleanisExpired(long time)Tests whether the message has expired.MessageloadMessage()Returns the message to which this reference refers, loading it from disk if the message has been swapped out.StringtoString()Returns a string representation of thisMessageSoftRefobject.
-
-
-
Field Detail
-
logger
private static final Logger logger
-
DEBUG
private static final boolean DEBUG
-
name
private String name
Name for persistent message, used to retrieve garbaged message from persistent storage.
-
ref
private Message ref
Reference for transient message, used to pin non persistent in memory.
-
softRef
private SoftReference<Message> softRef
The SoftReference to the message, which permits to the message to be garbaged in response to memory demand.
-
stamp
private int stamp
The stamp of the referenced message. It is useful to avoid reloading messages from disk when looking for a particular message.
-
messageId
private String messageId
If the notification is stored independently of its containing message, messageId contains the persistent name of this notification.
-
expiration
private long expiration
The expiration date of the notification hold by the message, if any.
-
deadNotAgentId
private AgentId deadNotAgentId
The agent responsible of treating the notification when it expires. It is useful to avoid reloading messages from disk before deleting them if the field is empty.
-
-
Constructor Detail
-
MessageSoftRef
MessageSoftRef(Message msg)
-
-
Method Detail
-
isExpired
public boolean isExpired(long time)
Tests whether the message has expired.- Parameters:
time- the current time.- Returns:
- true if the message has expired.
-
getDeadNotAgentId
public AgentId getDeadNotAgentId()
Returns the agent responsible of treating the notification when it expires.- Returns:
- the unique identifier of the agent responsible of treating the notification after expiration.
-
getMessage
public Message getMessage()
Returns this reference message's referent. If the message has been swap out it returns null.- Returns:
- The message to which this reference refers.
-
getStamp
public int getStamp()
Returns the stamp of the message backed by this MessageSoftRef, without reloading it if it has been swapped.- Returns:
- the stamp of the message.
-
loadMessage
public Message loadMessage() throws MessageSoftRef.TransactionError
Returns the message to which this reference refers, loading it from disk if the message has been swapped out. If loading from disk is done, the SoftReference is renewed to avoid reloading the message each time this method is called.- Returns:
- The message to which this reference refers.
- Throws:
MessageSoftRef.TransactionError
-
delete
public void delete()
Deletes the message in persistent storage. This method must be called during aTransaction.
-
-