Class MessageBatch

  • All Implemented Interfaces:
    java.lang.Iterable<Message>

    public class MessageBatch
    extends java.lang.Object
    implements java.lang.Iterable<Message>
    Represents a message batch; multiple messages from the same sender to the same receiver(s). This class is unsynchronized.
    Since:
    3.3
    Author:
    Bela Ban
    • 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)
    • Method Detail

      • getDest

        public Address getDest()
      • getSender

        public Address getSender()
      • isMulticast

        public boolean isMulticast()
      • multicast

        public boolean multicast()
      • multicast

        public MessageBatch multicast​(boolean flag)
      • capacity

        public int capacity()
      • timestamp

        public long timestamp()
      • 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,
                                boolean resize)
        Adds a message to the table
        Parameters:
        msg - the message
        resize - 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 message
        resize - 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,
                                boolean resize)
        Adds another batch to this one
        Parameters:
        batch - the batch to add to this batch
        resize - 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 array
        num_msgs - the number of messages to add, should be <= msgs.length
      • 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 batch
        clear - 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)
      • 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 calling Message.size() on all messages)
      • length

        public int length()
        Returns the total number of bytes of the message batch (by calling Message.getLength() on all messages)
      • iterator

        public java.util.Iterator<Message> iterator()
        Iterator which iterates only over non-null messages, skipping null messages
        Specified by:
        iterator in interface java.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)
      • 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 class java.lang.Object
      • printHeaders

        public java.lang.String printHeaders()