net.i2p.router.util

## Class CoDelBlockingQueue<E extends CDQEntry>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractQueue<E>
    - - java.util.concurrent.LinkedBlockingQueue<E>
      - - net.i2p.router.util.CoDelBlockingQueue<E>

- Type Parameters:
    `E` - type of elements in this queue
  All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

      public class CoDelBlockingQueue<E extends CDQEntry>
      extends LinkedBlockingQueue<E>

  CoDel (Controlled Delay) implementation of Active Queue Management.

  Implements the CoDel algorithm from RFC 8289 for managing queue congestion and controlling latency through packet dropping. Provides active queue management with automatic dropping when queue delay exceeds configurable thresholds.

  Code and comments are derived from RFC 8289 appendix, implementing the standard CoDel algorithm with configurable target delay and interval parameters. Monitors queue sojourn time and drops packets when above target to maintain optimal throughput and latency characteristics.

  Input methods are overridden to add timestamps for delay calculation. Output methods implement AQM behavior with comprehensive statistics tracking for performance monitoring.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_CODEL_INTERVAL`
    `static String` | `PROP_CODEL_TARGET`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CoDelBlockingQueue(I2PAppContext ctx, String name, int capacity)` Target 15, interval 100
    `CoDelBlockingQueue(I2PAppContext ctx, String name, int capacity, int target, int interval)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(E o)`
    `void` | `clear()`
    `int` | `drainAllTo(Collection<? super E> c)` Drains all, without updating stats or dropping.
    `int` | `drainTo(Collection<? super E> c)` Updates stats and possibly drops while draining.
    `int` | `drainTo(Collection<? super E> c, int maxElements)` Updates stats and possibly drops while draining.
    `boolean` | `isBacklogged()` Has the head of the queue been waiting too long, or is the queue almost full?
    `boolean` | `isNearlyFull()` Check if the queue is nearly full (above threshold).
    `boolean` | `offer(E o)`
    `boolean` | `offer(E o, long timeout, TimeUnit unit)`
    `E` | `poll()`
    `void` | `put(E o)`
    `E` | `take()`

    - ### Methods inherited from class java.util.concurrent.LinkedBlockingQueue

      `contains, iterator, peek, poll, remainingCapacity, remove, size, spliterator, toArray, toArray, toString`

    - ### Methods inherited from class java.util.AbstractQueue

      `addAll, element, remove`

    - ### Methods inherited from class java.util.AbstractCollection

      `containsAll, isEmpty, removeAll, retainAll`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Queue

      `element, remove`

    - ### Methods inherited from interface java.util.Collection

      `addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Field Detail

    - #### PROP_CODEL_INTERVAL

          public static final String PROP_CODEL_INTERVAL

      See Also:
        Constant Field Values

    - #### PROP_CODEL_TARGET

          public static final String PROP_CODEL_TARGET

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CoDelBlockingQueue

          public CoDelBlockingQueue(I2PAppContext ctx,
                                    String name,
                                    int capacity)

      Target 15, interval 100
      Parameters:
        `name` - for stats

    - #### CoDelBlockingQueue

          public CoDelBlockingQueue(I2PAppContext ctx,
                                    String name,
                                    int capacity,
                                    int target,
                                    int interval)

      Parameters:
        `target` - the target max latency (ms)
        `interval` - how long above target to start dropping (ms)
        `name` - for stats

  - ### Method Detail

    - #### add

          public boolean add(E o)

      Specified by:
        `add` in interface `Collection<E extends CDQEntry>`
      Specified by:
        `add` in interface `BlockingQueue<E extends CDQEntry>`
      Specified by:
        `add` in interface `Queue<E extends CDQEntry>`
      Overrides:
        `add` in class `AbstractQueue<E extends CDQEntry>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<E extends CDQEntry>`
      Overrides:
        `clear` in class `LinkedBlockingQueue<E extends CDQEntry>`

    - #### drainAllTo

          public int drainAllTo(Collection<? super E> c)

      Drains all, without updating stats or dropping.

    - #### drainTo

          public int drainTo(Collection<? super E> c)

      Updates stats and possibly drops while draining.
      Specified by:
        `drainTo` in interface `BlockingQueue<E extends CDQEntry>`
      Overrides:
        `drainTo` in class `LinkedBlockingQueue<E extends CDQEntry>`

    - #### drainTo

          public int drainTo(Collection<? super E> c,
                             int maxElements)

      Updates stats and possibly drops while draining.
      Specified by:
        `drainTo` in interface `BlockingQueue<E extends CDQEntry>`
      Overrides:
        `drainTo` in class `LinkedBlockingQueue<E extends CDQEntry>`

    - #### isBacklogged

          public boolean isBacklogged()

      Has the head of the queue been waiting too long, or is the queue almost full?

    - #### isNearlyFull

          public boolean isNearlyFull()

      Check if the queue is nearly full (above threshold). Used for early drop decisions before blocking.
      Returns:
        true if queue is above 90% capacity

    - #### offer

          public boolean offer(E o)

      Specified by:
        `offer` in interface `BlockingQueue<E extends CDQEntry>`
      Specified by:
        `offer` in interface `Queue<E extends CDQEntry>`
      Overrides:
        `offer` in class `LinkedBlockingQueue<E extends CDQEntry>`

    - #### offer

          public boolean offer(E o,
                               long timeout,
                               TimeUnit unit)
                        throws InterruptedException

      Specified by:
        `offer` in interface `BlockingQueue<E extends CDQEntry>`
      Overrides:
        `offer` in class `LinkedBlockingQueue<E extends CDQEntry>`
      Throws:
        `InterruptedException`

    - #### poll

          public E poll()

      Specified by:
        `poll` in interface `Queue<E extends CDQEntry>`
      Overrides:
        `poll` in class `LinkedBlockingQueue<E extends CDQEntry>`

    - #### put

          public void put(E o)
                   throws InterruptedException

      Specified by:
        `put` in interface `BlockingQueue<E extends CDQEntry>`
      Overrides:
        `put` in class `LinkedBlockingQueue<E extends CDQEntry>`
      Throws:
        `InterruptedException`

    - #### take

          public E take()
                 throws InterruptedException

      Specified by:
        `take` in interface `BlockingQueue<E extends CDQEntry>`
      Overrides:
        `take` in class `LinkedBlockingQueue<E extends CDQEntry>`
      Throws:
        `InterruptedException`