Changeset b8949ea


Ignore:
Timestamp:
Sep 5, 2012 3:50:11 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
0c5b4c0
Parents:
9286d6a
Message:

Non-codel version of priority blocking queue, so we can
implement priority queues without necessarily committing to codel.

Location:
router/java/src/net/i2p/router/util
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/util/CDPQEntry.java

    r9286d6a rb8949ea  
    55 *  @since 0.9.3
    66 */
    7 public interface CDPQEntry extends CDQEntry {
     7public interface CDPQEntry extends CDQEntry, PQEntry {
    88
    9     /**
    10      *  Higher is higher priority
    11      */
    12     public int getPriority();
    13 
    14     /**
    15      *  To be set by the queue
    16      */
    17     public void setSeqNum(long num);
    18 
    19     /**
    20      *  Needed to ensure FIFO ordering within a single priority
    21      */
    22     public long getSeqNum();
    239}
  • router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java

    r9286d6a rb8949ea  
    2626 *  @since 0.9.3
    2727 */
    28 public class CoDelPriorityBlockingQueue<E extends CDPQEntry> extends PriorityBlockingQueue<E> {
     28public class CoDelPriorityBlockingQueue<E extends CDPQEntry> extends PriBlockingQueue<E> {
    2929
    3030    private final I2PAppContext _context;
     
    8282     */
    8383    public CoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity) {
    84         super(initialCapacity, new PriorityComparator());
     84        super(initialCapacity);
    8585        _context = ctx;
    8686        _log = ctx.logManager().getLog(CoDelPriorityBlockingQueue.class);
     
    9696
    9797    @Override
    98     public boolean add(E o) {
    99         timestamp(o);
    100         return super.add(o);
    101     }
    102 
    103     @Override
    104     public boolean offer(E o) {
    105         timestamp(o);
    106         return super.offer(o);
    107     }
    108 
    109     @Override
    110     public boolean offer(E o, long timeout, TimeUnit unit) {
    111         timestamp(o);
    112         return super.offer(o, timeout, unit);
    113     }
    114 
    115     @Override
    116     public void put(E o) {
    117         timestamp(o);
    118         super.put(o);
    119     }
    120 
    121     @Override
    12298    public void clear() {
    12399        super.clear();
     
    181157    /////// private below here
    182158
    183     private void timestamp(E o) {
     159    @Override
     160    protected void timestamp(E o) {
    184161        o.setSeqNum(_seqNum.incrementAndGet());
    185162        o.setEnqueueTime(_context.clock().now());
     
    318295        _drop_next = t + (long) (INTERVAL / Math.sqrt(_count));
    319296    }
    320 
    321     /**
    322      *  highest priority first, then lowest sequence number first
    323      */
    324     private static class PriorityComparator<E extends CDPQEntry> implements Comparator<E> {
    325         public int compare(E l, E r) {
    326             int d = r.getPriority() - l.getPriority();
    327             if (d != 0)
    328                 return d;
    329             long ld = l.getSeqNum() - r.getSeqNum();
    330             return ld > 0 ? 1 : -1;
    331         }
    332     }
    333297}
Note: See TracChangeset for help on using the changeset viewer.