Package org.jgroups

Interface Message

    • Method Detail

      • getType

        short getType()
        Returns the type of the message, e.g. BYTES_MSG, OBJ_MSG etc
      • getDest

        Address getDest()
        Returns the destination address to send the message to. A null value sends the message to all cluster members
      • setDest

        Message setDest​(Address new_dest)
        Sets the destination address to send the message to. A null value sends the message to all cluster members
      • getSrc

        Address getSrc()
        Returns the address of the sender
      • setSrc

        Message setSrc​(Address new_src)
        Sets the address of the sender of this message
      • putHeader

        Message putHeader​(short id,
                          Header hdr)
        Adds a header to the message
      • getHeader

        <T extends Header> T getHeader​(short id)
        Gets a header from the message
      • getHeaders

        java.util.Map<java.lang.Short,​Header> getHeaders()
        Returns a hashmap of all header IDs and their associated headers
      • getNumHeaders

        int getNumHeaders()
        Returns the number of headers
      • printHeaders

        java.lang.String printHeaders()
        Returns a pretty-printed string of the headers
      • clearHeaders

        Message clearHeaders()
        Removes all headers: use carefully!
      • setFlag

        Message setFlag​(Message.Flag... flags)
        Sets one or more flags (xor-ing existing flags)
      • setFlag

        default Message setFlag​(short flag,
                                boolean transient_flags)
        Sets the flags as a short; this way, multiple flags can be set in one operation
        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
      • setFlag

        Message setFlag​(short flag,
                        boolean transient_flags,
                        boolean xor)
        Sets the flags as a short; this way, multiple flags can be set in one operation
        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
      • setFlag

        Message setFlag​(Message.TransientFlag... flags)
        Sets one or more transient flags (xor-ing). Transient flags are not marshalled
      • setFlagIfAbsent

        boolean setFlagIfAbsent​(Message.TransientFlag flag)
        Atomically sets a transient flag if not set. Returns true if the flags was set, else false (already set)
      • getFlags

        short getFlags​(boolean transient_flags)
        Returns the flags as an or-ed short
        Parameters:
        transient_flags - Returns transient flags if true, else regular flags
      • getFlags

        default short getFlags()
      • clearFlag

        Message clearFlag​(Message.Flag... flags)
        Removes a number of flags from the message. No-op for a flag if it is not set
      • clearFlag

        Message clearFlag​(Message.TransientFlag... flags)
        Removes a number of transient flags from the message. No-op for a flag if it is not set
      • isFlagSet

        boolean isFlagSet​(Message.Flag flag)
        Returns true if a flag is set, false otherwise
      • isFlagSet

        boolean isFlagSet​(Message.TransientFlag flag)
        Returns true if a transient flag is set, false otherwise
      • copy

        Message copy​(boolean copy_payload,
                     boolean copy_headers)
        Copies a 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
      • hasPayload

        boolean hasPayload()
        Returns true if the message has a payload, e.g. a byte[] array in a BytesMessage or an object in an ObjectMessage. This is more generic than hasArray(), as it is not just applicable to a byte array.
        Returns:
        True if the message has a payload
      • hasArray

        boolean hasArray()
        Returns true if this message has a byte[] array as payload (even if it's null!), false otherwise
      • getArray

        byte[] getArray()
        Returns a reference to the payload (byte array). Note that this array should not be modified as we do not copy the array on copy() or clone(): the array of the copied message is simply a reference to the old array.
        Even if offset and length are used: we return the entire array, not a subset.
        Throws an exception if the message does not have a byte[] array payload (hasArray() is false).
        Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.
      • getOffset

        int getOffset()
        Returns the offset of the byte[] array at which user data starts. Throws an exception if the message does not have a byte[] array payload (if hasArray() is false).
        Note that this is a convenience method, as most messages are of type BytesMessage.
      • getLength

        int getLength()
        Returns the length of the byte[] array payload. If the message does not have a byte[] array payload (hasArray() is false), then the serialized size may be returned, or an implementation may choose to throw an exception
      • setArray

        Message setArray​(byte[] b,
                         int offset,
                         int length)
        Sets the byte array in a message.
        Throws an exception if the message does not have a byte[] array payload (hasArray() is false).
        Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.
      • setArray

        default Message setArray​(byte[] b)
      • setArray

        Message setArray​(ByteArray buf)
        Sets the byte array in a message.
        Throws an exception if the message does not have a byte[] array payload (hasArray() is false).
        Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.
      • getObject

        <T> T getObject()
        Gets an object from the payload. If the payload is a byte[] array (e.g. as in BytesMessage), an attempt to de-serialize the array into an object is made, and the object returned.
        If the payload is an object (e.g. as is the case in ObjectMessage), the object will be returned directly.
      • setObject

        Message setObject​(java.lang.Object obj)
        Sets an object in a message. In a ObjectMessage, the object is set directly. In a BytesMessage, the object is serialized into a byte[] array and then the array is set as the payload of the message
      • getPayload

        <T> T getPayload()
        Returns the payload without any conversion (e.g. as in getObject() or getArray())
        Type Parameters:
        T - The type of the object
        Returns:
        The payload
      • setPayload

        Message setPayload​(java.lang.Object pl)
        Sets the payload
        Parameters:
        pl - The paylolad
      • size

        int size()
        Returns the exact size of the marshalled message
        Returns:
        The number of bytes for the marshalled message
      • writeToNoAddrs

        void writeToNoAddrs​(Address src,
                            java.io.DataOutput out,
                            short... excluded_headers)
                     throws java.io.IOException
        Writes the message to an output stream excluding the destination (and possibly source) address, plus a number of headers
        Throws:
        java.io.IOException
      • writePayload

        void writePayload​(java.io.DataOutput out)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readPayload

        void readPayload​(java.io.DataInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException