Class PriorityTaskQueue<T>
java.lang.Object
fr.gouv.vitam.processing.distributor.core.PriorityTaskQueue<T>
- Type Parameters:
T
- the type of entries held in this queue
A task queue backed by a "regular priority" bounded blocking queue, and a "high-priority" non-blocking queue.
Adding regular entries may be blocking is max capacity reached.
Adding high-priority entries is non-blocking.
Retrieving entries from queue may be blocking if queue is empty (no high-priority or regular entry present).
High-priority entries have precedence over regular entries.
This class is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionPriorityTaskQueue
(int maxRegularQueueSize) Constructor of thePriorityTaskQueue<T>
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addHighPriorityEntry
(T entry) Adds a high-priority entry to the queue.void
addRegularEntry
(T entry) Adds a regular entry to the queue.int
size()
take()
Removes and returns next entry from the queue.
-
Constructor Details
-
PriorityTaskQueue
public PriorityTaskQueue(int maxRegularQueueSize) Constructor of thePriorityTaskQueue<T>
- Parameters:
maxRegularQueueSize
- the max size of regular queue.- Throws:
IllegalArgumentException
- if queue size in invalid.
-
-
Method Details
-
addRegularEntry
Adds a regular entry to the queue. Attempts to add entries on full regular queue causes caller thread to be blocked until enough space is available.- Parameters:
entry
- the entry to add to regular queue- Throws:
IllegalArgumentException
- if entry is nullInterruptedException
- if caller thread is interrupted
-
addHighPriorityEntry
Adds a high-priority entry to the queue.- Parameters:
entry
- the entry to add to high-priority queue
-
take
Removes and returns next entry from the queue. High-priority entries have precedence over regular entries. Attempts to remove entries from empty queue causes caller thread to be blocked until new entries are added to queue.- Returns:
- the next entry removed from queue
- Throws:
InterruptedException
- if caller thread is interrupted
-
size
public int size()
-