Package org.jgroups.util
Class MessageBatch
- java.lang.Object
-
- org.jgroups.util.MessageBatch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MessageBatch.Mode
-
Field Summary
Fields Modifier and Type Field Description protected AsciiString
cluster_name
The name of the cluster in which the message batch is sent, this is equivalent to TpHeader.cluster_nameprotected Address
dest
The destination address.protected FastArray<Message>
messages
The storage of the messages; removed messages have a null elementprotected MessageBatch.Mode
mode
Whether this message batch contains only OOB messages, or only regular messagesprotected boolean
multicast
Whether all messages have dest == null (multicast) or notprotected Address
sender
The sender of the message batchprotected long
timestamp
For 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 int
add(java.util.Collection<Message> msgs)
MessageBatch
add(Message msg)
int
add(Message[] msgs, int num_msgs)
Adds message to this batch from a message arrayint
add(Message msg, boolean resize)
Adds a message to the tableint
add(MessageBatch batch)
int
add(MessageBatch batch, boolean resize)
Adds another batch to this oneboolean
anyMatch(java.util.function.Predicate<Message> pred)
FastArray<Message>
array()
Returns the underlying message array.int
capacity()
MessageBatch
clear()
MessageBatch
cluster(AsciiString name)
AsciiString
clusterName()
MessageBatch
clusterName(AsciiString name)
Address
dest()
MessageBatch
dest(Address dest)
protected MessageBatch
determineMode()
protected MessageBatch
determineMode(Message msg)
<T extends Message>
Tfirst()
AsciiString
getClusterName()
Address
getDest()
MessageBatch.Mode
getMode()
Address
getSender()
boolean
isEmpty()
boolean
isMulticast()
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()
int
length()
Returns the total number of bytes of the message batch (by callingMessage.getLength()
on all messages)MessageBatch
mcast(boolean flag)
MessageBatch.Mode
mode()
MessageBatch
mode(MessageBatch.Mode mode)
boolean
multicast()
MessageBatch
multicast(boolean flag)
java.lang.String
printHeaders()
MessageBatch
removeIf(java.util.function.Predicate<Message> filter, boolean match_all)
MessageBatch
reset()
MessageBatch
resize(int new_capacity)
Address
sender()
MessageBatch
sender(Address sender)
MessageBatch
set(Address dest, Address sender, Message[] msgs)
MessageBatch
setClusterName(AsciiString name)
MessageBatch
setDest(Address dest)
MessageBatch
setMode(MessageBatch.Mode mode)
MessageBatch
setSender(Address sender)
int
size()
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)
long
timestamp()
MessageBatch
timestamp(long ts)
java.lang.String
toString()
long
totalSize()
Returns the size of the message batch (by callingMessage.size()
on all messages)int
transferFrom(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 mode)
-
mode
public MessageBatch mode(MessageBatch.Mode mode)
-
capacity
public int capacity()
-
timestamp
public long timestamp()
-
timestamp
public MessageBatch timestamp(long ts)
-
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 int add(Message msg, boolean resize)
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
public int add(MessageBatch batch)
-
add
public int 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 int 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- Returns:
- the number of messages added to this batch
-
add
public int 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)
-
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:
iterator
in 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:
toString
in classjava.lang.Object
-
printHeaders
public java.lang.String printHeaders()
-
determineMode
protected MessageBatch determineMode()
-
determineMode
protected MessageBatch determineMode(Message msg)
-
-