Class MessageImpl
- java.lang.Object
-
- com.sun.enterprise.mgmt.transport.MessageImpl
-
- All Implemented Interfaces:
Message,java.io.Serializable
public class MessageImpl extends java.lang.Object implements Message
This is a defaultMessage'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
Fields Modifier and Type Field Description static intDEFAULT_MAX_TOTAL_MESSAGE_LENGTHstatic intHEADER_LENGTHstatic intUNSPECIFIED_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
Constructors Constructor Description MessageImpl()MessageImpl(int type)MessageImpl(int type, java.util.Map<java.lang.String,java.io.Serializable> messages)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectaddMessageElement(java.lang.String key, java.io.Serializable value)Adds a special element to this message with key-value pairstatic intgetMaxMessageLength()java.lang.ObjectgetMessageElement(java.lang.String key)Returns the value to which the specified key is mapped, ornullif this message contains no mapping for the keyjava.util.Set<java.util.Map.Entry<java.lang.String,java.io.Serializable>>getMessageElements()Returns aSetelement view of the mappings contained in this messageBuffergetPlainBuffer(ExpandableBufferWriterFactory bufferWriterFactory)Returns aBufferof this messagejava.nio.ByteBuffergetPlainByteBuffer()Returns aByteBufferof this messagebyte[]getPlainBytes()Returns a byte array of this messagestatic java.lang.StringgetStringType(int type)intgetType()Returns the message's type i.g.intgetVersion()Returns the message's versionvoidinitialize(int type, java.util.Map<java.lang.String,java.io.Serializable> messages)Initializes this message with initial type and key-value pair's mapintparseHeader(byte[] bytes, int offset)Parses the message's header from given byte arrayintparseHeader(Buffer buffer, int offset)Parses the message's header from given ByteBuffervoidparseMessage(byte[] bytes, int offset, int length)Parses the message's body from given byte arrayvoidparseMessage(Buffer buffer, int offset, int length)Parses the message's body from given ByteBufferjava.lang.ObjectremoveMessageElement(java.lang.String key)Removes the mapping for a key from this message if it is presentstatic voidsetMaxMessageLength(int maxMsgLength)java.lang.StringtoString()
-
-
-
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
-
-
Method Detail
-
getMaxMessageLength
public static int getMaxMessageLength()
-
setMaxMessageLength
public static void setMaxMessageLength(int maxMsgLength)
-
initialize
public void initialize(int type, java.util.Map<java.lang.String,java.io.Serializable> messages) throws java.lang.IllegalArgumentExceptionInitializes this message with initial type and key-value pair's map- Specified by:
initializein interfaceMessage- Parameters:
type- message typemessages- key-value pair's message- Throws:
java.lang.IllegalArgumentException- if the argument is not valid
-
parseHeader
public int parseHeader(byte[] bytes, int offset) throws java.lang.IllegalArgumentExceptionParses the message's header from given byte array- Specified by:
parseHeaderin interfaceMessage- Parameters:
bytes- byte array which should be parsedoffset- 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
public int parseHeader(Buffer buffer, int offset) throws java.lang.IllegalArgumentException
Parses the message's header from given ByteBuffer- Specified by:
parseHeaderin interfaceMessage- Parameters:
buffer- ByteBuffer which should be parsedoffset- 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
public void parseMessage(byte[] bytes, int offset, int length) throws java.lang.IllegalArgumentException, MessageIOExceptionParses the message's body from given byte array- Specified by:
parseMessagein interfaceMessage- Parameters:
bytes- byte array which should be parsedoffset- offset from which the message should be parsedlength- the message's length(body length)- Throws:
java.lang.IllegalArgumentException- if the argument is not valid or an unexpected error occursMessageIOException- if an I/O error occurs
-
parseMessage
public void parseMessage(Buffer buffer, int offset, int length) throws java.lang.IllegalArgumentException, MessageIOException
Parses the message's body from given ByteBuffer- Specified by:
parseMessagein interfaceMessage- Parameters:
buffer- ByteBuffer which should be parsedoffset- offset from which the message should be parsedlength- the message's length(body length)- Throws:
java.lang.IllegalArgumentException- if the argument is not valid or an unexpected error occursMessageIOException- if an I/O error occurs
-
getVersion
public int getVersion()
Returns the message's version- Specified by:
getVersionin interfaceMessage- Returns:
- message version
-
getType
public int getType()
Returns the message's type i.g.TYPE_CLUSTER_MANAGER_MESSAGEorTYPE_HEALTH_MONITOR_MESSAGE's integer value or etc...
-
addMessageElement
public java.lang.Object addMessageElement(java.lang.String key, java.io.Serializable value)Adds a special element to this message with key-value pair- Specified by:
addMessageElementin interfaceMessage- Parameters:
key- key with which the specified value is to be associatedvalue- 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 java.lang.Object getMessageElement(java.lang.String key)
Returns the value to which the specified key is mapped, ornullif this message contains no mapping for the key- Specified by:
getMessageElementin interfaceMessage- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this message contains no mapping for the key
-
removeMessageElement
public java.lang.Object removeMessageElement(java.lang.String key)
Removes the mapping for a key from this message if it is present- Specified by:
removeMessageElementin interfaceMessage- 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 java.util.Set<java.util.Map.Entry<java.lang.String,java.io.Serializable>> getMessageElements()
Returns aSetelement view of the mappings contained in this message- Specified by:
getMessageElementsin interfaceMessage- Returns:
- a set element view of the mappings contained in this message
-
getPlainByteBuffer
public java.nio.ByteBuffer getPlainByteBuffer() throws MessageIOExceptionReturns aByteBufferof this message- Specified by:
getPlainByteBufferin interfaceMessage- Returns:
- a ByteBuffer
- Throws:
MessageIOException- if an I/O error occurs
-
getPlainBytes
public byte[] getPlainBytes() throws MessageIOExceptionReturns a byte array of this message- Specified by:
getPlainBytesin interfaceMessage- Returns:
- byte array
- Throws:
MessageIOException- if an I/O error occurs
-
getPlainBuffer
public Buffer getPlainBuffer(ExpandableBufferWriterFactory bufferWriterFactory) throws MessageIOException
Description copied from interface:MessageReturns aBufferof this message- Specified by:
getPlainBufferin interfaceMessage- Parameters:
bufferWriterFactory-ExpandableBufferWriterFactory.- Returns:
- a Buffer
- Throws:
MessageIOException- if an I/O error occurs
-
getStringType
public static java.lang.String getStringType(int type)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-