Package org.jgroups
Class BaseMessage
java.lang.Object
org.jgroups.BaseMessage
- All Implemented Interfaces:
Constructable<Message>,Message,SizeStreamable,Streamable
- Direct Known Subclasses:
BatchMessage,BytesMessage,CompositeMessage,EmptyMessage,LongMessage,NioMessage,ObjectMessage
A common superclass for all
Message implementations. It contains functionality to manage headers, flags and
destination and source addresses.- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgroups.Message
Message.Flag, Message.TransientFlag -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Address(package private) static final byteprotected shortprotected Header[]protected Address(package private) static final byteprotected byteFields inherited from interface org.jgroups.Message
BYTES_MSG, COMPOSITE_MSG, EARLYBATCH_MSG, EMPTY_MSG, FRAG_MSG, LONG_MSG, NIO_MSG, OBJ_MSG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclearFlag(Message.Flag... flags) Clears a number of flags in a messageclearFlag(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 the source- and destination addresses, flags and headers (if copy_headers is true).protected MessagecopyPayload(Message copy) Copies the payloadprotected static Header[]createHeaders(int size) getDest()Returns the destination address to send the message to.shortgetFlags(boolean transient_flags) Returns the internal representation of flags.<T extends Header>
TgetHeader(short id) Gets a header from the messageReturns a hashmap of all header IDs and their associated headersintReturns the number of headers<T> TReturns the payload without any conversion (e.g.getSrc()Returns the address of the senderHeader[]headers()booleanisFlagSet(Message.Flag flag) Checks if a given flag is setbooleanReturns true if a transient flag is set, false otherwiseReturns a pretty-printed string of the headersPuts a header given an ID into the hashmap.protected MessageputHeaderIfAbsent(short id, Header hdr) Adds a header to a message if not presentvoidRead the state of the current object (including superclasses) from instream Note that the input stream must not be closedintReturns the size (in bytes) of the marshalled objectSets the destination address to send the message to.setFlag(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 a number of flags in a messagesetFlag(Message.TransientFlag... flags) Same assetFlag(Flag...)except that transient flags are not marshalledbooleanAtomically checks if a given flag is set and - if not - sets it.setPayload(Object pl) Sets the payloadSets the address of the sender of this messageintsize()Returns the exact size of the marshalled messagetoString()voidwriteTo(DataOutput out) Write the entire state of the current object (including superclasses) to outstream.voidwriteToNoAddrs(Address src, DataOutput out) Writes the message to an output stream excluding the destination (and possibly source) addressMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jgroups.Constructable
create
-
Field Details
-
dest
-
sender
-
headers
-
flags
protected volatile short flags -
transient_flags
protected volatile byte transient_flags -
DEST_SET
static final byte DEST_SET- See Also:
-
SRC_SET
static final byte SRC_SET- See Also:
-
-
Constructor Details
-
BaseMessage
public BaseMessage() -
BaseMessage
Constructs a message given a destination address- Parameters:
dest- The Address of the receiver. If it is null, then the message is sent to the group. Otherwise, it is sent to a single member.
-
-
Method Details
-
getDest
Description copied from interface:MessageReturns the destination address to send the message to. A null value sends the message to all cluster members -
setDest
Description copied from interface:MessageSets the destination address to send the message to. A null value sends the message to all cluster members -
getSrc
Description copied from interface:MessageReturns the address of the sender -
setSrc
Description copied from interface:MessageSets the address of the sender of this message -
getNumHeaders
public int getNumHeaders()Description copied from interface:MessageReturns the number of headers- Specified by:
getNumHeadersin interfaceMessage
-
getHeaders
Description copied from interface:MessageReturns a hashmap of all header IDs and their associated headers- Specified by:
getHeadersin interfaceMessage
-
headers
-
headers
-
printHeaders
Description copied from interface:MessageReturns a pretty-printed string of the headers- Specified by:
printHeadersin interfaceMessage
-
setFlag
Sets a number of flags in a message -
setFlag
Same assetFlag(Flag...)except that transient flags are not marshalled -
setFlag
Description copied from interface:MessageSets the flags as a short; this way, multiple flags can be set in one operation -
getFlags
public short getFlags(boolean transient_flags) Returns the internal representation of flags. Don't use this, as the internal format might change at any time ! This is only used by unit test code -
clearFlag
Clears a number of flags in a message -
clearFlag
Description copied from interface:MessageRemoves a number of transient flags from the message. No-op for a flag if it is not set -
isFlagSet
Checks if a given flag is set -
isFlagSet
Description copied from interface:MessageReturns true if a transient flag is set, false otherwise -
setFlagIfAbsent
Atomically checks if a given flag is set and - if not - sets it. When multiple threads concurrently call this method with the same flag, only one of them will be able to set the flag- Specified by:
setFlagIfAbsentin interfaceMessage- Parameters:
flag-- Returns:
- True if the flag could be set, false if not (was already set)
-
copy
Copies the source- and destination addresses, flags and headers (if copy_headers is true).If copy_payload is set, then method
copyPayload(Message)of the subclass will be called, which is responsible for copying the payload specific to that message type.Note that for headers, only the arrays holding references to the headers are copied, not the headers themselves ! The consequence is that the headers array of the copy hold the *same* references as the original, so do *not* modify the headers ! If you want to change a header, copy it and call
Message.putHeader(short,Header)again. -
putHeader
Puts a header given an ID into the hashmap. Overwrites potential existing entry. -
putHeaderIfAbsent
Description copied from interface:MessageAdds a header to a message if not present- Specified by:
putHeaderIfAbsentin interfaceMessage
-
getHeader
Description copied from interface:MessageGets a header from the message -
clearHeaders
Removes all headers: use carefully!- Specified by:
clearHeadersin interfaceMessage
-
getPayload
public <T> T getPayload()Description copied from interface:MessageReturns the payload without any conversion (e.g. as inMessage.getObject()orMessage.getArray())- Specified by:
getPayloadin interfaceMessage- Type Parameters:
T- The type of the object- Returns:
- The payload
-
setPayload
Description copied from interface:MessageSets the payload- Specified by:
setPayloadin interfaceMessage- Parameters:
pl- The paylolad
-
toString
-
serializedSize
public int serializedSize()Description copied from interface:SizeStreamableReturns the size (in bytes) of the marshalled object- Specified by:
serializedSizein interfaceSizeStreamable
-
size
public int size()Description copied from interface:MessageReturns the exact size of the marshalled message -
writeTo
Description copied from interface:StreamableWrite the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeToin interfaceStreamable- Throws:
IOException
-
writeToNoAddrs
Description copied from interface:MessageWrites the message to an output stream excluding the destination (and possibly source) address- Specified by:
writeToNoAddrsin interfaceMessage- Throws:
IOException
-
readFrom
Description copied from interface:StreamableRead the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFromin interfaceStreamable- Throws:
IOExceptionClassNotFoundException
-
putHeader
-
copyPayload
Copies the payload -
createHeaders
-