Package org.jgroups.util
Class MessageBatch
- java.lang.Object
-
- org.jgroups.util.MessageBatch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classMessageBatch.BatchIteratorIterates over non-null elements of a batch, skipping null elementsstatic 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 static intINCRprotected intindexIndex of the next message to be insertedprotected static java.util.function.ToIntBiFunction<Message,MessageBatch>length_visitorprotected 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 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 MessageBatchadd(Message msg)intadd(Message msg, boolean resize)Adds a message to the tableMessageBatchadd(MessageBatch batch)intadd(MessageBatch batch, boolean resize)Adds another batch to this oneMessage[]array()Returns the underlying message array.intcapacity()MessageBatchclear()AsciiStringclusterName()MessageBatchclusterName(AsciiString name)Addressdest()MessageBatchdest(Address dest)MessageBatch.ModedetermineMode()Messagefirst()voidforEach(java.util.function.BiConsumer<Message,MessageBatch> consumer)intgetCapacity()AsciiStringgetClusterName()AddressgetDest()java.util.Collection<Message>getMatchingMessages(short id, boolean remove)Removes and returns all messages which have a header with ID == idMessageBatch.ModegetMode()AddressgetSender()intindex()booleanisEmpty()booleanisMulticast()MessageIteratoriterator()Iterator which iterates only over non-null messages, skipping null messagesMessagelast()intlength()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.Modemode()MessageBatchmode(MessageBatch.Mode mode)booleanmulticast()MessageBatchmulticast(boolean flag)java.lang.StringprintHeaders()MessageBatchremove(java.util.function.Predicate<Message> filter)Removes all messages which match filterMessageBatchremove(Message msg)Removes the current message (found by indentity (==)) by nulling it in the message arrayMessageBatchreplace(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)Replaces all messages which match a given filter with a replacement messageMessageBatchreplace(Message existing_msg, Message new_msg)Replaces a message in the batch with another oneintreplaceIf(java.util.function.Predicate<Message> filter, Message replacement, boolean match_all)Replaces all messages that match a given filter with a replacement messageMessageBatchreset()protected voidresize()protected voidresize(int new_capacity)Addresssender()MessageBatchsender(Address sender)MessageBatchsetClusterName(AsciiString name)MessageBatchsetDest(Address dest)MessageBatchsetMode(MessageBatch.Mode mode)MessageBatchsetSender(Address sender)intsize()Returns the number of non-null messagesjava.util.stream.Stream<Message>stream()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 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:
iteratorin interfacejava.lang.Iterable<Message>
-
stream
public java.util.stream.Stream<Message> stream()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
printHeaders
public java.lang.String printHeaders()
-
resize
protected void resize()
-
resize
protected void resize(int new_capacity)
-
-