Class ThroughputLimitQueue<M>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<M>, java.util.Collection<M>, java.util.concurrent.BlockingQueue<M>, java.util.Queue<M>

    public class ThroughputLimitQueue<M>
    extends java.util.concurrent.LinkedBlockingQueue<M>
    Queue that limits it's size based on the throughput. Allows the queue to keep a certain number of seconds of processing in its queue.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ThroughputLimitQueue​(long queueSizeInMs)
      Creates a new queue.
      ThroughputLimitQueue​(com.yahoo.concurrent.Timer t, long queueSizeInMs)
      Creates a new queue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(M m)  
      boolean addAll​(java.util.Collection<? extends M> ms)  
      int capacity()  
      boolean offer​(M m)  
      boolean offer​(M m, long l, java.util.concurrent.TimeUnit timeUnit)  
      M poll()  
      M poll​(long l, java.util.concurrent.TimeUnit timeUnit)  
      void put​(M m)  
      int remainingCapacity()  
      M take()  
      • Methods inherited from class java.util.concurrent.LinkedBlockingQueue

        clear, contains, drainTo, drainTo, forEach, iterator, peek, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toString
      • Methods inherited from class java.util.AbstractQueue

        element, remove
      • Methods inherited from class java.util.AbstractCollection

        containsAll, isEmpty
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • ThroughputLimitQueue

        public ThroughputLimitQueue​(long queueSizeInMs)
        Creates a new queue.
        Parameters:
        queueSizeInMs - The maximum time we wish to have objects waiting in the queue.
      • ThroughputLimitQueue

        public ThroughputLimitQueue​(com.yahoo.concurrent.Timer t,
                                    long queueSizeInMs)
        Creates a new queue. Used for unit testing.
        Parameters:
        t - Used to measure time spent in the queue. Subclass for unit testing, or use SystemTimer for regular use.
        queueSizeInMs - The maximum time we wish to have objects waiting in the queue.
    • Method Detail

      • add

        public boolean add​(M m)
        Specified by:
        add in interface java.util.concurrent.BlockingQueue<M>
        Specified by:
        add in interface java.util.Collection<M>
        Specified by:
        add in interface java.util.Queue<M>
        Overrides:
        add in class java.util.AbstractQueue<M>
      • offer

        public boolean offer​(M m)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<M>
        Specified by:
        offer in interface java.util.Queue<M>
        Overrides:
        offer in class java.util.concurrent.LinkedBlockingQueue<M>
      • poll

        public M poll()
        Specified by:
        poll in interface java.util.Queue<M>
        Overrides:
        poll in class java.util.concurrent.LinkedBlockingQueue<M>
      • put

        public void put​(M m)
                 throws java.lang.InterruptedException
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<M>
        Overrides:
        put in class java.util.concurrent.LinkedBlockingQueue<M>
        Throws:
        java.lang.InterruptedException
      • offer

        public boolean offer​(M m,
                             long l,
                             java.util.concurrent.TimeUnit timeUnit)
                      throws java.lang.InterruptedException
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<M>
        Overrides:
        offer in class java.util.concurrent.LinkedBlockingQueue<M>
        Throws:
        java.lang.InterruptedException
      • take

        public M take()
               throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<M>
        Overrides:
        take in class java.util.concurrent.LinkedBlockingQueue<M>
        Throws:
        java.lang.InterruptedException
      • poll

        public M poll​(long l,
                      java.util.concurrent.TimeUnit timeUnit)
               throws java.lang.InterruptedException
        Specified by:
        poll in interface java.util.concurrent.BlockingQueue<M>
        Overrides:
        poll in class java.util.concurrent.LinkedBlockingQueue<M>
        Throws:
        java.lang.InterruptedException
      • capacity

        public int capacity()
        Returns:
        Returns the maximum capacity of the queue
      • remainingCapacity

        public int remainingCapacity()
        Specified by:
        remainingCapacity in interface java.util.concurrent.BlockingQueue<M>
        Overrides:
        remainingCapacity in class java.util.concurrent.LinkedBlockingQueue<M>
      • addAll

        public boolean addAll​(java.util.Collection<? extends M> ms)
        Specified by:
        addAll in interface java.util.Collection<M>
        Overrides:
        addAll in class java.util.AbstractQueue<M>