Class FixedPriorityBlockingQueue<T>
- java.lang.Object
-
- org.apache.iotdb.db.utils.datastructure.FixedPriorityBlockingQueue<T>
-
public class FixedPriorityBlockingQueue<T> extends java.lang.ObjectThis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFixedPriorityBlockingQueue.PollLastHook<T>
-
Constructor Summary
Constructors Constructor Description FixedPriorityBlockingQueue(int maxSize, java.util.Comparator<T> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontains(T element)java.util.Comparator<T>getComparator()intgetMaxSize()booleanisEmpty()voidput(T element)voidregsitPollLastHook(FixedPriorityBlockingQueue.PollLastHook<T> hook)Add a hook for this queue.intsize()Ttake()Return the element with min priority.TtakeMax()Return the element with max priority.java.lang.StringtoString()
-
-
-
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:
toStringin classjava.lang.Object
-
-