com.sun.enterprise.mgmt.transport
Class MessageImpl

java.lang.Object
  extended by com.sun.enterprise.mgmt.transport.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

Field Summary
static int DEFAULT_MAX_TOTAL_MESSAGE_LENGTH
           
static int HEADER_LENGTH
           
static int UNSPECIFIED_MESSAGE_LENGTH
           
 
Fields inherited from interface com.sun.enterprise.mgmt.transport.Message
SOURCE_PEER_ID_TAG, TARGET_PEER_ID_TAG, TYPE_CLUSTER_MANAGER_MESSAGE, TYPE_HEALTH_MONITOR_MESSAGE, TYPE_MASTER_NODE_MESSAGE, TYPE_MCAST_MESSAGE, TYPE_PING_MESSAGE, TYPE_PONG_MESSAGE
 
Constructor Summary
MessageImpl()
           
MessageImpl(int type)
           
MessageImpl(int type, Map<String,Serializable> messages)
           
 
Method Summary
 Object addMessageElement(String key, Serializable value)
          Adds a special element to this message with key-value pair
static int getMaxMessageLength()
           
 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
 Set<Map.Entry<String,Serializable>> getMessageElements()
          Returns a Set element view of the mappings contained in this message
 Buffer getPlainBuffer(ExpandableBufferWriterFactory bufferWriterFactory)
          Returns a Buffer of this message
 ByteBuffer getPlainByteBuffer()
          Returns a ByteBuffer of this message
 byte[] getPlainBytes()
          Returns a byte array of this message
static String getStringType(int type)
           
 int getType()
          Returns the message's type i.g.
 int getVersion()
          Returns the message's version
 void initialize(int type, Map<String,Serializable> messages)
          Initializes this message with initial type and key-value pair's map
 int parseHeader(Buffer buffer, int offset)
          Parses the message's header from given ByteBuffer
 int parseHeader(byte[] bytes, int offset)
          Parses the message's header from given byte array
 void parseMessage(Buffer buffer, int offset, int length)
          Parses the message's body from given ByteBuffer
 void parseMessage(byte[] bytes, int offset, int length)
          Parses the message's body from given byte array
 Object removeMessageElement(String key)
          Removes the mapping for a key from this message if it is present
static void setMaxMessageLength(int maxMsgLength)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MAX_TOTAL_MESSAGE_LENGTH

public static final int DEFAULT_MAX_TOTAL_MESSAGE_LENGTH
See Also:
Constant Field Values

UNSPECIFIED_MESSAGE_LENGTH

public static final int UNSPECIFIED_MESSAGE_LENGTH
See Also:
Constant Field Values

HEADER_LENGTH

public static final int HEADER_LENGTH
See Also:
Constant Field Values
Constructor Detail

MessageImpl

public MessageImpl()

MessageImpl

public MessageImpl(int type)

MessageImpl

public MessageImpl(int type,
                   Map<String,Serializable> messages)
Method Detail

getMaxMessageLength

public static int getMaxMessageLength()

setMaxMessageLength

public static void setMaxMessageLength(int maxMsgLength)

initialize

public void initialize(int type,
                       Map<String,Serializable> messages)
                throws IllegalArgumentException
Initializes this message with initial type and key-value pair's map

Specified by:
initialize in interface Message
Parameters:
type - message type
messages - key-value pair's message
Throws:
IllegalArgumentException - if the argument is not valid

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

parseMessage

public void parseMessage(Buffer buffer,
                         int offset,
                         int length)
                  throws IllegalArgumentException,
                         MessageIOException
Parses the message's body from given ByteBuffer

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

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

getMessageElements

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

Specified by:
getMessageElements in interface Message
Returns:
a set element view of the mappings contained in this message

getPlainByteBuffer

public ByteBuffer getPlainByteBuffer()
                              throws MessageIOException
Returns a ByteBuffer of this message

Specified by:
getPlainByteBuffer in interface Message
Returns:
a ByteBuffer
Throws:
MessageIOException - if an I/O error occurs

getPlainBytes

public byte[] getPlainBytes()
                     throws MessageIOException
Returns a byte array of this message

Specified by:
getPlainBytes in interface Message
Returns:
byte array
Throws:
MessageIOException - if an I/O error occurs

getPlainBuffer

public Buffer getPlainBuffer(ExpandableBufferWriterFactory bufferWriterFactory)
                      throws MessageIOException
Description copied from interface: Message
Returns a Buffer of this message

Specified by:
getPlainBuffer in interface Message
Parameters:
bufferWriterFactory - ExpandableBufferWriterFactory.
Returns:
a Buffer
Throws:
MessageIOException - if an I/O error occurs

getStringType

public static String getStringType(int type)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.