Class FixedPriorityBlockingQueue<T>


  • public class FixedPriorityBlockingQueue<T>
    extends java.lang.Object
    This is a priority blocking queue with a maximum size. If the queue's size is larger than the max size, the element with max priority will be kick out.
    • Constructor Detail

      • FixedPriorityBlockingQueue

        public FixedPriorityBlockingQueue​(int maxSize,
                                          java.util.Comparator<T> comparator)
    • Method Detail

      • put

        public void put​(T element)
                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • take

        public T take()
               throws java.lang.InterruptedException
        Return the element with min priority. If the queue is empty, the thread will be blocked util there are some elements inserted into the queue.
        Returns:
        Throws:
        java.lang.InterruptedException
      • takeMax

        public T takeMax()
                  throws java.lang.InterruptedException
        Return the element with max priority. If the queue is empty, the thread will be blocked util there are some elements inserted into the queue.
        Returns:
        Throws:
        java.lang.InterruptedException
      • regsitPollLastHook

        public void regsitPollLastHook​(FixedPriorityBlockingQueue.PollLastHook<T> hook)
        Add a hook for this queue. If an element is kicked out because the queue's size exceed the largest value, the hook will apply to this element. Notice, multiple hooks can be added to a queue, and all of them will be applied to the element kicked out. The order in which they are applied depends on the order in which they were registered.
        Parameters:
        hook -
      • contains

        public boolean contains​(T element)
      • size

        public int size()
      • clear

        public void clear()
      • isEmpty

        public boolean isEmpty()
      • getComparator

        public java.util.Comparator<T> getComparator()
      • getMaxSize

        public int getMaxSize()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object