Class BatchMessage
java.lang.Object
org.jgroups.BaseMessage
org.jgroups.BatchMessage
- All Implemented Interfaces:
Iterable<Message>, Constructable<Message>, Message, SizeStreamable, Streamable
A message that contains a batch of messages. This message will wrap several messages, so lower protocol layers only
have to process them once. This increases throughput for cases such as when average message size is small,
or there is a heavy processing cost (e.g.
Similar to
This class is unsynchronized; the envisaged use case is that a BatchMessage is created with a number of messages, or messages are added, but then the instance is not modified anymore and sent.
SEQUENCER).
Similar to
CompositeMessage but with some optimizations made for the specific use case.
This class is unsynchronized; the envisaged use case is that a BatchMessage is created with a number of messages, or messages are added, but then the instance is not modified anymore and sent.
- Since:
- 5.x
- Author:
- Bela Ban, Chris Johnson
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Message
Message.Flag, Message.TransientFlag -
Field Summary
FieldsFields inherited from class BaseMessage
dest, flags, headers, sender, transient_flagsFields inherited from interface Message
BYTES_MSG, COMPOSITE_MSG, EARLYBATCH_MSG, EMPTY_MSG, FRAG_MSG, LONG_MSG, NIO_MSG, OBJ_MSG -
Constructor Summary
ConstructorsConstructorDescriptionBatchMessage(Address dest, int capacity) BatchMessage(Address dest, Address src, Message[] msgs, int index) -
Method Summary
Modifier and TypeMethodDescriptionAdds the message at the end of the array.copy(boolean copy_payload, boolean copy_headers) Create a shallow copy of thisBatchMessage.create()Creates an instance of the class implementing this interfaceprotected voidensureCapacity(int size) protected MessageensureSameDest(Message msg) <T extends Message>
Tget(int index) byte[]getArray()Returns a reference to the payload (byte array).intReturns the length of the byte[] array payload.Message[]int<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.iterator()protected intvoidreadPayload(DataInput in) setArray(byte[] b, int o, int l) Sets 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 typeBytesMessage.Sets 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 typeBytesMessage.Sets an object in a message.toString()voidwritePayload(DataOutput out) Methods inherited from class BaseMessage
clearFlag, clearFlag, clearHeaders, copyPayload, 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, size, sizeNoAddrs, writeTo, writeToNoAddrsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
msgs
-
index
protected int index -
orig_src
-
-
Constructor Details
-
BatchMessage
public BatchMessage() -
BatchMessage
-
BatchMessage
-
-
Method Details
-
create
Description copied from interface:ConstructableCreates an instance of the class implementing this interface- Specified by:
createin interfaceConstructable<Message>- Returns:
- Supplier
-
getType
-
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.- Specified by:
hasPayloadin interfaceMessage- Returns:
- True if the message has a payload
-
hasArray
-
getNumberOfMessages
public int getNumberOfMessages() -
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 typeBytesMessage. -
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 typeBytesMessage. 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 typeBytesMessage. 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 typeBytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload. -
setObject
Description copied from interface:MessageSets 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 -
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 inObjectMessage), the object will be returned directly. -
getMessages
-
getOrigSender
-
setOrigSender
-
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 -
add
Adds the message at the end of the array. Increases the array if needed -
add
-
get
-
copy
Create a shallow copy of thisBatchMessage.- Specified by:
copyin interfaceMessage- Overrides:
copyin classBaseMessage- Parameters:
copy_payload- If true, the payload is copied, else it is null in the copied messagecopy_headers- If true, the headers are copied
-
toString
- Overrides:
toStringin classBaseMessage
-
payloadSize
protected int payloadSize()- Specified by:
payloadSizein classBaseMessage
-
iterator
-
writePayload
- Specified by:
writePayloadin interfaceMessage- Throws:
IOException
-
readPayload
- Specified by:
readPayloadin interfaceMessage- Throws:
IOExceptionClassNotFoundException
-
ensureCapacity
protected void ensureCapacity(int size) -
ensureSameDest
-