Interface Message

  • All Superinterfaces:
    java.io.Serializable
    All Known Implementing Classes:
    MessageImpl

    public interface Message
    extends java.io.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

      • initialize

        void initialize​(int type,
                        java.util.Map<java.lang.String,​java.io.Serializable> messages)
                 throws java.lang.IllegalArgumentException
        Initializes this message with initial type and key-value pair's map
        Parameters:
        type - message type
        messages - key-value pair's message
        Throws:
        java.lang.IllegalArgumentException - if the argument is not valid
      • parseHeader

        int parseHeader​(byte[] bytes,
                        int offset)
                 throws java.lang.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:
        java.lang.IllegalArgumentException - if the argument is not valid or an unexpected error occurs
      • parseHeader

        int parseHeader​(Buffer buffer,
                        int offset)
                 throws java.lang.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:
        java.lang.IllegalArgumentException - if the argument is not valid or an unexpected error occurs
      • parseMessage

        void parseMessage​(byte[] bytes,
                          int offset,
                          int length)
                   throws java.lang.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:
        java.lang.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 java.lang.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:
        java.lang.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

        java.lang.Object addMessageElement​(java.lang.String key,
                                           java.io.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

        java.lang.Object getMessageElement​(java.lang.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

        java.lang.Object removeMessageElement​(java.lang.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

        java.util.Set<java.util.Map.Entry<java.lang.String,​java.io.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
      • getPlainByteBuffer

        java.nio.ByteBuffer getPlainByteBuffer()
                                        throws MessageIOException
        Returns a ByteBuffer of this message
        Returns:
        a ByteBuffer
        Throws:
        MessageIOException - if an I/O error occurs