- Type Parameters:
E- type of elements held in this queue, extendingPQEntry
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
- Direct Known Subclasses:
CoDelPriorityBlockingQueue
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:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classPriBlockingQueue.PriorityComparator<E extends PQEntry>Comparator used to order queue elements by descending priority, then ascending sequence number to preserve FIFO inside priority.Field Summary
Modifier and TypeFieldDescriptionprotected final I2PAppContextThe I2P application context.protected final LogThe log instance.private final intCached maximum queue size limit to avoid repeated config property lookups.protected final StringThe queue name.private final AtomicLongAtomic sequence number for entries to ensure insertion order among equals in priority.protected static final intDefault backlog size threshold, depends on system speed.protected static final intDefault maximum queue size.private static final PriBlockingQueue.PriorityComparator<?> Singleton comparator instance to avoid repeated creation.static final StringProperty key for backlog threshold.static final StringProperty key for maximum queue size.private static final longPinned for serialized-form compatibility.Constructor Summary
ConstructorsConstructorDescriptionPriBlockingQueue(I2PAppContext ctx, String name, int initialCapacity) Priority blocking queue with the given initial capacity.Method Summary
Public MethodsModifier and TypeMethodDescriptionbooleanChecks if the queue size is above the backlog threshold, indicating potential congestion or overload.booleanInserts the specified element into this queue if it is not full, applying sequence timestamp to ensure FIFO ordering within priority.protected voidAssigns a unique sequence number to the element to maintain FIFO ordering among elements of the same priority.Methods inherited from class PriorityBlockingQueue
add, clear, comparator, contains, drainTo, drainTo, forEach, iterator, offer, peek, poll, poll, put, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, take, toArray, toArray, toStringMethods inherited from class AbstractQueue
addAll, element, removeMethods inherited from class AbstractCollection
containsAll, isEmptyMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
equals, hashCode, parallelStream, stream, toArray
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
_context
The I2P application context._log
The log instance._name
The queue name._seqNum
Atomic sequence number for entries to ensure insertion order among equals in priority._maxSize
private final int _maxSizeCached maximum queue size limit to avoid repeated config property lookups.DEFAULT_BACKLOG_SIZE
protected static final int DEFAULT_BACKLOG_SIZEDefault backlog size threshold, depends on system speed.DEFAULT_MAX_SIZE
protected static final int DEFAULT_MAX_SIZEDefault maximum queue size.PROP_MAX_SIZE
Property key for maximum queue size.- See Also:
PROP_BACKLOG_SIZE
Property key for backlog threshold.- See Also:
PRIORITY_COMPARATOR
Singleton comparator instance to avoid repeated creation.
Constructor Details
PriBlockingQueue
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 contextname- a name for this queue instanceinitialCapacity- the initial capacity for the priority queue
Method Details
offer
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.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
Assigns a unique sequence number to the element to maintain FIFO ordering among elements of the same priority.- Parameters:
o- the element to timestamp