Package org.jgroups

Class BaseMessage

    • Field Detail

      • headers

        protected volatile Header[] headers
      • flags

        protected volatile short flags
      • transient_flags

        protected volatile byte transient_flags
    • Constructor Detail

      • BaseMessage

        public BaseMessage()
      • BaseMessage

        public BaseMessage​(Address dest)
        Constructs a message given a destination address
        Parameters:
        dest - The Address of the receiver. If it is null, then the message is sent to the group. Otherwise, it is sent to a single member.
    • Method Detail

      • getDest

        public Address getDest()
        Description copied from interface: Message
        Returns the destination address to send the message to. A null value sends the message to all cluster members
        Specified by:
        getDest in interface Message
      • setDest

        public Message setDest​(Address new_dest)
        Description copied from interface: Message
        Sets the destination address to send the message to. A null value sends the message to all cluster members
        Specified by:
        setDest in interface Message
      • getSrc

        public Address getSrc()
        Description copied from interface: Message
        Returns the address of the sender
        Specified by:
        getSrc in interface Message
      • setSrc

        public Message setSrc​(Address new_src)
        Description copied from interface: Message
        Sets the address of the sender of this message
        Specified by:
        setSrc in interface Message
      • getNumHeaders

        public int getNumHeaders()
        Description copied from interface: Message
        Returns the number of headers
        Specified by:
        getNumHeaders in interface Message
      • getHeaders

        public java.util.Map<java.lang.Short,​Header> getHeaders()
        Description copied from interface: Message
        Returns a hashmap of all header IDs and their associated headers
        Specified by:
        getHeaders in interface Message
      • headers

        public Header[] headers()
      • printHeaders

        public java.lang.String printHeaders()
        Description copied from interface: Message
        Returns a pretty-printed string of the headers
        Specified by:
        printHeaders in interface Message
      • setFlag

        public Message setFlag​(Message.Flag... flags)
        Sets a number of flags in a message
        Specified by:
        setFlag in interface Message
        Parameters:
        flags - The flag or flags
        Returns:
        A reference to the message
      • setFlag

        public Message setFlag​(short flag,
                               boolean transient_flags,
                               boolean xor)
        Description copied from interface: Message
        Sets the flags as a short; this way, multiple flags can be set in one operation
        Specified by:
        setFlag in interface Message
        Parameters:
        flag - The flag to be set (as a short). Overrides existing flags (no xor-ing)
        transient_flags - True if the flag is transient, false otherwise
        xor - When true, existing flags will be xor-ed with flag, otherwise not
      • getFlags

        public short getFlags​(boolean transient_flags)
        Returns the internal representation of flags. Don't use this, as the internal format might change at any time ! This is only used by unit test code
        Specified by:
        getFlags in interface Message
        Parameters:
        transient_flags - Returns transient flags if true, else regular flags
        Returns:
      • clearFlag

        public Message clearFlag​(Message.Flag... flags)
        Clears a number of flags in a message
        Specified by:
        clearFlag in interface Message
        Parameters:
        flags - The flags
        Returns:
        A reference to the message
      • isFlagSet

        public boolean isFlagSet​(Message.Flag flag)
        Checks if a given flag is set
        Specified by:
        isFlagSet in interface Message
        Parameters:
        flag - The flag
        Returns:
        Whether the flag is currently set
      • setFlagIfAbsent

        public boolean setFlagIfAbsent​(Message.TransientFlag flag)
        Atomically checks if a given flag is set and - if not - sets it. When multiple threads concurrently call this method with the same flag, only one of them will be able to set the flag
        Specified by:
        setFlagIfAbsent in interface Message
        Parameters:
        flag -
        Returns:
        True if the flag could be set, false if not (was already set)
      • copy

        public Message copy​(boolean copy_payload,
                            boolean copy_headers)
        Copies the source- and destination addresses, flags and headers (if copy_headers is true).
        If copy_payload is set, then method copyPayload(Message) of the subclass will be called, which is responsible for copying the payload specific to that message type.
        Note that for headers, only the arrays holding references to the headers are copied, not the headers themselves ! The consequence is that the headers array of the copy hold the *same* references as the original, so do *not* modify the headers ! If you want to change a header, copy it and call Message.putHeader(short,Header) again.
        Specified by:
        copy in interface Message
        Parameters:
        copy_payload - If true, the payload is copied, else it is null in the copied message
        copy_headers - If true, the headers are copied
      • putHeader

        public Message putHeader​(short id,
                                 Header hdr)
        Puts a header given an ID into the hashmap. Overwrites potential existing entry.
        Specified by:
        putHeader in interface Message
      • putHeaderIfAbsent

        public Message putHeaderIfAbsent​(short id,
                                         Header hdr)
        Description copied from interface: Message
        Adds a header to a message if not present
        Specified by:
        putHeaderIfAbsent in interface Message
      • getHeader

        public <T extends Header> T getHeader​(short id)
        Description copied from interface: Message
        Gets a header from the message
        Specified by:
        getHeader in interface Message
      • clearHeaders

        public Message clearHeaders()
        Removes all headers: use carefully!
        Specified by:
        clearHeaders in interface Message
      • setPayload

        public Message setPayload​(java.lang.Object pl)
        Description copied from interface: Message
        Sets the payload
        Specified by:
        setPayload in interface Message
        Parameters:
        pl - The paylolad
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • size

        public int size()
        Description copied from interface: Message
        Returns the exact size of the marshalled message
        Specified by:
        size in interface Message
        Returns:
        The number of bytes for the marshalled message
      • writeTo

        public void writeTo​(java.io.DataOutput out)
                     throws java.io.IOException
        Description copied from interface: Streamable
        Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed
        Specified by:
        writeTo in interface Streamable
        Throws:
        java.io.IOException
      • writeToNoAddrs

        public void writeToNoAddrs​(Address src,
                                   java.io.DataOutput out)
                            throws java.io.IOException
        Description copied from interface: Message
        Writes the message to an output stream excluding the destination (and possibly source) address
        Specified by:
        writeToNoAddrs in interface Message
        Throws:
        java.io.IOException
      • readFrom

        public void readFrom​(java.io.DataInput in)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException
        Description copied from interface: Streamable
        Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed
        Specified by:
        readFrom in interface Streamable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • putHeader

        protected Message putHeader​(short id,
                                    Header hdr,
                                    boolean replace_if_present)
      • copyPayload

        protected Message copyPayload​(Message copy)
        Copies the payload
      • createHeaders

        protected static Header[] createHeaders​(int size)