net.i2p.router.util
Class CoDelBlockingQueue<E extends CDQEntry>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by java.util.concurrent.LinkedBlockingQueue<E>
              extended by net.i2p.router.util.CoDelBlockingQueue<E>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

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

CoDel implementation of Active Queue Management. Ref: http://queue.acm.org/detail.cfm?id=2209336 Ref: http://queue.acm.org/appendices/codel.html Code and comments are directly from appendix above, apparently public domain. Input: add(), offer(), and put() are overridden to add a timestamp. Output : take(), poll(), and drainTo() are overridden to implement AQM and drop entries if necessary. peek(), and remove() are NOT overridden, and do NOT implement AQM or update stats.

Since:
0.9.3
See Also:
Serialized Form

Constructor Summary
CoDelBlockingQueue(I2PAppContext ctx, String name, int capacity)
           
 
Method Summary
 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 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
iterator, peek, poll, remainingCapacity, remove, size, toArray, toArray, toString
 
Methods inherited from class java.util.AbstractQueue
addAll, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, 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.concurrent.BlockingQueue
contains
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll
 

Constructor Detail

CoDelBlockingQueue

public CoDelBlockingQueue(I2PAppContext ctx,
                          String name,
                          int capacity)
Parameters:
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>

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

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

clear

public void clear()
Specified by:
clear in interface Collection<E extends CDQEntry>
Overrides:
clear in class LinkedBlockingQueue<E extends CDQEntry>

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

poll

public E poll()
Specified by:
poll in interface Queue<E extends CDQEntry>
Overrides:
poll in class LinkedBlockingQueue<E extends CDQEntry>

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>

drainAllTo

public int drainAllTo(Collection<? super E> c)
Drains all, without updating stats or dropping.


isBacklogged

public boolean isBacklogged()
Has the head of the queue been waiting too long, or is the queue almost full?