forked from I2P_Developers/i2p.i2p
SimpleTimer (ticket #653):
- Move all remaining uses to SimpleTimer2 - Deprecate
This commit is contained in:
@ -13,7 +13,6 @@ import net.i2p.data.Destination;
|
|||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.SessionKey;
|
import net.i2p.data.SessionKey;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
|
||||||
import net.i2p.util.SimpleTimer2;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -494,7 +493,8 @@ class ConnectionManager {
|
|||||||
}
|
}
|
||||||
_pendingPings.remove(id);
|
_pendingPings.remove(id);
|
||||||
} else {
|
} else {
|
||||||
SimpleTimer.getInstance().addEvent(new PingFailed(id, notifier), timeoutMs);
|
PingFailed pf = new PingFailed(id, notifier);
|
||||||
|
pf.schedule(timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ok = req.pongReceived();
|
boolean ok = req.pongReceived();
|
||||||
@ -505,11 +505,12 @@ class ConnectionManager {
|
|||||||
public void pingComplete(boolean ok);
|
public void pingComplete(boolean ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PingFailed implements SimpleTimer.TimedEvent {
|
private class PingFailed extends SimpleTimer2.TimedEvent {
|
||||||
private final Long _id;
|
private final Long _id;
|
||||||
private final PingNotifier _notifier;
|
private final PingNotifier _notifier;
|
||||||
|
|
||||||
public PingFailed(Long id, PingNotifier notifier) {
|
public PingFailed(Long id, PingNotifier notifier) {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
_id = id;
|
_id = id;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
}
|
}
|
||||||
|
@ -953,6 +953,7 @@ public class I2PAppContext {
|
|||||||
/**
|
/**
|
||||||
* Use instead of SimpleTimer.getInstance()
|
* Use instead of SimpleTimer.getInstance()
|
||||||
* @since 0.9 to replace static instance in the class
|
* @since 0.9 to replace static instance in the class
|
||||||
|
* @deprecated use SimpleTimer2
|
||||||
*/
|
*/
|
||||||
public SimpleTimer simpleTimer() {
|
public SimpleTimer simpleTimer() {
|
||||||
if (!_simpleTimerInitialized)
|
if (!_simpleTimerInitialized)
|
||||||
@ -960,6 +961,9 @@ public class I2PAppContext {
|
|||||||
return _simpleTimer;
|
return _simpleTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use SimpleTimer2
|
||||||
|
*/
|
||||||
private void initializeSimpleTimer() {
|
private void initializeSimpleTimer() {
|
||||||
synchronized (_lock19) {
|
synchronized (_lock19) {
|
||||||
if (_simpleTimer == null)
|
if (_simpleTimer == null)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package net.i2p.util;
|
package net.i2p.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Deprecated - used only by SimpleTimer
|
||||||
*
|
*
|
||||||
* @author sponge
|
* @author sponge
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,7 @@ public class SimpleTimer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If you have a context, use context.simpleTimer() instead
|
* If you have a context, use context.simpleTimer() instead
|
||||||
|
* @deprecated use SimpleTimer2
|
||||||
*/
|
*/
|
||||||
public static SimpleTimer getInstance() {
|
public static SimpleTimer getInstance() {
|
||||||
return I2PAppContext.getGlobalContext().simpleTimer();
|
return I2PAppContext.getGlobalContext().simpleTimer();
|
||||||
@ -39,6 +40,7 @@ public class SimpleTimer {
|
|||||||
/**
|
/**
|
||||||
* To be instantiated by the context.
|
* To be instantiated by the context.
|
||||||
* Others should use context.simpleTimer() instead
|
* Others should use context.simpleTimer() instead
|
||||||
|
* @deprecated use SimpleTimer2
|
||||||
*/
|
*/
|
||||||
public SimpleTimer(I2PAppContext context) {
|
public SimpleTimer(I2PAppContext context) {
|
||||||
this(context, "SimpleTimer");
|
this(context, "SimpleTimer");
|
||||||
@ -47,6 +49,7 @@ public class SimpleTimer {
|
|||||||
/**
|
/**
|
||||||
* To be instantiated by the context.
|
* To be instantiated by the context.
|
||||||
* Others should use context.simpleTimer() instead
|
* Others should use context.simpleTimer() instead
|
||||||
|
* @deprecated use SimpleTimer2
|
||||||
*/
|
*/
|
||||||
private SimpleTimer(I2PAppContext context, String name) {
|
private SimpleTimer(I2PAppContext context, String name) {
|
||||||
runn = new SimpleStore(true);
|
runn = new SimpleStore(true);
|
||||||
@ -146,6 +149,7 @@ public class SimpleTimer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// FIXME if you plan to use this class again
|
||||||
while (_events.containsKey(time))
|
while (_events.containsKey(time))
|
||||||
time = new Long(time.longValue() + 1);
|
time = new Long(time.longValue() + 1);
|
||||||
_events.put(time, event);
|
_events.put(time, event);
|
||||||
|
@ -205,10 +205,8 @@ public class SimpleTimer2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* More efficient than reschedule().
|
* Slightly more efficient than reschedule().
|
||||||
* Only call this after calling the non-scheduling constructor,
|
* Does nothing if already scheduled.
|
||||||
* or from within timeReached(), or you will get duplicates on the queue.
|
|
||||||
* Otherwise use reschedule().
|
|
||||||
*/
|
*/
|
||||||
public synchronized void schedule(long timeoutMs) {
|
public synchronized void schedule(long timeoutMs) {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
@ -236,7 +234,8 @@ public class SimpleTimer2 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the earliest of the new time and the old time
|
* Use the earliest of the new time and the old time
|
||||||
* Do not call from within timeReached()
|
* May be called from within timeReached(), but schedule() is
|
||||||
|
* better there.
|
||||||
*
|
*
|
||||||
* @param timeoutMs
|
* @param timeoutMs
|
||||||
*/
|
*/
|
||||||
@ -245,8 +244,8 @@ public class SimpleTimer2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* useEarliestTime must be false if called from within timeReached(), as
|
* May be called from within timeReached(), but schedule() is
|
||||||
* it won't be rescheduled, in favor of the currently running task
|
* better there.
|
||||||
*
|
*
|
||||||
* @param timeoutMs
|
* @param timeoutMs
|
||||||
* @param useEarliestTime if its already scheduled, use the earlier of the
|
* @param useEarliestTime if its already scheduled, use the earlier of the
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||||||
*
|
*
|
||||||
* Use socket.setsotimeout instead?
|
* Use socket.setsotimeout instead?
|
||||||
*/
|
*/
|
||||||
public class SocketTimeout implements SimpleTimer.TimedEvent {
|
public class SocketTimeout extends SimpleTimer2.TimedEvent {
|
||||||
private Socket _targetSocket;
|
private Socket _targetSocket;
|
||||||
private long _startTime;
|
private long _startTime;
|
||||||
private long _inactivityDelay;
|
private long _inactivityDelay;
|
||||||
@ -24,12 +24,13 @@ public class SocketTimeout implements SimpleTimer.TimedEvent {
|
|||||||
private Runnable _command;
|
private Runnable _command;
|
||||||
public SocketTimeout(long delay) { this(null, delay); }
|
public SocketTimeout(long delay) { this(null, delay); }
|
||||||
public SocketTimeout(Socket socket, long delay) {
|
public SocketTimeout(Socket socket, long delay) {
|
||||||
|
super(SimpleTimer2.getInstance());
|
||||||
_inactivityDelay = delay;
|
_inactivityDelay = delay;
|
||||||
_targetSocket = socket;
|
_targetSocket = socket;
|
||||||
_cancelled = false;
|
_cancelled = false;
|
||||||
_lastActivity = _startTime = System.currentTimeMillis();
|
_lastActivity = _startTime = System.currentTimeMillis();
|
||||||
_totalTimeoutTime = -1;
|
_totalTimeoutTime = -1;
|
||||||
SimpleTimer.getInstance().addEvent(SocketTimeout.this, delay);
|
schedule(delay);
|
||||||
}
|
}
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
if (_cancelled) return;
|
if (_cancelled) return;
|
||||||
@ -44,13 +45,13 @@ public class SocketTimeout implements SimpleTimer.TimedEvent {
|
|||||||
}
|
}
|
||||||
if (_command != null) _command.run();
|
if (_command != null) _command.run();
|
||||||
} else {
|
} else {
|
||||||
SimpleTimer.getInstance().addEvent(SocketTimeout.this, _inactivityDelay);
|
schedule(_inactivityDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public boolean cancel() {
|
||||||
_cancelled = true;
|
_cancelled = true;
|
||||||
SimpleTimer.getInstance().removeEvent(SocketTimeout.this);
|
return super.cancel();
|
||||||
}
|
}
|
||||||
public void setSocket(Socket s) { _targetSocket = s; }
|
public void setSocket(Socket s) { _targetSocket = s; }
|
||||||
public void resetTimer() { _lastActivity = System.currentTimeMillis(); }
|
public void resetTimer() { _lastActivity = System.currentTimeMillis(); }
|
||||||
|
@ -25,7 +25,7 @@ import net.i2p.router.ReplyJob;
|
|||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.util.ConcurrentHashSet;
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks outbound messages.
|
* Tracks outbound messages.
|
||||||
@ -254,10 +254,11 @@ public class OutboundMessageRegistry {
|
|||||||
/** @deprecated unused */
|
/** @deprecated unused */
|
||||||
public void renderStatusHTML(Writer out) throws IOException {}
|
public void renderStatusHTML(Writer out) throws IOException {}
|
||||||
|
|
||||||
private class CleanupTask implements SimpleTimer.TimedEvent {
|
private class CleanupTask extends SimpleTimer2.TimedEvent {
|
||||||
private long _nextExpire;
|
private long _nextExpire;
|
||||||
|
|
||||||
public CleanupTask() {
|
public CleanupTask() {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
_nextExpire = -1;
|
_nextExpire = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,14 +313,14 @@ public class OutboundMessageRegistry {
|
|||||||
|
|
||||||
if (_nextExpire <= now)
|
if (_nextExpire <= now)
|
||||||
_nextExpire = now + 10*1000;
|
_nextExpire = now + 10*1000;
|
||||||
SimpleTimer.getInstance().addEvent(CleanupTask.this, _nextExpire - now);
|
schedule(_nextExpire - now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleExpiration(MessageSelector sel) {
|
public void scheduleExpiration(MessageSelector sel) {
|
||||||
long now = _context.clock().now();
|
long now = _context.clock().now();
|
||||||
if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
|
if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
|
||||||
_nextExpire = sel.getExpiration();
|
_nextExpire = sel.getExpiration();
|
||||||
SimpleTimer.getInstance().addEvent(CleanupTask.this, _nextExpire - now);
|
reschedule(_nextExpire - now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import net.i2p.util.ConcurrentHashSet;
|
|||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
|
import net.i2p.util.SimpleTimer2;
|
||||||
import net.i2p.util.Translate;
|
import net.i2p.util.Translate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -369,7 +370,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
// _flooder.startup();
|
// _flooder.startup();
|
||||||
_expireEvent.setIsAlive(true);
|
_expireEvent.setIsAlive(true);
|
||||||
_testEvent.setIsAlive(true); // this queues it for 3-6 minutes in the future...
|
_testEvent.setIsAlive(true); // this queues it for 3-6 minutes in the future...
|
||||||
SimpleTimer.getInstance().addEvent(_testEvent, 10*1000); // lets requeue it for Real Soon
|
_testEvent.reschedule(10*1000); // lets requeue it for Real Soon
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
@ -681,7 +682,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
_context.router().rebuildRouterInfo();
|
_context.router().rebuildRouterInfo();
|
||||||
}
|
}
|
||||||
_testEvent.forceRun();
|
_testEvent.forceRun();
|
||||||
SimpleTimer.getInstance().addEvent(_testEvent, 5*1000);
|
_testEvent.reschedule(5*1000);
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,7 +860,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
|
|
||||||
if (getReachabilityStatus() != CommSystemFacade.STATUS_OK) {
|
if (getReachabilityStatus() != CommSystemFacade.STATUS_OK) {
|
||||||
_testEvent.forceRun();
|
_testEvent.forceRun();
|
||||||
SimpleTimer.getInstance().addEvent(_testEvent, 0);
|
_testEvent.reschedule(0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -933,7 +934,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class RemoveDropList implements SimpleTimer.TimedEvent {
|
private class RemoveDropList implements SimpleTimer.TimedEvent {
|
||||||
private RemoteHostId _peer;
|
private final RemoteHostId _peer;
|
||||||
public RemoveDropList(RemoteHostId peer) { _peer = peer; }
|
public RemoveDropList(RemoteHostId peer) { _peer = peer; }
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
_dropList.remove(_peer);
|
_dropList.remove(_peer);
|
||||||
@ -2361,12 +2362,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
public String toString() { return "UDP bid @ " + getLatencyMs(); }
|
public String toString() { return "UDP bid @ " + getLatencyMs(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExpirePeerEvent implements SimpleTimer.TimedEvent {
|
private class ExpirePeerEvent extends SimpleTimer2.TimedEvent {
|
||||||
private final Set<PeerState> _expirePeers;
|
private final Set<PeerState> _expirePeers;
|
||||||
private final List<PeerState> _expireBuffer;
|
private final List<PeerState> _expireBuffer;
|
||||||
private volatile boolean _alive;
|
private volatile boolean _alive;
|
||||||
|
|
||||||
public ExpirePeerEvent() {
|
public ExpirePeerEvent() {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
_expirePeers = new ConcurrentHashSet(128);
|
_expirePeers = new ConcurrentHashSet(128);
|
||||||
_expireBuffer = new ArrayList();
|
_expireBuffer = new ArrayList();
|
||||||
}
|
}
|
||||||
@ -2403,7 +2405,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
_expireBuffer.clear();
|
_expireBuffer.clear();
|
||||||
|
|
||||||
if (_alive)
|
if (_alive)
|
||||||
SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
|
schedule(30*1000);
|
||||||
}
|
}
|
||||||
public void add(PeerState peer) {
|
public void add(PeerState peer) {
|
||||||
_expirePeers.add(peer);
|
_expirePeers.add(peer);
|
||||||
@ -2414,9 +2416,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
public void setIsAlive(boolean isAlive) {
|
public void setIsAlive(boolean isAlive) {
|
||||||
_alive = isAlive;
|
_alive = isAlive;
|
||||||
if (isAlive) {
|
if (isAlive) {
|
||||||
SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
|
reschedule(30*1000);
|
||||||
} else {
|
} else {
|
||||||
SimpleTimer.getInstance().removeEvent(ExpirePeerEvent.this);
|
cancel();
|
||||||
_expirePeers.clear();
|
_expirePeers.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2515,12 +2517,16 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
//return ( (val != null) && ("true".equals(val)) );
|
//return ( (val != null) && ("true".equals(val)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PeerTestEvent implements SimpleTimer.TimedEvent {
|
private class PeerTestEvent extends SimpleTimer2.TimedEvent {
|
||||||
private volatile boolean _alive;
|
private volatile boolean _alive;
|
||||||
/** when did we last test our reachability */
|
/** when did we last test our reachability */
|
||||||
private long _lastTested;
|
private long _lastTested;
|
||||||
private boolean _forceRun;
|
private boolean _forceRun;
|
||||||
|
|
||||||
|
PeerTestEvent() {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
|
}
|
||||||
|
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
if (shouldTest()) {
|
if (shouldTest()) {
|
||||||
long now = _context.clock().now();
|
long now = _context.clock().now();
|
||||||
@ -2532,7 +2538,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
long delay = (TEST_FREQUENCY / 2) + _context.random().nextInt(TEST_FREQUENCY);
|
long delay = (TEST_FREQUENCY / 2) + _context.random().nextInt(TEST_FREQUENCY);
|
||||||
if (delay <= 0)
|
if (delay <= 0)
|
||||||
throw new RuntimeException("wtf, delay is " + delay);
|
throw new RuntimeException("wtf, delay is " + delay);
|
||||||
SimpleTimer.getInstance().addEvent(PeerTestEvent.this, delay);
|
schedule(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2558,9 +2564,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
_alive = isAlive;
|
_alive = isAlive;
|
||||||
if (isAlive) {
|
if (isAlive) {
|
||||||
long delay = _context.random().nextInt(2*TEST_FREQUENCY);
|
long delay = _context.random().nextInt(2*TEST_FREQUENCY);
|
||||||
SimpleTimer.getInstance().addEvent(PeerTestEvent.this, delay);
|
reschedule(delay);
|
||||||
} else {
|
} else {
|
||||||
SimpleTimer.getInstance().removeEvent(PeerTestEvent.this);
|
cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import net.i2p.util.ByteCache;
|
|||||||
import net.i2p.util.HexDump;
|
import net.i2p.util.HexDump;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleByteCache;
|
import net.i2p.util.SimpleByteCache;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle fragments at the endpoint of a tunnel, peeling off fully completed
|
* Handle fragments at the endpoint of a tunnel, peeling off fully completed
|
||||||
@ -369,7 +369,7 @@ class FragmentHandler {
|
|||||||
_fragmentedMessages.remove(Long.valueOf(messageId));
|
_fragmentedMessages.remove(Long.valueOf(messageId));
|
||||||
}
|
}
|
||||||
if (msg.getExpireEvent() != null)
|
if (msg.getExpireEvent() != null)
|
||||||
SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
|
msg.getExpireEvent().cancel();
|
||||||
receiveComplete(msg);
|
receiveComplete(msg);
|
||||||
} else {
|
} else {
|
||||||
noteReception(msg.getMessageId(), 0, msg);
|
noteReception(msg.getMessageId(), 0, msg);
|
||||||
@ -378,7 +378,7 @@ class FragmentHandler {
|
|||||||
msg.setExpireEvent(evt);
|
msg.setExpireEvent(evt);
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + messageId);
|
_log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + messageId);
|
||||||
SimpleTimer.getInstance().addEvent(evt, MAX_DEFRAGMENT_TIME);
|
evt.schedule(MAX_DEFRAGMENT_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,7 +437,7 @@ class FragmentHandler {
|
|||||||
_fragmentedMessages.remove(Long.valueOf(messageId));
|
_fragmentedMessages.remove(Long.valueOf(messageId));
|
||||||
}
|
}
|
||||||
if (msg.getExpireEvent() != null)
|
if (msg.getExpireEvent() != null)
|
||||||
SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
|
msg.getExpireEvent().cancel();
|
||||||
_context.statManager().addRateData("tunnel.fragmentedComplete", msg.getFragmentCount(), msg.getLifetime());
|
_context.statManager().addRateData("tunnel.fragmentedComplete", msg.getFragmentCount(), msg.getLifetime());
|
||||||
receiveComplete(msg);
|
receiveComplete(msg);
|
||||||
} else {
|
} else {
|
||||||
@ -447,7 +447,7 @@ class FragmentHandler {
|
|||||||
msg.setExpireEvent(evt);
|
msg.setExpireEvent(evt);
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + msg.getMessageId() + "/" + fragmentNum);
|
_log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + msg.getMessageId() + "/" + fragmentNum);
|
||||||
SimpleTimer.getInstance().addEvent(evt, MAX_DEFRAGMENT_TIME);
|
evt.schedule(MAX_DEFRAGMENT_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,10 +548,11 @@ class FragmentHandler {
|
|||||||
public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel);
|
public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RemoveFailed implements SimpleTimer.TimedEvent {
|
private class RemoveFailed extends SimpleTimer2.TimedEvent {
|
||||||
private final FragmentedMessage _msg;
|
private final FragmentedMessage _msg;
|
||||||
|
|
||||||
public RemoveFailed(FragmentedMessage msg) {
|
public RemoveFailed(FragmentedMessage msg) {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
_msg = msg;
|
_msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import net.i2p.data.Hash;
|
|||||||
import net.i2p.data.TunnelId;
|
import net.i2p.data.TunnelId;
|
||||||
import net.i2p.util.ByteCache;
|
import net.i2p.util.ByteCache;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather fragments of I2NPMessages at a tunnel endpoint, making them available
|
* Gather fragments of I2NPMessages at a tunnel endpoint, making them available
|
||||||
@ -28,7 +28,7 @@ class FragmentedMessage {
|
|||||||
private final long _createdOn;
|
private final long _createdOn;
|
||||||
private boolean _completed;
|
private boolean _completed;
|
||||||
private long _releasedAfter;
|
private long _releasedAfter;
|
||||||
private SimpleTimer.TimedEvent _expireEvent;
|
private SimpleTimer2.TimedEvent _expireEvent;
|
||||||
|
|
||||||
private static final ByteCache _cache = ByteCache.getInstance(512, TrivialPreprocessor.PREPROCESSED_SIZE);
|
private static final ByteCache _cache = ByteCache.getInstance(512, TrivialPreprocessor.PREPROCESSED_SIZE);
|
||||||
// 64 is pretty absurd, 32 is too, most likely
|
// 64 is pretty absurd, 32 is too, most likely
|
||||||
@ -160,9 +160,11 @@ class FragmentedMessage {
|
|||||||
found++;
|
found++;
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** used in the fragment handler so we can cancel the expire event on success */
|
/** used in the fragment handler so we can cancel the expire event on success */
|
||||||
SimpleTimer.TimedEvent getExpireEvent() { return _expireEvent; }
|
public SimpleTimer2.TimedEvent getExpireEvent() { return _expireEvent; }
|
||||||
void setExpireEvent(SimpleTimer.TimedEvent evt) { _expireEvent = evt; }
|
|
||||||
|
public void setExpireEvent(SimpleTimer2.TimedEvent evt) { _expireEvent = evt; }
|
||||||
|
|
||||||
/** have we received all of the fragments? */
|
/** have we received all of the fragments? */
|
||||||
public boolean isComplete() {
|
public boolean isComplete() {
|
||||||
|
@ -10,7 +10,7 @@ import net.i2p.data.i2np.TunnelGatewayMessage;
|
|||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serve as the gatekeeper for a tunnel, accepting messages, coallescing and/or
|
* Serve as the gatekeeper for a tunnel, accepting messages, coallescing and/or
|
||||||
@ -124,7 +124,7 @@ class TunnelGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (delayedFlush) {
|
if (delayedFlush) {
|
||||||
_context.simpleTimer().addEvent(_delayedFlush, delayAmount);
|
_delayedFlush.reschedule(delayAmount);
|
||||||
}
|
}
|
||||||
_context.statManager().addRateData("tunnel.lockedGatewayAdd", afterAdded-beforeLock, remaining);
|
_context.statManager().addRateData("tunnel.lockedGatewayAdd", afterAdded-beforeLock, remaining);
|
||||||
if (_log.shouldLog(Log.DEBUG)) {
|
if (_log.shouldLog(Log.DEBUG)) {
|
||||||
@ -278,7 +278,11 @@ class TunnelGateway {
|
|||||||
public long getLifetime() { return _context.clock().now()-_created; }
|
public long getLifetime() { return _context.clock().now()-_created; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DelayedFlush implements SimpleTimer.TimedEvent {
|
protected class DelayedFlush extends SimpleTimer2.TimedEvent {
|
||||||
|
DelayedFlush() {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
|
}
|
||||||
|
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
boolean wantRequeue = false;
|
boolean wantRequeue = false;
|
||||||
int remaining = 0;
|
int remaining = 0;
|
||||||
@ -304,7 +308,7 @@ class TunnelGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wantRequeue)
|
if (wantRequeue)
|
||||||
_context.simpleTimer().addEvent(_delayedFlush, delayAmount);
|
schedule(delayAmount);
|
||||||
else
|
else
|
||||||
_lastFlush = _context.clock().now();
|
_lastFlush = _context.clock().now();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer2;
|
||||||
|
|
||||||
import org.xlattice.crypto.filters.BloomSHA1;
|
import org.xlattice.crypto.filters.BloomSHA1;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public class DecayingBloomFilter {
|
|||||||
private final long _longToEntryMask;
|
private final long _longToEntryMask;
|
||||||
protected long _currentDuplicates;
|
protected long _currentDuplicates;
|
||||||
protected volatile boolean _keepDecaying;
|
protected volatile boolean _keepDecaying;
|
||||||
protected final SimpleTimer.TimedEvent _decayEvent;
|
protected final SimpleTimer2.TimedEvent _decayEvent;
|
||||||
/** just for logging */
|
/** just for logging */
|
||||||
protected final String _name;
|
protected final String _name;
|
||||||
/** synchronize against this lock when switching double buffers */
|
/** synchronize against this lock when switching double buffers */
|
||||||
@ -64,7 +64,7 @@ public class DecayingBloomFilter {
|
|||||||
context.addShutdownTask(new Shutdown());
|
context.addShutdownTask(new Shutdown());
|
||||||
_decayEvent = new DecayEvent();
|
_decayEvent = new DecayEvent();
|
||||||
_keepDecaying = true;
|
_keepDecaying = true;
|
||||||
SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
|
_decayEvent.schedule(_durationMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +118,7 @@ public class DecayingBloomFilter {
|
|||||||
}
|
}
|
||||||
_decayEvent = new DecayEvent();
|
_decayEvent = new DecayEvent();
|
||||||
_keepDecaying = true;
|
_keepDecaying = true;
|
||||||
SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
|
_decayEvent.schedule(_durationMs);
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("New DBF " + name + " m = " + m + " k = " + k + " entryBytes = " + entryBytes +
|
_log.warn("New DBF " + name + " m = " + m + " k = " + k + " entryBytes = " + entryBytes +
|
||||||
" numExtenders = " + numExtenders + " cycle (s) = " + (durationMs / 1000));
|
" numExtenders = " + numExtenders + " cycle (s) = " + (durationMs / 1000));
|
||||||
@ -274,7 +274,7 @@ public class DecayingBloomFilter {
|
|||||||
|
|
||||||
public void stopDecaying() {
|
public void stopDecaying() {
|
||||||
_keepDecaying = false;
|
_keepDecaying = false;
|
||||||
SimpleTimer.getInstance().removeEvent(_decayEvent);
|
_decayEvent.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void decay() {
|
protected void decay() {
|
||||||
@ -310,11 +310,15 @@ public class DecayingBloomFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DecayEvent implements SimpleTimer.TimedEvent {
|
private class DecayEvent extends SimpleTimer2.TimedEvent {
|
||||||
|
DecayEvent() {
|
||||||
|
super(_context.simpleTimer2());
|
||||||
|
}
|
||||||
|
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
if (_keepDecaying) {
|
if (_keepDecaying) {
|
||||||
decay();
|
decay();
|
||||||
SimpleTimer.getInstance().addEvent(DecayEvent.this, _durationMs);
|
schedule(_durationMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user