Package org.jgroups.util
Class MessageBatch
- java.lang.Object
-
- org.jgroups.util.MessageBatch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessageBatch.Mode
-
Field Summary
Fields Modifier and Type Field Description protected AsciiStringcluster_nameThe name of the cluster in which the message batch is sent, this is equivalent to TpHeader.cluster_nameprotected AddressdestThe destination address.protected FastArray<Message>messagesThe storage of the messages; removed messages have a null elementprotected MessageBatch.ModemodeWhether this message batch contains only OOB messages, or only regular messagesprotected booleanmulticastWhether all messages have dest == null (multicast) or notprotected AddresssenderThe sender of the message batchprotected longtimestampFor benchmarking; may get removed without notice
-
Constructor Summary
Constructors Constructor Description MessageBatch()MessageBatch(int capacity)MessageBatch(java.util.Collection<Message> msgs)MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, java.util.Collection<Message> msgs)MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, MessageBatch.Mode mode, int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageBatchadd(java.util.Collection<Message> msgs)MessageBatchadd(Message msg)MessageBatchadd(Message[] msgs, int num_msgs)Adds message to this batch from a message arrayMessageBatchadd(Message msg, boolean resize)Adds a message to the tableMessageBatchadd(Message msg, boolean resize, boolean determine_mode)Adds a message to the tableMessageBatchadd(MessageBatch batch)MessageBatchadd(MessageBatch batch, boolean resize)Adds another batch to this onebooleananyMatch(java.util.function.Predicate<Message> pred)FastArray<Message>array()Returns the underlying message array.intcapacity()MessageBatchclear()MessageBatchcluster(AsciiString name)AsciiStringclusterName()MessageBatchclusterName(AsciiString name)Addressdest()MessageBatchdest(Address dest)MessageBatchdetermineMode()<T extends Message>
Tfirst()AsciiStringgetClusterName()AddressgetDest()MessageBatch.ModegetMode()AddressgetSender()MessageBatchincr(int i)MessageBatchincrement(int i)booleanisEmpty()booleanisMulticast()java.util.Iterator<Message>iterator()Iterator which iterates only over non-null messages, skipping null messagesjava.util.Iterator<Message>iterator(java.util.function.Predicate<Message> filter)Iterates 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)MessageBatchmcast(boolean flag)MessageBatch.Modemode()MessageBatchmode(MessageBatch.Mode m)booleanmulticast()MessageBatchmulticast(boolean flag)java.lang.StringprintHeaders()MessageBatchremoveIf(java.util.function.Predicate<Message> filter, boolean match_all)MessageBatchreset()MessageBatchresize(int new_capacity)Addresssender()MessageBatchsender(Address sender)MessageBatchset(Address dest, Address sender, Message[] msgs)MessageBatchsetClusterName(AsciiString name)MessageBatchsetDest(Address dest)MessageBatchsetMode(MessageBatch.Mode m)MessageBatchsetSender(Address sender)intsize()Returns the number of non-null messagesjava.util.stream.Stream<Message>stream()java.util.stream.Stream<Message>stream(java.util.function.Predicate<Message> p)java.util.stream.Stream<Message>stream(java.util.function.Predicate<Message> p, boolean parallel)longtimestamp()MessageBatchtimestamp(long ts)java.lang.StringtoString()longtotalSize()Returns the size of the message batch (by callingMessage.size()on all messages)inttransferFrom(MessageBatch other, boolean clear)Transfers messages from other to this batch.
-
-
-
Field Detail
-
dest
protected Address dest
The destination address. Null if this is a multicast message batch, non-null if the batch is sent to a specific member
-
sender
protected Address sender
The sender of the message batch
-
cluster_name
protected AsciiString cluster_name
The name of the cluster in which the message batch is sent, this is equivalent to TpHeader.cluster_name
-
messages
protected FastArray<Message> messages
The storage of the messages; removed messages have a null element
-
multicast
protected boolean multicast
Whether all messages have dest == null (multicast) or not
-
mode
protected MessageBatch.Mode mode
Whether this message batch contains only OOB messages, or only regular messages
-
timestamp
protected long timestamp
For benchmarking; may get removed without notice
-
-
Constructor Detail
-
MessageBatch
public MessageBatch()
-
MessageBatch
public MessageBatch(int capacity)
-
MessageBatch
public MessageBatch(java.util.Collection<Message> msgs)
-
MessageBatch
public MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, java.util.Collection<Message> msgs)
-
MessageBatch
public MessageBatch(Address dest, Address sender, AsciiString cluster_name, boolean multicast, MessageBatch.Mode mode, int capacity)
-
-
Method Detail
-
getDest
public Address getDest()
-
dest
public Address dest()
-
setDest
public MessageBatch setDest(Address dest)
-
dest
public MessageBatch dest(Address dest)
-
getSender
public Address getSender()
-
sender
public Address sender()
-
setSender
public MessageBatch setSender(Address sender)
-
sender
public MessageBatch sender(Address sender)
-
getClusterName
public AsciiString getClusterName()
-
clusterName
public AsciiString clusterName()
-
setClusterName
public MessageBatch setClusterName(AsciiString name)
-
clusterName
public MessageBatch clusterName(AsciiString name)
-
cluster
public MessageBatch cluster(AsciiString name)
-
isMulticast
public boolean isMulticast()
-
multicast
public boolean multicast()
-
multicast
public MessageBatch multicast(boolean flag)
-
mcast
public MessageBatch mcast(boolean flag)
-
getMode
public MessageBatch.Mode getMode()
-
mode
public MessageBatch.Mode mode()
-
setMode
public MessageBatch setMode(MessageBatch.Mode m)
-
mode
public MessageBatch mode(MessageBatch.Mode m)
-
capacity
public int capacity()
-
timestamp
public long timestamp()
-
timestamp
public MessageBatch timestamp(long ts)
-
increment
public MessageBatch increment(int i)
-
incr
public MessageBatch incr(int i)
-
array
public FastArray<Message> array()
Returns the underlying message array. This is only intended for testing !
-
first
public <T extends Message> T first()
-
last
public <T extends Message> T last()
-
add
public MessageBatch add(Message msg)
-
add
public MessageBatch add(Message msg, boolean resize)
Adds a message to the table- Parameters:
msg- the messageresize- whether or not to resize the table- Returns:
- always true if resize==true, else true if the message was added or false if not
-
add
public MessageBatch add(Message msg, boolean resize, boolean determine_mode)
Adds a message to the table- Parameters:
msg- the messageresize- whether or not to resize the table- Returns:
- always true if resize==true, else true if the message was added or false if not
-
add
public MessageBatch add(MessageBatch batch)
-
add
public MessageBatch add(MessageBatch batch, boolean resize)
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
public MessageBatch add(Message[] msgs, int num_msgs)
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
-
add
public MessageBatch add(java.util.Collection<Message> msgs)
-
set
public MessageBatch set(Address dest, Address sender, Message[] msgs)
-
removeIf
public MessageBatch removeIf(java.util.function.Predicate<Message> filter, boolean match_all)
-
transferFrom
public int transferFrom(MessageBatch other, boolean clear)
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
public MessageBatch clear()
-
reset
public MessageBatch reset()
-
anyMatch
public boolean anyMatch(java.util.function.Predicate<Message> pred)
-
determineMode
public MessageBatch determineMode()
-
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
public MessageBatch resize(int new_capacity)
-
iterator
public java.util.Iterator<Message> iterator()
Iterator which iterates only over non-null messages, skipping null messages- Specified by:
iteratorin interfacejava.lang.Iterable<Message>
-
iterator
public java.util.Iterator<Message> iterator(java.util.function.Predicate<Message> filter)
Iterates over all non-null message which match filter
-
stream
public java.util.stream.Stream<Message> stream()
-
stream
public java.util.stream.Stream<Message> stream(java.util.function.Predicate<Message> p, boolean parallel)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
printHeaders
public java.lang.String printHeaders()
-
-