Package org.jgroups.util
Class MessageBatch
java.lang.Object
org.jgroups.util.MessageBatch
Represents a message batch; multiple messages from the same sender to the same receiver(s). This class is unsynchronized.
- Since:
- 3.3
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AsciiStringThe name of the cluster in which the message batch is sent, this is equivalent to TpHeader.cluster_nameprotected AddressThe destination address.The storage of the messages; removed messages have a null elementprotected MessageBatch.ModeWhether this message batch contains only OOB messages, or only regular messagesprotected booleanWhether all messages have dest == null (multicast) or notprotected AddressThe sender of the message batchprotected longFor benchmarking; may get removed without notice -
Constructor Summary
ConstructorsConstructorDescriptionMessageBatch(int capacity) MessageBatch(Collection<Message> msgs) MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, Collection<Message> msgs) MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, MessageBatch.Mode mode, int capacity) -
Method Summary
Modifier and TypeMethodDescriptionintadd(Collection<Message> msgs) intAdds message to this batch from a message arrayintAdds a message to the tableintadd(MessageBatch batch) intadd(MessageBatch batch, boolean resize) Adds another batch to this onebooleanarray()Returns the underlying message array.intcapacity()clear()clusterName(AsciiString name) dest()protected MessageBatch<T extends Message>
Tfirst()getDest()getMode()booleanisEmpty()booleaniterator()Iterator which iterates only over non-null messages, skipping null messagesIterates over all non-null message which match filter<T extends Message>
Tlast()intlength()Returns the total number of bytes of the message batch (by callingMessage.getLength()on all messages)mcast(boolean flag) mode()booleanmulticast(boolean flag) reset()resize(int new_capacity) sender()setClusterName(AsciiString name) intsize()Returns the number of non-null messagesstream()longtimestamp(long ts) toString()longReturns the size of the message batch (by callingMessage.size()on all messages)inttransferFrom(MessageBatch other, boolean clear) Transfers messages from other to this batch.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
dest
The destination address. Null if this is a multicast message batch, non-null if the batch is sent to a specific member -
sender
The sender of the message batch -
cluster_name
The name of the cluster in which the message batch is sent, this is equivalent to TpHeader.cluster_name -
messages
The storage of the messages; removed messages have a null element -
multicast
protected boolean multicastWhether all messages have dest == null (multicast) or not -
mode
Whether this message batch contains only OOB messages, or only regular messages -
timestamp
protected long timestampFor benchmarking; may get removed without notice
-
-
Constructor Details
-
MessageBatch
public MessageBatch() -
MessageBatch
public MessageBatch(int capacity) -
MessageBatch
-
MessageBatch
public MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, Collection<Message> msgs) -
MessageBatch
public MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, MessageBatch.Mode mode, int capacity)
-
-
Method Details
-
getDest
-
dest
-
setDest
-
dest
-
getSender
-
sender
-
setSender
-
sender
-
getClusterName
-
clusterName
-
setClusterName
-
clusterName
-
isMulticast
public boolean isMulticast() -
multicast
public boolean multicast() -
multicast
-
mcast
-
getMode
-
mode
-
setMode
-
mode
-
capacity
public int capacity() -
timestamp
public long timestamp() -
timestamp
-
array
Returns the underlying message array. This is only intended for testing ! -
first
-
last
-
add
-
add
Adds a message to the table- Parameters:
msg- the messageresize- whether or not to resize the table. If true, the method will always return 1- Returns:
- always 1 if resize==true, else 1 if the message was added or 0 if not
-
add
-
add
Adds another batch to this one- Parameters:
batch- the batch to add to this batchresize- when true, this batch will be resized to accommodate the other batch- Returns:
- the number of messages from the other batch that were added successfully. Will always be batch.size() unless resize is false: in this case, the number of messages that were added successfully is returned
-
add
Adds message to this batch from a message array- Parameters:
msgs- the message arraynum_msgs- the number of messages to add, should be <= msgs.length- Returns:
- the number of messages added to this batch
-
add
-
set
-
removeIf
-
transferFrom
Transfers messages from other to this batch. Optionally clears the other batch after the transfer- Parameters:
other- the other batchclear- If true, the transferred messages are removed from the other batch- Returns:
- the number of transferred messages (may be 0 if the other batch was empty)
-
clear
-
reset
-
anyMatch
-
size
public int size()Returns the number of non-null messages -
isEmpty
public boolean isEmpty() -
totalSize
public long totalSize()Returns the size of the message batch (by callingMessage.size()on all messages) -
length
public int length()Returns the total number of bytes of the message batch (by callingMessage.getLength()on all messages) -
resize
-
iterator
Iterator which iterates only over non-null messages, skipping null messages -
iterator
Iterates over all non-null message which match filter -
stream
-
stream
-
stream
-
toString
-
printHeaders
-
determineMode
-