Package io.pravega.common.util
Class PriorityBlockingDrainingQueue<T extends PriorityBlockingDrainingQueue.Item>
- java.lang.Object
-
- io.pravega.common.util.AbstractDrainingQueue<T>
-
- io.pravega.common.util.PriorityBlockingDrainingQueue<T>
-
- Type Parameters:
T- Type of item,
public class PriorityBlockingDrainingQueue<T extends PriorityBlockingDrainingQueue.Item> extends AbstractDrainingQueue<T>
AbstractDrainingQueueimplementation with multiple priority levels. Supports up toByte.MAX_VALUEpriority levels, with Priority 0 being the highest.Important notes: -
AbstractDrainingQueue.poll(int)andAbstractDrainingQueue.take(int)will return items with the highest available priority and will never mix items with different priorities. That means that, even if there are more items (with lower priority), those will not be included in the result even if the requested number of items exceeds what we can return. These (lower priority) items may be retrieved using a subsequent call (assuming no higher priority items are added in the meantime).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePriorityBlockingDrainingQueue.ItemDefines an Item that can be added to aPriorityBlockingDrainingQueue.
-
Constructor Summary
Constructors Constructor Description PriorityBlockingDrainingQueue(byte maxPriorityValue)Creates a new instance of thePriorityBlockingDrainingQueueclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddInternal(T item)Updates the internal data structure to include the given item.protected java.util.Queue<T>fetch(int maxCount)Extracts a number of items from the queue.protected TpeekInternal()Returns the first item in the Queue.protected intsizeInternal()Returns the size of the queue.-
Methods inherited from class io.pravega.common.util.AbstractDrainingQueue
add, cancelPendingTake, close, newTakeResult, peek, poll, size, take, take
-
-
-
-
Constructor Detail
-
PriorityBlockingDrainingQueue
public PriorityBlockingDrainingQueue(byte maxPriorityValue)
Creates a new instance of thePriorityBlockingDrainingQueueclass.- Parameters:
maxPriorityValue- Maximum allowed priority value.
-
-
Method Detail
-
addInternal
protected void addInternal(T item)
Description copied from class:AbstractDrainingQueueUpdates the internal data structure to include the given item. NOTE: this is invoked while holding the lock. There is no need for additional synchronization in the implementation.- Specified by:
addInternalin classAbstractDrainingQueue<T extends PriorityBlockingDrainingQueue.Item>- Parameters:
item- The item to include.
-
sizeInternal
protected int sizeInternal()
Description copied from class:AbstractDrainingQueueReturns the size of the queue. NOTE: this is invoked while holding the lock. There is no need for additional synchronization in the implementation.- Specified by:
sizeInternalin classAbstractDrainingQueue<T extends PriorityBlockingDrainingQueue.Item>- Returns:
- The size of the queue.
-
peekInternal
protected T peekInternal()
Description copied from class:AbstractDrainingQueueReturns the first item in the Queue. NOTE: this is invoked while holding the lock. There is no need for additional synchronization in the implementation.- Specified by:
peekInternalin classAbstractDrainingQueue<T extends PriorityBlockingDrainingQueue.Item>- Returns:
- The first item, or null if
AbstractDrainingQueue.size()is 0.
-
fetch
protected java.util.Queue<T> fetch(int maxCount)
Description copied from class:AbstractDrainingQueueExtracts a number of items from the queue. NOTE: this is invoked while holding the lock. There is no need for additional synchronization in the implementation.- Specified by:
fetchin classAbstractDrainingQueue<T extends PriorityBlockingDrainingQueue.Item>- Parameters:
maxCount- The maximum number of items to extract.- Returns:
- The extracted items, in order.
-
-