Class SizeBoundedQueue<T>

java.lang.Object
org.jgroups.util.SizeBoundedQueue<T>

public class SizeBoundedQueue<T> extends Object
Blocking FIFO queue bounded by the max number of bytes of all elements. When adding threads are blocked due to capacity constraints, and the application terminates, it is the caller's duty to interrupt all threads.
Since:
4.0.4
  • Field Details

    • lock

      protected final Lock lock
    • not_full

      protected final Condition not_full
    • not_empty

      protected final Condition not_empty
    • max_size

      protected final int max_size
    • queue

      protected final Queue<SizeBoundedQueue.El<T>> queue
    • count

      protected int count
    • waiters

      protected int waiters
    • done

      protected boolean done
  • Constructor Details

    • SizeBoundedQueue

      public SizeBoundedQueue(int max_size)
    • SizeBoundedQueue

      public SizeBoundedQueue(int max_size, Lock lock)
  • Method Details

    • add

      public void add(T element, int size) throws InterruptedException
      Throws:
      InterruptedException
    • remove

      public T remove()
      Removes and returns the first element or null if the queue is empty
    • drainTo

      public int drainTo(Collection<T> c, int max_bytes)
      Removes and adds to collection c as many elements as possible (including waiters) but not exceeding max_bytes. E.g. if we have elements {1000b, 2000b, 4000b} and max_bytes=6000, then only the first 2 elements are removed and the new size is 4000
      Parameters:
      c - The collection to transfer the removed elements to
      max_bytes - The max number of bytes to remove
      Returns:
      The accumulated number of bytes of all removed elements
    • clear

      public void clear(boolean done)
    • getElements

      public int getElements()
      Returns the number of elements in the queue
    • size

      public int size()
      Returns the accumulated size of all elements in the queue
    • isEmpty

      public boolean isEmpty()
    • getWaiters

      public int getWaiters()
    • hasWaiters

      public boolean hasWaiters()
    • isDone

      public boolean isDone()
    • queueSize

      public int queueSize()
      For testing only - should always be the same as size()
    • toString

      public String toString()
      Overrides:
      toString in class Object