Interface Message

  • All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    MessageImpl

    public interface Message
    extends Serializable
    This represents internal message interface which is sent and received on the top of Shoal management module Currently, six message types exist. TYPE_CLUSTER_MANAGER_MESSAGE, TYPE_HEALTH_MONITOR_MESSAGE, TYPE_MASTER_NODE_MESSAGE and TYPE_MCAST_MESSAGE are required. TYPE_PING_MESSAGE, TYPE_PONG_MESSAGE are optional. i.g. JXTA transport layer doesn't need it. This message can contain various elements with key-value pair. i.g. For the purpose of storing a source's PeerID from which the message is sent, SOURCE_PEER_ID_TAG key is used.
    Author:
    Bongjae Chang
    • Method Detail

      • parseHeader

        int parseHeader​(byte[] bytes,
                        int offset)
                 throws IllegalArgumentException
        Parses the message's header from given byte array
        Parameters:
        bytes - byte array which should be parsed
        offset - offset from which the message should be parsed
        Returns:
        the message's length(body length) which this message contains
        Throws:
        IllegalArgumentException - if the argument is not valid or an unexpected error occurs
      • parseHeader

        int parseHeader​(Buffer buffer,
                        int offset)
                 throws IllegalArgumentException
        Parses the message's header from given ByteBuffer
        Parameters:
        buffer - ByteBuffer which should be parsed
        offset - offset from which the message should be parsed
        Returns:
        the message's length(body length) which this message contains
        Throws:
        IllegalArgumentException - if the argument is not valid or an unexpected error occurs
      • parseMessage

        void parseMessage​(byte[] bytes,
                          int offset,
                          int length)
                   throws IllegalArgumentException,
                          MessageIOException
        Parses the message's body from given byte array
        Parameters:
        bytes - byte array which should be parsed
        offset - offset from which the message should be parsed
        length - the message's length(body length)
        Throws:
        IllegalArgumentException - if the argument is not valid or an unexpected error occurs
        MessageIOException - if an I/O error occurs
      • parseMessage

        void parseMessage​(Buffer buffer,
                          int offset,
                          int length)
                   throws IllegalArgumentException,
                          MessageIOException
        Parses the message's body from given ByteBuffer
        Parameters:
        buffer - ByteBuffer which should be parsed
        offset - offset from which the message should be parsed
        length - the message's length(body length)
        Throws:
        IllegalArgumentException - if the argument is not valid or an unexpected error occurs
        MessageIOException - if an I/O error occurs
      • getVersion

        int getVersion()
        Returns the message's version
        Returns:
        message version
      • getType

        int getType()
        Returns the message's type i.g. TYPE_CLUSTER_MANAGER_MESSAGE or TYPE_HEALTH_MONITOR_MESSAGE's integer value or etc...
        Returns:
        message type
      • addMessageElement

        Object addMessageElement​(String key,
                                 Serializable value)
        Adds a special element to this message with key-value pair
        Parameters:
        key - key with which the specified value is to be associated
        value - serializable value to be associated with the specified key
        Returns:
        the previous value associated with key, or null if there was no mapping for key
      • getMessageElement

        Object getMessageElement​(String key)
        Returns the value to which the specified key is mapped, or null if this message contains no mapping for the key
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this message contains no mapping for the key
      • removeMessageElement

        Object removeMessageElement​(String key)
        Removes the mapping for a key from this message if it is present
        Parameters:
        key - key whose mapping is to be removed from the message
        Returns:
        the previous value associated with key, or null if there was no mapping for key
      • getMessageElements

        Set<Map.Entry<String,​Serializable>> getMessageElements()
        Returns a Set element view of the mappings contained in this message
        Returns:
        a set element view of the mappings contained in this message