public class MessageImpl extends Object implements Message
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) ----| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_TOTAL_MESSAGE_LENGTH |
static int |
HEADER_LENGTH |
static int |
UNSPECIFIED_MESSAGE_LENGTH |
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 and Description |
|---|
MessageImpl() |
MessageImpl(int type) |
MessageImpl(int type,
Map<String,Serializable> messages) |
| Modifier and Type | Method and Description |
|---|---|
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() |
public static final int DEFAULT_MAX_TOTAL_MESSAGE_LENGTH
public static final int UNSPECIFIED_MESSAGE_LENGTH
public static final int HEADER_LENGTH
public MessageImpl()
public MessageImpl(int type)
public MessageImpl(int type,
Map<String,Serializable> messages)
public static int getMaxMessageLength()
public static void setMaxMessageLength(int maxMsgLength)
public void initialize(int type,
Map<String,Serializable> messages)
throws IllegalArgumentException
initialize in interface Messagetype - message typemessages - key-value pair's messageIllegalArgumentException - if the argument is not validpublic int parseHeader(byte[] bytes,
int offset)
throws IllegalArgumentException
parseHeader in interface Messagebytes - byte array which should be parsedoffset - offset from which the message should be parsedIllegalArgumentException - if the argument is not valid or an unexpected error occurspublic int parseHeader(Buffer buffer, int offset) throws IllegalArgumentException
parseHeader in interface Messagebuffer - ByteBuffer which should be parsedoffset - offset from which the message should be parsedIllegalArgumentException - if the argument is not valid or an unexpected error occurspublic void parseMessage(byte[] bytes,
int offset,
int length)
throws IllegalArgumentException,
MessageIOException
parseMessage in interface Messagebytes - byte array which should be parsedoffset - offset from which the message should be parsedlength - the message's length(body length)IllegalArgumentException - if the argument is not valid or an unexpected error occursMessageIOException - if an I/O error occurspublic void parseMessage(Buffer buffer, int offset, int length) throws IllegalArgumentException, MessageIOException
parseMessage in interface Messagebuffer - ByteBuffer which should be parsedoffset - offset from which the message should be parsedlength - the message's length(body length)IllegalArgumentException - if the argument is not valid or an unexpected error occursMessageIOException - if an I/O error occurspublic int getVersion()
getVersion in interface Messagepublic int getType()
TYPE_CLUSTER_MANAGER_MESSAGE or
TYPE_HEALTH_MONITOR_MESSAGE's integer value or etc...public Object addMessageElement(String key, Serializable value)
addMessageElement in interface Messagekey - key with which the specified value is to be associatedvalue - serializable value to be associated with the specified keypublic Object getMessageElement(String key)
null if this message contains no mapping for the
keygetMessageElement in interface Messagekey - the key whose associated value is to be returnednull if this message contains no mapping for the
keypublic Object removeMessageElement(String key)
removeMessageElement in interface Messagekey - key whose mapping is to be removed from the messagepublic Set<Map.Entry<String,Serializable>> getMessageElements()
Set element view of the mappings contained in this messagegetMessageElements in interface Messagepublic ByteBuffer getPlainByteBuffer() throws MessageIOException
ByteBuffer of this messagegetPlainByteBuffer in interface MessageMessageIOException - if an I/O error occurspublic byte[] getPlainBytes()
throws MessageIOException
getPlainBytes in interface MessageMessageIOException - if an I/O error occurspublic Buffer getPlainBuffer(ExpandableBufferWriterFactory bufferWriterFactory) throws MessageIOException
MessageBuffer of this messagegetPlainBuffer in interface MessagebufferWriterFactory - ExpandableBufferWriterFactory.MessageIOException - if an I/O error occurspublic static String getStringType(int type)
Copyright © 2017–2020 Eclipse Foundation. All rights reserved.