Type Parameters:
E - type of elements held in this queue, extending PQEntry
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
Direct Known Subclasses:
CoDelPriorityBlockingQueue

public class PriBlockingQueue<E extends PQEntry>extends PriorityBlockingQueue<E>
Priority blocking queue with bounded capacity and FIFO ordering within priority levels.

Extends PriorityBlockingQueue to provide bounded capacity with FIFO ordering for elements sharing the same priority. Entries extend PQEntry to include sequence numbers for insertion ordering.

Applies sequence timestamps on insertion to ensure FIFO behavior within same priority level while maintaining priority-based ordering. Capacity is controlled by configuration properties to prevent unbounded growth and enable backpressure management.

Thread-safe implementation suitable for concurrent producer-consumer scenarios.

See Also:
  • Field Details

    • _context

      protected final transient I2PAppContext _context
      The I2P application context.
    • _log

      protected final transient Log _log
      The log instance.
    • _name

      protected final String _name
      The queue name.
    • DEFAULT_BACKLOG_SIZE

      protected static final int DEFAULT_BACKLOG_SIZE
      Default backlog size threshold, depends on system speed.
    • DEFAULT_MAX_SIZE

      protected static final int DEFAULT_MAX_SIZE
      Default maximum queue size.
    • PROP_MAX_SIZE

      public static final String PROP_MAX_SIZE
      Property key for maximum queue size.
      See Also:
    • PROP_BACKLOG_SIZE

      public static final String PROP_BACKLOG_SIZE
      Property key for backlog threshold.
      See Also:
  • Constructor Details

    • PriBlockingQueue

      public PriBlockingQueue(I2PAppContext ctx, String name, int initialCapacity)
      Priority blocking queue with the given initial capacity. The queue is bounded by a configurable max size read once at construction.
      Parameters:
      ctx - the I2P application context
      name - a name for this queue instance
      initialCapacity - the initial capacity for the priority queue
  • Method Details

    • offer

      public boolean offer(E o)
      Inserts the specified element into this queue if it is not full, applying sequence timestamp to ensure FIFO ordering within priority. Returns false if the queue has reached its maximum size.

      The capacity check is best-effort: size() and offer(E) are not atomic, so the queue may briefly exceed _maxSize under concurrent insertions. PriorityBlockingQueue is unbounded, so an exact atomic bound would require external synchronization.

      Specified by:
      offer in interface BlockingQueue<E extends PQEntry>
      Specified by:
      offer in interface Queue<E extends PQEntry>
      Overrides:
      offer in class PriorityBlockingQueue<E extends PQEntry>
      Parameters:
      o - the element to add
      Returns:
      true if successfully added, false if queue is full
    • isBacklogged

      public boolean isBacklogged()
      Checks if the queue size is above the backlog threshold, indicating potential congestion or overload.
      Returns:
      true if queue size is above backlog size threshold, false otherwise
    • timestamp

      protected void timestamp(E o)
      Assigns a unique sequence number to the element to maintain FIFO ordering among elements of the same priority.
      Parameters:
      o - the element to timestamp