Class ObjectMessage
- All Implemented Interfaces:
Constructable<Message>,Message,SizeStreamable,Streamable
Message with an object as payload. The object won't get serialized until sent by the transport.
Note that the object passed to the constructor (or set with setObject(Object)) must not be changed after
the creation of an ObjectMessage.
- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgroups.Message
Message.Flag, Message.TransientFlag -
Field Summary
FieldsFields inherited from class org.jgroups.BaseMessage
dest, DEST_SET, flags, headers, sender, SRC_SET, transient_flagsFields inherited from interface org.jgroups.Message
BYTES_MSG, COMPOSITE_MSG, EARLYBATCH_MSG, EMPTY_MSG, FRAG_MSG, LONG_MSG, NIO_MSG, OBJ_MSG -
Constructor Summary
ConstructorsConstructorDescriptionObjectMessage(Address dest) Constructs a message given a destination addressObjectMessage(Address dest, Object obj) Constructs a message given a destination address and the payload objectObjectMessage(Address dest, SizeStreamable obj) Constructs a message given a destination address and the payload object -
Method Summary
Modifier and TypeMethodDescriptionprotected MessagecopyPayload(Message copy) Copies the payloadcreate()Creates an instance of the class implementing this interfacebyte[]getArray()Returns a reference to the payload (byte array).intReturns the length of the byte[] array payload.<T> TGets an object from the payload.intReturns the offset of the byte[] array at which user data starts.shortgetType()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.booleanprotected intobjSize()voidreadPayload(DataInput in) setArray(byte[] b, int off, int len) Sets the byte array in a message.Sets the byte array in a message.Sets the object.setObject(SizeStreamable obj) Sets the payload to aSizeStreamable(or null).setWrapped(boolean b) intsize()Returns the exact size of the marshalled messagetoString()voidwritePayload(DataOutput out) Methods inherited from class org.jgroups.BaseMessage
clearFlag, clearFlag, clearHeaders, copy, createHeaders, getDest, getFlags, getHeader, getHeaders, getNumHeaders, getPayload, getSrc, headers, headers, isFlagSet, isFlagSet, printHeaders, putHeader, putHeader, putHeaderIfAbsent, readFrom, serializedSize, setDest, setFlag, setFlag, setFlag, setFlagIfAbsent, setPayload, setSrc, writeTo, writeToNoAddrs
-
Field Details
-
obj
-
-
Constructor Details
-
ObjectMessage
public ObjectMessage() -
ObjectMessage
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.
-
ObjectMessage
Constructs a message given a destination address and the payload object- 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.obj- To be used as payload.
-
ObjectMessage
Constructs a message given a destination address and the payload object- 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.obj- TheSizeStreamableobject to be used as payload. Note that this constructor has fewer checks (e.g. instanceof) thanObjectMessage(org.jgroups.Address,java.lang.Object).
-
-
Method Details
-
create
Description copied from interface:ConstructableCreates an instance of the class implementing this interface -
getType
public short getType()Description copied from interface:MessageReturns the type of the message, e.g. BYTES_MSG, OBJ_MSG etc -
hasPayload
public boolean hasPayload()Description copied from interface:MessageReturns true if the message has a payload, e.g. a byte[] array in aBytesMessageor an object in anObjectMessage. This is more generic thanMessage.hasArray(), as it is not just applicable to a byte array.- Returns:
- True if the message has a payload
-
hasArray
public boolean hasArray()Description copied from interface:MessageReturns true if this message has a byte[] array as payload (even if it's null!), false otherwise -
getOffset
public int getOffset()Description copied from interface:MessageReturns the offset of the byte[] array at which user data starts. Throws an exception if the message does not have a byte[] array payload (ifMessage.hasArray()is false).Note that this is a convenience method, as most messages are of type
BytesMessage. -
getLength
public int getLength()Description copied from interface:MessageReturns the length of the byte[] array payload. If the message does not have a byte[] array payload (Message.hasArray()is false), then the serialized size may be returned, or an implementation may choose to throw an exception -
getArray
public byte[] getArray()Description copied from interface:MessageReturns 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 (
Message.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
Description copied from interface:MessageSets the byte array in a message.Throws an exception if the message does not have a byte[] array payload (
Message.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
Description copied from interface:MessageSets the byte array in a message.Throws an exception if the message does not have a byte[] array payload (
Message.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. -
isWrapped
public boolean isWrapped() -
setWrapped
-
setObject
Sets the object. If the object doesn't implementSizeStreamable, or is a primitive type, it will be wrapped into anObjectWrapperSerializable(which does implement SizeStreamable) -
setObject
Sets the payload to aSizeStreamable(or null). This method has fewer checks (e.g. instanceof) thansetObject(Object).- Parameters:
obj- TheSizeStreamableto be used as payload (or null)
-
setSizeStreamable
-
getObject
public <T> T getObject()Description copied from interface:MessageGets 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. -
size
public int size()Description copied from interface:MessageReturns the exact size of the marshalled message- Specified by:
sizein interfaceMessage- Overrides:
sizein classBaseMessage- Returns:
- The number of bytes for the marshalled message
-
writePayload
- Throws:
IOException
-
readPayload
- Throws:
IOExceptionClassNotFoundException
-
copyPayload
Description copied from class:BaseMessageCopies the payload- Overrides:
copyPayloadin classBaseMessage
-
toString
- Overrides:
toStringin classBaseMessage
-
objSize
protected int objSize()
-