Changeset 83ee57a


Ignore:
Timestamp:
Jun 16, 2011 9:02:56 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
32793ac1
Parents:
4cff55d
Message:
  • Shutdown:
    • Implement and call shutdown for RouterWatchdog?
    • Fix i2psnark DirMonitor? not stopping
    • Fix UPnP-Disposer not stopping quickly
    • Implement and call YKGenerator and DHSessionKeyBuilder shutdown
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r4cff55d r83ee57a  
    4949    private /* FIXME final FIXME */ File _configFile;
    5050    private Properties _config;
    51     private I2PAppContext _context;
    52     private Log _log;
     51    private final I2PAppContext _context;
     52    private final Log _log;
    5353    private final List _messages;
    54     private I2PSnarkUtil _util;
     54    private final I2PSnarkUtil _util;
    5555    private PeerCoordinatorSet _peerCoordinatorSet;
    5656    private ConnectionAcceptor _connectionAcceptor;
    5757    private Thread _monitor;
    58     private boolean _running;
     58    private volatile boolean _running;
    5959   
    6060    public static final String PROP_I2CP_HOST = "i2psnark.i2cpHost";
     
    10901090            getBWLimit();
    10911091            boolean doMagnets = true;
    1092             while (true) {
     1092            while (_running) {
    10931093                File dir = getDataDir();
    10941094                if (_log.shouldLog(Log.DEBUG))
  • core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java

    r4cff55d r83ee57a  
    5454    private static final int CALC_DELAY;
    5555    private static final LinkedBlockingQueue<DHSessionKeyBuilder> _builders;
    56     private static final Thread _precalcThread;
     56    private static Thread _precalcThread;
     57    private static volatile boolean _isRunning;
    5758
    5859    // the data of importance
     
    9798            _log.debug("DH Precalc (minimum: " + MIN_NUM_BUILDERS + " max: " + MAX_NUM_BUILDERS + ", delay: "
    9899                       + CALC_DELAY + ")");
    99 
    100         _precalcThread = new I2PThread(new DHSessionKeyBuilderPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
    101         _precalcThread.setName("DH Precalc");
    102         _precalcThread.setDaemon(true);
    103         _precalcThread.setPriority(Thread.MIN_PRIORITY);
    104         _precalcThread.start();
     100        startPrecalc();
     101    }
     102
     103    /** @since 0.8.8 */
     104    private static void startPrecalc() {
     105        synchronized(DHSessionKeyBuilder.class) {
     106            _precalcThread = new I2PThread(new DHSessionKeyBuilderPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS),
     107                                           "DH Precalc", true);
     108            _precalcThread.setPriority(Thread.MIN_PRIORITY);
     109            _isRunning = true;
     110            _precalcThread.start();
     111        }
     112    }
     113
     114    /**
     115     *  Note that this stops the singleton precalc thread.
     116     *  You don't want to do this if there are multiple routers in the JVM.
     117     *  Fix this if you care. See Router.shutdown().
     118     *  @since 0.8.8
     119     */
     120    public static void shutdown() {
     121        _isRunning = false;
     122        _precalcThread.interrupt();
     123        _builders.clear();
     124    }
     125
     126    /**
     127     *  Only required if shutdown() previously called.
     128     *  @since 0.8.8
     129     */
     130    public static void restart() {
     131        synchronized(DHSessionKeyBuilder.class) {
     132            if (!_isRunning)
     133                startPrecalc();
     134        }
    105135    }
    106136
  • core/java/src/net/i2p/crypto/ElGamalEngine.java

    r4cff55d r83ee57a  
    7979
    8080   
     81    /**
     82     *  Note that this stops the singleton precalc thread.
     83     *  You don't want to do this if there are multiple routers in the JVM.
     84     *  Fix this if you care. See Router.shutdown().
     85     *  @since 0.8.8
     86     */
     87    public void shutdown() {
     88        YKGenerator.shutdown();
     89    }
     90
     91    /**
     92     *  Only required if shutdown() previously called.
     93     *  @since 0.8.8
     94     */
     95    public static void restart() {
     96        YKGenerator.restart();
     97    }
     98
    8199    private final static BigInteger _two = new NativeBigInteger(1, new byte[] { 0x02});
    82100
  • core/java/src/net/i2p/crypto/YKGenerator.java

    r4cff55d r83ee57a  
    4343    private static final int CALC_DELAY;
    4444    private static final LinkedBlockingQueue<BigInteger[]> _values;
    45     private static final Thread _precalcThread;
     45    private static Thread _precalcThread;
    4646    private static final I2PAppContext ctx;
     47    private static volatile boolean _isRunning;
    4748
    4849    public final static String PROP_YK_PRECALC_MIN = "crypto.yk.precalc.min";
     
    7879        ctx.statManager().createRateStat("crypto.YKUsed", "Need a YK from the queue", "Encryption", new long[] { 60*60*1000 });
    7980        ctx.statManager().createRateStat("crypto.YKEmpty", "YK queue empty", "Encryption", new long[] { 60*60*1000 });
    80 
    81         _precalcThread = new I2PThread(new YKPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
    82         _precalcThread.setName("YK Precalc");
    83         _precalcThread.setDaemon(true);
    84         _precalcThread.setPriority(Thread.MIN_PRIORITY);
    85         _precalcThread.start();
     81        startPrecalc();
     82    }
     83
     84    /** @since 0.8.8 */
     85    private static void startPrecalc() {
     86        synchronized(YKGenerator.class) {
     87            _precalcThread = new I2PThread(new YKPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS),
     88                                       "YK Precalc", true);
     89            _precalcThread.setPriority(Thread.MIN_PRIORITY);
     90            _isRunning = true;
     91            _precalcThread.start();
     92        }
     93    }
     94
     95    /**
     96     *  Note that this stops the singleton precalc thread.
     97     *  You don't want to do this if there are multiple routers in the JVM.
     98     *  Fix this if you care. See Router.shutdown().
     99     *  @since 0.8.8
     100     */
     101    public static void shutdown() {
     102        _isRunning = false;
     103        _precalcThread.interrupt();
     104        _values.clear();
     105    }
     106
     107    /**
     108     *  Only required if shutdown() previously called.
     109     *  @since 0.8.8
     110     */
     111    public static void restart() {
     112        synchronized(YKGenerator.class) {
     113            if (!_isRunning)
     114                startPrecalc();
     115        }
    86116    }
    87117
     
    162192
    163193        public void run() {
    164             while (true) {
     194            while (_isRunning) {
    165195                int curSize = 0;
    166196                //long start = Clock.getInstance().now();
     
    173203                curSize = startSize;
    174204                if (curSize < _minSize) {
    175                     for (int i = curSize; i < _maxSize; i++) {
     205                    for (int i = curSize; i < _maxSize && _isRunning; i++) {
    176206                        //long begin = Clock.getInstance().now();
    177207                        if (!addValues(generateYK()))
  • router/java/src/net/i2p/router/Router.java

    r4cff55d r83ee57a  
    7676    private ShutdownHook _shutdownHook;
    7777    private final I2PThread _gracefulShutdownDetector;
     78    private final RouterWatchdog _watchdog;
     79    private final Thread _watchdogThread;
    7880   
    7981    public final static String PROP_CONFIG_FILE = "router.configLocation";
     
    278280        _gracefulShutdownDetector.start();
    279281       
    280         Thread watchdog = new I2PAppThread(new RouterWatchdog(_context), "RouterWatchdog", true);
    281         watchdog.start();
     282        _watchdog = new RouterWatchdog(_context);
     283        _watchdogThread = new I2PAppThread(_watchdog, "RouterWatchdog", true);
     284        _watchdogThread.start();
    282285       
    283286    }
     
    644647    private void warmupCrypto() {
    645648        _context.random().nextBoolean();
    646         new DHSessionKeyBuilder(); // load the class so it starts the precalc process
     649        // Use restart() to refire the static refiller threads, in case
     650        // we are restarting the router in the same JVM (Android)
     651        DHSessionKeyBuilder.restart();
     652        _context.elGamalEngine().restart();
    647653    }
    648654   
     
    978984
    979985        // shut down I2PAppContext tasks here
     986
     987        // TODO if there are multiple routers in the JVM, we don't want to do this
     988        // to the DH or YK tasks, as they are singletons.
     989        // Have MultiRouter set a property or something.
     990        try {
     991            DHSessionKeyBuilder.shutdown();
     992        } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting DH", t); }
     993        try {
     994            _context.elGamalEngine().shutdown();
     995        } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting elGamal", t); }
    980996        try {
    981997            ((FortunaRandomSource)_context.random()).shutdown();
     
    983999
    9841000        // logManager shut down in finalShutdown()
     1001        _watchdog.shutdown();
     1002        _watchdogThread.interrupt();
    9851003        finalShutdown(exitCode);
    9861004    }
  • router/java/src/net/i2p/router/RouterWatchdog.java

    r4cff55d r83ee57a  
    1616    private final RouterContext _context;
    1717    private int _consecutiveErrors;
     18    private volatile boolean _isRunning;
    1819   
    1920    private static final long MAX_JOB_RUN_LAG = 60*1000;
     
    2223        _context = ctx;
    2324        _log = ctx.logManager().getLog(RouterWatchdog.class);
     25        _isRunning = true;
    2426    }
    2527   
     28    /** @since 0.8.8 */
     29    public void shutdown() {
     30        _isRunning = false;
     31    }
     32
    2633    public boolean verifyJobQueueLiveliness() {
    2734        long when = _context.jobQueue().getLastJobBegin();
     
    110117   
    111118    public void run() {
    112         while (true) {
     119        while (_isRunning) {
    113120            try { Thread.sleep(60*1000); } catch (InterruptedException ie) {}
    114121            monitorRouter();
  • router/java/src/org/cybergarage/util/ThreadCore.java

    r4cff55d r83ee57a  
    6666                        //threadObject.stop();
    6767                        setThreadObject(null);
     68                        // I2P break Disposer out of sleep()
     69                        threadObject.interrupt();
    6870                }
    6971        }
Note: See TracChangeset for help on using the changeset viewer.