Class MessageBatch

java.lang.Object
org.jgroups.util.MessageBatch
All Implemented Interfaces:
Iterable<Message>

public class MessageBatch extends Object implements Iterable<Message>
Represents a message batch; multiple messages from the same sender to the same receiver(s). This class is unsynchronized.
Since:
3.3
  • Field Details

    • 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 Details

  • Method Details

    • 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)
    • mcast

      public MessageBatch mcast(boolean flag)
    • getMode

      public MessageBatch.Mode getMode()
    • mode

      public MessageBatch.Mode mode()
    • setMode

      public MessageBatch setMode(MessageBatch.Mode m)
    • 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 message
      resize - 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 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 int 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
      Returns:
      the number of messages added to this batch
    • add

      public int add(Collection<Message> msgs)
    • set

      public MessageBatch set(Address dest, Address sender, Message[] msgs)
    • removeIf

      public MessageBatch removeIf(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)
    • clear

      public MessageBatch clear()
    • reset

      public MessageBatch reset()
    • anyMatch

      public boolean anyMatch(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)
    • resize

      public MessageBatch resize(int new_capacity)
    • iterator

      public Iterator<Message> iterator()
      Iterator which iterates only over non-null messages, skipping null messages
      Specified by:
      iterator in interface Iterable<Message>
    • iterator

      public Iterator<Message> iterator(Predicate<Message> filter)
      Iterates over all non-null message which match filter
    • stream

      public Stream<Message> stream()
    • stream

      public Stream<Message> stream(Predicate<Message> p)
    • stream

      public Stream<Message> stream(Predicate<Message> p, boolean parallel)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • printHeaders

      public String printHeaders()
    • determineMode

      protected MessageBatch determineMode()