Interface Message
- All Superinterfaces:
Constructable<Message>,SizeStreamable,Streamable
- All Known Implementing Classes:
BaseMessage,BatchMessage,BytesMessage,CompositeMessage,EmptyMessage,FragmentedMessage,LongMessage,NioMessage,ObjectMessage
Subclasses define different types of payloads, e.g. byte arrays, ByteBuffers, Objects etc.
- Since:
- 5.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final short -
Method Summary
Modifier and TypeMethodDescriptionclearFlag(Message.Flag... flags) Removes a number of flags from the message.clearFlag(Message.TransientFlag... flags) Removes a number of transient flags from the message.Removes all headers: use carefully!copy(boolean copy_payload, boolean copy_headers) Copies a messagedefault Addressdest()default Messagebyte[]getArray()Returns a reference to the payload (byte array).getDest()Returns the destination address to send the message to.default shortgetFlags()shortgetFlags(boolean transient_flags) Returns the flags as an or-ed short<T extends Header>
TgetHeader(short id) Gets a header from the messageReturns a hashmap of all header IDs and their associated headersintReturns the length of the byte[] array payload.intReturns the number of headers<T> TGets an object from the payload.intReturns the offset of the byte[] array at which user data starts.<T> TReturns the payload without any conversion (e.g.getSrc()Returns the address of the sendershortgetType()Returns the type of the message, e.g.booleanhasArray()Returns true if this message has a byte[] array as payload (even if it's null!), false otherwisebooleanReturns true if the message has a payload, e.g.booleanisFlagSet(Message.Flag flag) Returns true if a flag is set, false otherwisebooleanReturns true if a transient flag is set, false otherwiseReturns a pretty-printed string of the headersAdds a header to the messageputHeaderIfAbsent(short id, Header hdr) Adds a header to a message if not presentvoidreadPayload(DataInput in) default MessagesetArray(byte[] b) setArray(byte[] b, int offset, int length) Sets the byte array in a message.Sets the byte array in a message.Sets the destination address to send the message to.default MessagesetFlag(short flag, boolean transient_flags) Sets the flags as a short; this way, multiple flags can be set in one operationsetFlag(short flag, boolean transient_flags, boolean xor) Sets the flags as a short; this way, multiple flags can be set in one operationsetFlag(Message.Flag... flags) Sets one or more flags (xor-ing existing flags)setFlag(Message.TransientFlag... flags) Sets one or more transient flags (xor-ing).booleanAtomically sets a transient flag if not set.Sets an object in a message.setPayload(Object pl) Sets the payloadSets the address of the sender of this messageintsize()Returns the exact size of the marshalled messagedefault Addresssrc()default MessagevoidwritePayload(DataOutput out) voidwriteToNoAddrs(Address src, DataOutput out) Writes the message to an output stream excluding the destination (and possibly source) addressMethods inherited from interface org.jgroups.Constructable
createMethods inherited from interface org.jgroups.util.SizeStreamable
serializedSizeMethods inherited from interface org.jgroups.util.Streamable
readFrom, writeTo
-
Field Details
-
BYTES_MSG
static final short BYTES_MSG- See Also:
-
NIO_MSG
static final short NIO_MSG- See Also:
-
EMPTY_MSG
static final short EMPTY_MSG- See Also:
-
OBJ_MSG
static final short OBJ_MSG- See Also:
-
LONG_MSG
static final short LONG_MSG- See Also:
-
COMPOSITE_MSG
static final short COMPOSITE_MSG- See Also:
-
FRAG_MSG
static final short FRAG_MSG- See Also:
-
EARLYBATCH_MSG
static final short EARLYBATCH_MSG- See Also:
-
-
Method Details
-
getType
short getType()Returns the type of the message, e.g. BYTES_MSG, OBJ_MSG etc -
getDest
Address getDest()Returns the destination address to send the message to. A null value sends the message to all cluster members -
dest
-
setDest
Sets the destination address to send the message to. A null value sends the message to all cluster members -
dest
-
getSrc
Address getSrc()Returns the address of the sender -
src
-
setSrc
Sets the address of the sender of this message -
src
-
putHeader
Adds a header to the message -
putHeaderIfAbsent
Adds a header to a message if not present -
getHeader
Gets a header from the message -
getHeaders
Returns a hashmap of all header IDs and their associated headers -
getNumHeaders
int getNumHeaders()Returns the number of headers -
printHeaders
String printHeaders()Returns a pretty-printed string of the headers -
clearHeaders
Message clearHeaders()Removes all headers: use carefully! -
setFlag
Sets one or more flags (xor-ing existing flags) -
setFlag
Sets the flags as a short; this way, multiple flags can be set in one operation- Parameters:
flag- The flag to be set (as a short). Overrides existing flags (no xor-ing)transient_flags- True if the flag is transient, false otherwise
-
setFlag
Sets the flags as a short; this way, multiple flags can be set in one operation- Parameters:
flag- The flag to be set (as a short). Overrides existing flags (no xor-ing)transient_flags- True if the flag is transient, false otherwisexor- When true, existing flags will be xor-ed with flag, otherwise not
-
setFlag
Sets one or more transient flags (xor-ing). Transient flags are not marshalled -
setFlagIfAbsent
Atomically sets a transient flag if not set. Returns true if the flags was set, else false (already set) -
getFlags
short getFlags(boolean transient_flags) Returns the flags as an or-ed short- Parameters:
transient_flags- Returns transient flags if true, else regular flags
-
getFlags
default short getFlags() -
clearFlag
Removes a number of flags from the message. No-op for a flag if it is not set -
clearFlag
Removes a number of transient flags from the message. No-op for a flag if it is not set -
isFlagSet
Returns true if a flag is set, false otherwise -
isFlagSet
Returns true if a transient flag is set, false otherwise -
copy
Copies a message- Parameters:
copy_payload- If true, the payload is copied, else it is null in the copied messagecopy_headers- If true, the headers are copied
-
hasPayload
boolean hasPayload()Returns true if the message has a payload, e.g. a byte[] array in aBytesMessageor an object in anObjectMessage. This is more generic thanhasArray(), as it is not just applicable to a byte array.- Returns:
- True if the message has a payload
-
hasArray
boolean hasArray()Returns true if this message has a byte[] array as payload (even if it's null!), false otherwise -
getArray
byte[] getArray()Returns a reference to the payload (byte array). Note that this array should not be modified as we do not copy the array on copy() or clone(): the array of the copied message is simply a reference to the old array.Even if offset and length are used: we return the entire array, not a subset.
Throws an exception if the message does not have a byte[] array payload (
hasArray()is false).Note that this is a convenience method, as most messages are of type
BytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload. -
getOffset
int getOffset()Returns the offset of the byte[] array at which user data starts. Throws an exception if the message does not have a byte[] array payload (ifhasArray()is false).Note that this is a convenience method, as most messages are of type
BytesMessage. -
getLength
int getLength()Returns the length of the byte[] array payload. If the message does not have a byte[] array payload (hasArray()is false), then the serialized size may be returned, or an implementation may choose to throw an exception -
setArray
Sets the byte array in a message.Throws an exception if the message does not have a byte[] array payload (
hasArray()is false).Note that this is a convenience method, as most messages are of type
BytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload. -
setArray
-
setArray
Sets the byte array in a message.Throws an exception if the message does not have a byte[] array payload (
hasArray()is false).Note that this is a convenience method, as most messages are of type
BytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload. -
getObject
<T> T getObject()Gets an object from the payload. If the payload is a byte[] array (e.g. as inBytesMessage), an attempt to de-serialize the array into an object is made, and the object returned.If the payload is an object (e.g. as is the case in
ObjectMessage), the object will be returned directly. -
setObject
Sets an object in a message. In aObjectMessage, the object is set directly. In aBytesMessage, the object is serialized into a byte[] array and then the array is set as the payload of the message -
getPayload
<T> T getPayload()Returns the payload without any conversion (e.g. as ingetObject()orgetArray())- Type Parameters:
T- The type of the object- Returns:
- The payload
-
setPayload
Sets the payload- Parameters:
pl- The paylolad
-
size
int size()Returns the exact size of the marshalled message- Returns:
- The number of bytes for the marshalled message
-
writeToNoAddrs
Writes the message to an output stream excluding the destination (and possibly source) address- Throws:
IOException
-
writePayload
- Throws:
IOException
-
readPayload
- Throws:
IOExceptionClassNotFoundException
-