Class 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
    • 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
        AgentId of sender.
      • to

        transient AgentId to
        AgentId of destination agent.
      • 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
      • stringId

        private transient String stringId
      • pool

        private static Pool pool
    • Constructor Detail

      • Message

        private Message()
        Construct a new message.
    • 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()
      • toString

        public String toString()
        Returns a string representation for this object.
        Overrides:
        toString in class Object
        Returns:
        A string representation of 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.
      • 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.
      • getEncodableClassId

        public int getEncodableClassId()
        Description copied from interface: Encodable
        Returns a unique class identifier.
        Specified by:
        getEncodableClassId in interface Encodable
        Returns:
        a unique class identifier
      • getEncodedSize

        public int getEncodedSize()
                           throws Exception
        Description copied from interface: Encodable
        Returns the size of the byte array that results from the encoding of this object.
        Specified by:
        getEncodedSize in interface Encodable
        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: Encodable
        Encodes the content of this object
        Specified by:
        encode in interface Encodable
        Parameters:
        encoder - the encoder to be used for the encoding
        Throws:
        Exception - if an error occurs
      • decode

        public void decode​(Decoder decoder)
                    throws Exception
        Description copied from interface: Encodable
        Decodes the content of this object
        Specified by:
        decode in interface Encodable
        Parameters:
        decoder - the decoder to be used for the decoding
        Throws:
        Exception - if an error occurs