Changeset 4b989eb


Ignore:
Timestamp:
Sep 7, 2011 1:38:30 AM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b64eff9
Parents:
8dc1c4f
Message:
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    r8dc1c4f r4b989eb  
     12011-09-07 zzz
     2  * Console: Limit max displayed participating tunnels
     3  * JobQueue: Change queue from a Set to a TreeSet for more efficiency
     4  * TunnelDispatcher: Change participant expire List to a Queue for
     5    efficiency and to remove global lock. Also remove separate
     6    time List for space savings.
     7
    182011-09-06 zzz
    29  * Console: Move configservice.jsp rendering code from
  • router/java/src/net/i2p/router/JobImpl.java

    r8dc1c4f r4b989eb  
    99 */
    1010
     11import java.util.concurrent.atomic.AtomicLong;
     12
    1113import net.i2p.util.Log;
     14
    1215/**
    1316 * Base implementation of a Job
     
    1619    private final RouterContext _context;
    1720    private final JobTiming _timing;
    18     private static long _idSrc = 0;
     21    private static AtomicLong _idSrc = new AtomicLong();
    1922    private final long _id;
    2023    //private Exception _addedBy;
     
    2427        _context = context;
    2528        _timing = new JobTiming(context);
    26         _id = ++_idSrc;
     29        _id = _idSrc.incrementAndGet();
    2730    }
    2831   
  • router/java/src/net/i2p/router/JobQueue.java

    r8dc1c4f r4b989eb  
    1414import java.util.Collection;
    1515import java.util.Collections;
    16 import java.util.HashSet;
     16import java.util.Comparator;
    1717import java.util.Iterator;
    1818import java.util.List;
     
    2020import java.util.SortedMap;
    2121import java.util.TreeMap;
     22import java.util.TreeSet;
    2223import java.util.Set;
    2324import java.util.concurrent.ConcurrentHashMap;
     
    4647    /** list of jobs that are ready to run ASAP */
    4748    private final BlockingQueue<Job> _readyJobs;
    48     /** list of jobs that are scheduled for running in the future */
     49    /** SortedSet of jobs that are scheduled for running in the future, earliest first */
    4950    private final Set<Job> _timedJobs;
    5051    /** job name to JobStat for that job */
     
    138139        _alive = true;
    139140        _readyJobs = new LinkedBlockingQueue();
    140         _timedJobs = new HashSet(64);
     141        _timedJobs = new TreeSet(new JobComparator());
    141142        _jobLock = new Object();
    142143        _queueRunners = new ConcurrentHashMap(RUNNERS);
    143144        _jobStats = new ConcurrentHashMap();
    144         _allowParallelOperation = false;
    145145        _pumper = new QueuePumper();
    146146        I2PThread pumperThread = new I2PThread(_pumper, "Job Queue Pumper", true);
     
    169169            numReady = _readyJobs.size();
    170170            if (!alreadyExists) {
    171                 if (_timedJobs.contains(job))
    172                     alreadyExists = true;
     171                //if (_timedJobs.contains(job))
     172                //    alreadyExists = true;
     173                // Always remove and re-add, since it needs to be
     174                // re-sorted in the TreeSet.
     175                _timedJobs.remove(job);
    173176            }
    174177
     
    186189                    } else {
    187190                        _timedJobs.add(job);
     191                        // only notify for _timedJobs, as _readyJobs does not use that lock
     192                        _jobLock.notifyAll();
    188193                    }
    189194                }
    190195            }
    191             _jobLock.notifyAll();
    192196        }
    193197       
     
    469473                                    iter.remove();
    470474                                } else {
    471                                     if ( (timeToWait <= 0) || (timeLeft < timeToWait) )
     475                                    //if ( (timeToWait <= 0) || (timeLeft < timeToWait) )
     476                                    // _timedJobs is now a TreeSet, so once we hit one that is
     477                                    // not ready yet, we can break
    472478                                        timeToWait = timeLeft;
     479                                        break;
    473480                                }
    474481                            }
     
    611618
    612619    /**
     620     *  Comparator for the _timedJobs TreeSet.
     621     *  Ensure different jobs with the same timing are different so they aren't removed.
     622     *  @since 0.8.9
     623     */
     624    private static class JobComparator implements Comparator<Job> {
     625         public int compare(Job l, Job r) {
     626             // equals first, Jobs generally don't override so this should be fast
     627             if (l.equals(r))
     628                 return 0;
     629             // This is for _timedJobs, which always have a JobTiming.
     630             // PoisonJob only goes in _readyJobs.
     631             long ld = l.getTiming().getStartAfter() - r.getTiming().getStartAfter();
     632             if (ld < 0)
     633                 return -1;
     634             if (ld > 0)
     635                 return 1;
     636             ld = l.getJobId() - r.getJobId();
     637             if (ld < 0)
     638                 return -1;
     639             if (ld > 0)
     640                 return 1;
     641             return l.hashCode() - r.hashCode();
     642        }
     643    }
     644
     645    /**
    613646     *  Dump the current state.
    614647     *  For the router console jobs status page.
  • router/java/src/net/i2p/router/RouterVersion.java

    r8dc1c4f r4b989eb  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 12;
     21    public final static long BUILD = 13;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.