* Router Clock: First cut at recognizing and reacting to large system

clock shifts by partially restarting the router. Also improve
    restarts initiated from config.jsp
    Tickets #465, #468, #494
  * UPnP: Wait for a while to ensure port removal at shutdown or restart
This commit is contained in:
zzz
2011-07-10 00:00:58 +00:00
parent 4fd1800944
commit 42acdc314a
8 changed files with 209 additions and 58 deletions

View File

@@ -17,7 +17,7 @@ import net.i2p.util.Log;
* forever.
*/
public class Timestamper implements Runnable {
private I2PAppContext _context;
private final I2PAppContext _context;
private Log _log;
private final List<String> _servers;
private List<String> _priorityServers;
@@ -26,7 +26,7 @@ public class Timestamper implements Runnable {
private int _concurringServers;
private int _consecutiveFails;
private volatile boolean _disabled;
private boolean _daemon;
private final boolean _daemon;
private boolean _initialized;
private boolean _wellSynced;
private volatile boolean _isRunning;
@@ -60,6 +60,10 @@ public class Timestamper implements Runnable {
// moved here to prevent problems with synchronized statements.
_servers = new ArrayList(3);
_listeners = new CopyOnWriteArrayList();
_context = ctx;
_daemon = daemon;
// DO NOT initialize _log here, stack overflow via LogManager init loop
// Don't bother starting a thread if we are disabled.
// This means we no longer check every 5 minutes to see if we got enabled,
// so the property must be set at startup.
@@ -69,10 +73,6 @@ public class Timestamper implements Runnable {
_initialized = true;
return;
}
_context = ctx;
_daemon = daemon;
_initialized = false;
_wellSynced = false;
if (lsnr != null)
_listeners.add(lsnr);
updateConfig();
@@ -124,6 +124,15 @@ public class Timestamper implements Runnable {
} catch (InterruptedException ie) {}
}
/**
* Update the time immediately.
* @since 0.8.8
*/
public void timestampNow() {
if (_initialized && _isRunning && (!_disabled) && _timestamperThread != null)
_timestamperThread.interrupt();
}
/** @since 0.8.8 */
private class Shutdown implements Runnable {
public void run() {

View File

@@ -1,6 +1,5 @@
package net.i2p.util;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -21,11 +20,11 @@ import net.i2p.time.Timestamper;
public class Clock implements Timestamper.UpdateListener {
protected final I2PAppContext _context;
private final Timestamper _timestamper;
protected final long _startedOn;
protected long _startedOn;
protected boolean _statCreated;
protected volatile long _offset;
protected boolean _alreadyChanged;
private final Set _listeners;
private final Set<ClockUpdateListener> _listeners;
public Clock(I2PAppContext context) {
_context = context;
@@ -33,6 +32,7 @@ public class Clock implements Timestamper.UpdateListener {
_timestamper = new Timestamper(context, this);
_startedOn = System.currentTimeMillis();
}
public static Clock getInstance() {
return I2PAppContext.getGlobalContext().clock();
}
@@ -151,13 +151,17 @@ public class Clock implements Timestamper.UpdateListener {
}
protected void fireOffsetChanged(long delta) {
for (Iterator iter = _listeners.iterator(); iter.hasNext();) {
ClockUpdateListener lsnr = (ClockUpdateListener) iter.next();
for (ClockUpdateListener lsnr : _listeners) {
lsnr.offsetChanged(delta);
}
}
public static interface ClockUpdateListener {
public interface ClockUpdateListener {
/**
* @param delta = (new offset - old offset),
* where each offset = (now() - System.currentTimeMillis())
*/
public void offsetChanged(long delta);
}
}