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
@ThreadSafe public class PriorityTaskQueue<T> extends java.lang.Object
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
Constructors Constructor Description PriorityTaskQueue(int maxRegularQueueSize)
Constructor of thePriorityTaskQueue
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHighPriorityEntry(T entry)
Adds a high-priority entry to the queue.void
addRegularEntry(T entry)
Adds a regular entry to the queue.int
size()
T
take()
Removes and returns next entry from the queue.
-
-
-
Constructor Detail
-
PriorityTaskQueue
public PriorityTaskQueue(int maxRegularQueueSize)
Constructor of thePriorityTaskQueue
- Parameters:
maxRegularQueueSize
- the max size of regular queue.- Throws:
java.lang.IllegalArgumentException
- if queue size in invalid.
-
-
Method Detail
-
addRegularEntry
public void addRegularEntry(T entry) throws java.lang.InterruptedException
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:
java.lang.IllegalArgumentException
- if entry is nulljava.lang.InterruptedException
- if caller thread is interrupted
-
addHighPriorityEntry
public void addHighPriorityEntry(T entry)
Adds a high-priority entry to the queue.- Parameters:
entry
- the entry to add to high-priority queue
-
take
public T take() throws java.lang.InterruptedException
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:
java.lang.InterruptedException
- if caller thread is interrupted
-
size
public int size()
-
-