Package org.jgroups.util
Class MessageBatch
- java.lang.Object
-
- org.jgroups.util.MessageBatch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
MessageBatch.BatchIterator
Iterates over non-null elements of a batch, skipping null elementsstatic 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 static int
INCR
protected int
index
Index of the next message to be insertedprotected static java.util.function.ToIntBiFunction<Message,MessageBatch>
length_visitor
protected 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 static java.util.function.ToLongBiFunction<Message,MessageBatch>
total_size_visitor
-
Constructor Summary
Constructors Constructor Description 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, java.util.Collection<Message> msgs, java.util.function.Predicate<Message> filter)
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 MessageBatch
add(Message msg)
int
add(Message msg, boolean resize)
Adds a message to the tableMessageBatch
add(MessageBatch batch)
int
add(MessageBatch batch, boolean resize)
Adds another batch to this oneMessage[]
array()
Returns the underlying message array.int
capacity()
MessageBatch
clear()
AsciiString
clusterName()
MessageBatch
clusterName(AsciiString name)
Address
dest()
MessageBatch
dest(Address dest)
MessageBatch.Mode
determineMode()
Message
first()
void
forEach(java.util.function.BiConsumer<Message,MessageBatch> consumer)
int
getCapacity()
AsciiString
getClusterName()
Address
getDest()
java.util.Collection<Message>
getMatchingMessages(short id, boolean remove)
Removes and returns all messages which have a header with ID == idMessageBatch.Mode
getMode()
Address
getSender()
int
index()
boolean
isEmpty()
boolean
isMulticast()
MessageIterator
iterator()
Iterator which iterates only over non-null messages, skipping null messagesMessage
last()
int
length()
Returns the total number of bytes of the message batch (by callingMessage.getLength()
on all messages)<T> java.util.Collection<T>
map(java.util.function.BiFunction<Message,MessageBatch,T> visitor)
Applies a function to all messages and returns a list of the function resultsMessageBatch.Mode
mode()
MessageBatch
mode(MessageBatch.Mode mode)
boolean
multicast()
MessageBatch
multicast(boolean flag)
java.lang.String
printHeaders()
MessageBatch
remove(java.util.function.Predicate<Message> filter)
Removes all messages which match filterMessageBatch
remove(Message msg)
Removes the current message (found by indentity (==)) by nulling it in the message arrayMessageBatch
replace(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)
Replaces all messages which match a given filter with a replacement messageMessageBatch
replace(Message existing_msg, Message new_msg)
Replaces a message in the batch with another oneint
replaceIf(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)
Replaces all messages that match a given filter with a replacement messageMessageBatch
reset()
protected void
resize()
protected void
resize(int new_capacity)
Address
sender()
MessageBatch
sender(Address sender)
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.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 Message[] messages
The storage of the messages; removed messages have a null element
-
index
protected int index
Index of the next message to be inserted
-
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
-
INCR
protected static final int INCR
- See Also:
- Constant Field Values
-
length_visitor
protected static final java.util.function.ToIntBiFunction<Message,MessageBatch> length_visitor
-
total_size_visitor
protected static final java.util.function.ToLongBiFunction<Message,MessageBatch> total_size_visitor
-
-
Constructor Detail
-
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, java.util.Collection<Message> msgs, java.util.function.Predicate<Message> filter)
-
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)
-
isMulticast
public boolean isMulticast()
-
multicast
public boolean multicast()
-
multicast
public MessageBatch multicast(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)
-
getCapacity
public int getCapacity()
-
capacity
public int capacity()
-
index
public int index()
-
array
public Message[] array()
Returns the underlying message array. This is only intended for testing !
-
first
public Message first()
-
last
public Message 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 MessageBatch 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==0: in this case, the number of messages that were added successfully is returned
-
replace
public MessageBatch replace(Message existing_msg, Message new_msg)
Replaces a message in the batch with another one- Parameters:
existing_msg
- The message to be replaced. The message has to be non-null and is found by identity (==) comparisonnew_msg
- The message to replace the existing message with, can be null- Returns:
-
replace
public MessageBatch replace(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)
Replaces all messages which match a given filter with a replacement message- Parameters:
filter
- the filter. If null, no changes take place. Note that filter needs to be able to handle null msgsreplacement
- the replacement message. Can be null, which essentially removes all messages matching filtermatch_all
- whether to replace the first or all matches- Returns:
- the MessageBatch
-
replaceIf
public int replaceIf(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)
Replaces all messages that match a given filter with a replacement message- Parameters:
filter
- the filter. If null, no changes take place. Note that filter needs to be able to handle null msgsreplacement
- the replacement message. Can be null, which essentially removes all messages matching filtermatch_all
- whether to replace the first or all matches- Returns:
- the number of matched messages
-
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)
-
remove
public MessageBatch remove(Message msg)
Removes the current message (found by indentity (==)) by nulling it in the message array- Parameters:
msg
-- Returns:
-
remove
public MessageBatch remove(java.util.function.Predicate<Message> filter)
Removes all messages which match filter- Parameters:
filter
- the filter. If null, no removal takes place- Returns:
- the MessageBatch
-
clear
public MessageBatch clear()
-
reset
public MessageBatch reset()
-
getMatchingMessages
public java.util.Collection<Message> getMatchingMessages(short id, boolean remove)
Removes and returns all messages which have a header with ID == id
-
map
public <T> java.util.Collection<T> map(java.util.function.BiFunction<Message,MessageBatch,T> visitor)
Applies a function to all messages and returns a list of the function results
-
forEach
public void forEach(java.util.function.BiConsumer<Message,MessageBatch> consumer)
-
size
public int size()
Returns the number of non-null messages
-
isEmpty
public boolean isEmpty()
-
determineMode
public MessageBatch.Mode determineMode()
-
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)
-
iterator
public MessageIterator iterator()
Iterator which iterates only over non-null messages, skipping null messages- Specified by:
iterator
in interfacejava.lang.Iterable<Message>
-
stream
public java.util.stream.Stream<Message> stream()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
printHeaders
public java.lang.String printHeaders()
-
resize
protected void resize()
-
resize
protected void resize(int new_capacity)
-
-