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 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 Details

    • PriorityTaskQueue

      public PriorityTaskQueue(int maxRegularQueueSize)
      Constructor of the PriorityTaskQueue<T>
      Parameters:
      maxRegularQueueSize - the max size of regular queue.
      Throws:
      IllegalArgumentException - if queue size in invalid.
  • Method Details

    • addRegularEntry

      public void addRegularEntry(T entry) throws 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:
      IllegalArgumentException - if entry is null
      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 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:
      InterruptedException - if caller thread is interrupted
    • size

      public int size()