Class MessageImpl

  • All Implemented Interfaces:
    Message, Serializable

    public class MessageImpl
    extends Object
    implements Message
    This is a default Message's implementation The byte array or ByteBuffer which represent this message's low level data will be cached if this message is not modified Here are this message's structure ---- [packet] magic(4) + version(4) + type(4) + messages_length(4) + messages(message_length) [messages] message_count(4) + message_key1 + message_value1 + message_key2 + message_value2 + ...(message_count) ----
    Author:
    Bongjae Chang
    See Also:
    Serialized Form
    • Constructor Detail

      • MessageImpl

        public MessageImpl()
      • MessageImpl

        public MessageImpl​(int type)
    • Method Detail

      • getMaxMessageLength

        public static int getMaxMessageLength()
      • setMaxMessageLength

        public static void setMaxMessageLength​(int maxMsgLength)
      • parseHeader

        public int parseHeader​(byte[] bytes,
                               int offset)
                        throws IllegalArgumentException
        Parses the message's header from given byte array
        Specified by:
        parseHeader in interface Message
        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

        public int parseHeader​(Buffer buffer,
                               int offset)
                        throws IllegalArgumentException
        Parses the message's header from given ByteBuffer
        Specified by:
        parseHeader in interface Message
        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

        public void parseMessage​(byte[] bytes,
                                 int offset,
                                 int length)
                          throws IllegalArgumentException,
                                 MessageIOException
        Parses the message's body from given byte array
        Specified by:
        parseMessage in interface Message
        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
      • getVersion

        public int getVersion()
        Returns the message's version
        Specified by:
        getVersion in interface Message
        Returns:
        message version
      • getType

        public int getType()
        Returns the message's type i.g. TYPE_CLUSTER_MANAGER_MESSAGE or TYPE_HEALTH_MONITOR_MESSAGE's integer value or etc...
        Specified by:
        getType in interface Message
        Returns:
        message type
      • addMessageElement

        public Object addMessageElement​(String key,
                                        Serializable value)
        Adds a special element to this message with key-value pair
        Specified by:
        addMessageElement in interface Message
        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

        public 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
        Specified by:
        getMessageElement in interface Message
        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

        public Object removeMessageElement​(String key)
        Removes the mapping for a key from this message if it is present
        Specified by:
        removeMessageElement in interface Message
        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
      • getStringType

        public static String getStringType​(int type)