Package fr.dyade.aaa.agent
Class Message
- java.lang.Object
-
- fr.dyade.aaa.agent.Message
-
- All Implemented Interfaces:
Encodable,Serializable
public final class Message extends Object implements Serializable, Encodable
The internal message structure. A message is divided in 2 parts:- An immutable part with source and destination agent unique id, and notification object.
- A variable part containing information about message routing (next hop) and the current stamp of the message.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classMessage.Factory
-
Field Summary
Fields Modifier and Type Field Description private static booleanDEBUG(package private) shortdestThe unique id. of destination server(package private) static byteDETACHABLE(package private) AgentIdfromAgentIdof sender.(package private) static intLENGTHstatic Loggerlogger(package private) NotificationnotThe notification.(package private) static byteNOTNULL(package private) static byteNULL(package private) static bytePERSISTENTprivate static Poolpoolprivate SerializableWrapperserializedNot(package private) static longserialVersionUIDdefine serialVersionUID for interoperability(package private) shortsourceThe unique id. of source server(package private) intstampThe current stamp of the messageprivate StringstringId(package private) AgentIdtoAgentIdof destination agent.-
Fields inherited from interface fr.dyade.aaa.common.encoding.Encodable
BOOLEAN_ENCODED_SIZE, BYTE_ENCODED_SIZE, DOUBLE_ENCODED_SIZE, FLOAT_ENCODED_SIZE, INT_ENCODED_SIZE, LONG_ENCODED_SIZE, SHORT_ENCODED_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description privateMessage()Construct a new message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static Messagealloc()Allocates a message from the pool.(package private) static Messagealloc(AgentId from, AgentId to, Notification not)Allocates a message from the pool.StringBufferappendToString(StringBuffer strbuf)Adds a string representation for this object in the StringBuffer parameter.voiddecode(Decoder decoder)Decodes the content of this object(package private) voiddelete()Deletes the current object in persistent storage.voidencode(Encoder encoder)Encodes the content of this object(package private) voidfree()Frees the message to the pool.shortgetDest()Get the unique server id. of the addressee of this messageintgetEncodableClassId()Returns a unique class identifier.intgetEncodedSize()Returns the size of the byte array that results from the encoding of this object.AgentIdgetFrom()NotificationgetNot()shortgetSource()Get the unique server identifier of the sender of this messageintgetStamp()Get the stamp of this messageAgentIdgetTo()booleanisPersistent()Tests if the associated notification is persistent or not.(package private) static Messageload(String name)Restores the object state from the persistent storage.(package private) voidoptFromByte(byte opt)(package private) byteoptToByte()private voidreadObject(ObjectInputStream in)The readObject method is responsible for reading from the stream and restoring the classes fields.(package private) voidsave()Saves the object state on persistent storage.private voidset(AgentId from, AgentId to, Notification not)StringtoString()Returns a string representation for this object.(package private) StringtoStringId()private voidwriteObject(ObjectOutputStream out)The writeObject method is responsible for writing the state of the object for its particular class so that the corresponding readObject method can restore it.
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
define serialVersionUID for interoperability- See Also:
- Constant Field Values
-
logger
public static final Logger logger
-
DEBUG
private static final boolean DEBUG
-
from
transient AgentId from
AgentIdof sender.
-
to
transient AgentId to
AgentIdof destination agent.
-
not
transient Notification not
The notification.
-
source
transient short source
The unique id. of source server
-
dest
transient short dest
The unique id. of destination server
-
stamp
transient int stamp
The current stamp of the message
-
LENGTH
static final int LENGTH
- See Also:
- Constant Field Values
-
NULL
static final byte NULL
- See Also:
- Constant Field Values
-
NOTNULL
static final byte NOTNULL
- See Also:
- Constant Field Values
-
PERSISTENT
static final byte PERSISTENT
- See Also:
- Constant Field Values
-
DETACHABLE
static final byte DETACHABLE
- See Also:
- Constant Field Values
-
stringId
private transient String stringId
-
pool
private static Pool pool
-
serializedNot
private SerializableWrapper serializedNot
-
-
Method Detail
-
getSource
public short getSource()
Get the unique server identifier of the sender of this message- Returns:
- the unique server identifier of the source.
-
getDest
public short getDest()
Get the unique server id. of the addressee of this message- Returns:
- the unique server identifier of the destination.
-
getStamp
public int getStamp()
Get the stamp of this message- Returns:
- the stamp of this message.
-
getFrom
public AgentId getFrom()
-
getTo
public AgentId getTo()
-
getNot
public Notification getNot()
-
toString
public String toString()
Returns a string representation for this object.
-
appendToString
public StringBuffer appendToString(StringBuffer strbuf)
Adds a string representation for this object in the StringBuffer parameter.- Parameters:
strbuf- the String buffer to append.- Returns:
- A string representation of this object.
-
optToByte
byte optToByte()
-
optFromByte
void optFromByte(byte opt)
-
writeObject
private void writeObject(ObjectOutputStream out) throws IOException
The writeObject method is responsible for writing the state of the object for its particular class so that the corresponding readObject method can restore it. Be careful this method should only be used for saving messages in persistent storage, sending messages will be done by another way. It is also used for HA synchronization.- Parameters:
out- The output stream.- Throws:
IOException- an error occurs.
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
The readObject method is responsible for reading from the stream and restoring the classes fields. Be careful this method should only be used for restoring messages from persistent storage, receiving messages will be done by another way.- Parameters:
in- The input stream.- Throws:
IOException- an error occurs.ClassNotFoundException- an error occurs.
-
toStringId
final String toStringId()
-
isPersistent
public boolean isPersistent()
Tests if the associated notification is persistent or not.- Returns:
- true if the associated notification is persistent.
-
save
void save() throws IOException
Saves the object state on persistent storage.- Throws:
IOException- an error occurs.
-
load
static Message load(String name) throws IOException, ClassNotFoundException
Restores the object state from the persistent storage.- Parameters:
name- the persistent message name.- Returns:
- the loaded message.
- Throws:
IOException- when accessing the stored imageClassNotFoundException- if the stored image class may not be found
-
delete
void delete()
Deletes the current object in persistent storage.
-
alloc
static Message alloc()
Allocates a message from the pool.- Returns:
- the allocated message.
-
alloc
static Message alloc(AgentId from, AgentId to, Notification not)
Allocates a message from the pool.- Parameters:
from- id of source Agent.to- id of destination Agent.not- Notification to be signaled.- Returns:
- the allocated message.
-
free
void free()
Frees the message to the pool.
-
set
private void set(AgentId from, AgentId to, Notification not)
-
getEncodableClassId
public int getEncodableClassId()
Description copied from interface:EncodableReturns a unique class identifier.- Specified by:
getEncodableClassIdin interfaceEncodable- Returns:
- a unique class identifier
-
getEncodedSize
public int getEncodedSize() throws ExceptionDescription copied from interface:EncodableReturns the size of the byte array that results from the encoding of this object.- Specified by:
getEncodedSizein interfaceEncodable- Returns:
- the size of the encoded byte array
- Throws:
Exception- if an error occurs
-
encode
public void encode(Encoder encoder) throws Exception
Description copied from interface:EncodableEncodes the content of this object
-
-