forked from I2P_Developers/i2p.i2p
SimpleTimer (ticket #653):
- Move all remaining uses to SimpleTimer2 - Deprecate
This commit is contained in:
@ -25,7 +25,7 @@ import net.i2p.router.ReplyJob;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
|
||||
/**
|
||||
* Tracks outbound messages.
|
||||
@ -254,10 +254,11 @@ public class OutboundMessageRegistry {
|
||||
/** @deprecated unused */
|
||||
public void renderStatusHTML(Writer out) throws IOException {}
|
||||
|
||||
private class CleanupTask implements SimpleTimer.TimedEvent {
|
||||
private class CleanupTask extends SimpleTimer2.TimedEvent {
|
||||
private long _nextExpire;
|
||||
|
||||
public CleanupTask() {
|
||||
super(_context.simpleTimer2());
|
||||
_nextExpire = -1;
|
||||
}
|
||||
|
||||
@ -312,14 +313,14 @@ public class OutboundMessageRegistry {
|
||||
|
||||
if (_nextExpire <= now)
|
||||
_nextExpire = now + 10*1000;
|
||||
SimpleTimer.getInstance().addEvent(CleanupTask.this, _nextExpire - now);
|
||||
schedule(_nextExpire - now);
|
||||
}
|
||||
|
||||
public void scheduleExpiration(MessageSelector sel) {
|
||||
long now = _context.clock().now();
|
||||
if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
|
||||
_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.SimpleScheduler;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
/**
|
||||
@ -369,7 +370,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
// _flooder.startup();
|
||||
_expireEvent.setIsAlive(true);
|
||||
_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() {
|
||||
@ -681,7 +682,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_context.router().rebuildRouterInfo();
|
||||
}
|
||||
_testEvent.forceRun();
|
||||
SimpleTimer.getInstance().addEvent(_testEvent, 5*1000);
|
||||
_testEvent.reschedule(5*1000);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@ -859,7 +860,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
if (getReachabilityStatus() != CommSystemFacade.STATUS_OK) {
|
||||
_testEvent.forceRun();
|
||||
SimpleTimer.getInstance().addEvent(_testEvent, 0);
|
||||
_testEvent.reschedule(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -933,7 +934,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
|
||||
private class RemoveDropList implements SimpleTimer.TimedEvent {
|
||||
private RemoteHostId _peer;
|
||||
private final RemoteHostId _peer;
|
||||
public RemoveDropList(RemoteHostId peer) { _peer = peer; }
|
||||
public void timeReached() {
|
||||
_dropList.remove(_peer);
|
||||
@ -2361,12 +2362,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
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 List<PeerState> _expireBuffer;
|
||||
private volatile boolean _alive;
|
||||
|
||||
public ExpirePeerEvent() {
|
||||
super(_context.simpleTimer2());
|
||||
_expirePeers = new ConcurrentHashSet(128);
|
||||
_expireBuffer = new ArrayList();
|
||||
}
|
||||
@ -2403,7 +2405,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_expireBuffer.clear();
|
||||
|
||||
if (_alive)
|
||||
SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
|
||||
schedule(30*1000);
|
||||
}
|
||||
public void add(PeerState peer) {
|
||||
_expirePeers.add(peer);
|
||||
@ -2414,9 +2416,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
public void setIsAlive(boolean isAlive) {
|
||||
_alive = isAlive;
|
||||
if (isAlive) {
|
||||
SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
|
||||
reschedule(30*1000);
|
||||
} else {
|
||||
SimpleTimer.getInstance().removeEvent(ExpirePeerEvent.this);
|
||||
cancel();
|
||||
_expirePeers.clear();
|
||||
}
|
||||
}
|
||||
@ -2515,12 +2517,16 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
//return ( (val != null) && ("true".equals(val)) );
|
||||
}
|
||||
|
||||
private class PeerTestEvent implements SimpleTimer.TimedEvent {
|
||||
private class PeerTestEvent extends SimpleTimer2.TimedEvent {
|
||||
private volatile boolean _alive;
|
||||
/** when did we last test our reachability */
|
||||
private long _lastTested;
|
||||
private boolean _forceRun;
|
||||
|
||||
PeerTestEvent() {
|
||||
super(_context.simpleTimer2());
|
||||
}
|
||||
|
||||
public void timeReached() {
|
||||
if (shouldTest()) {
|
||||
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);
|
||||
if (delay <= 0)
|
||||
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;
|
||||
if (isAlive) {
|
||||
long delay = _context.random().nextInt(2*TEST_FREQUENCY);
|
||||
SimpleTimer.getInstance().addEvent(PeerTestEvent.this, delay);
|
||||
reschedule(delay);
|
||||
} 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.Log;
|
||||
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
|
||||
@ -369,7 +369,7 @@ class FragmentHandler {
|
||||
_fragmentedMessages.remove(Long.valueOf(messageId));
|
||||
}
|
||||
if (msg.getExpireEvent() != null)
|
||||
SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
|
||||
msg.getExpireEvent().cancel();
|
||||
receiveComplete(msg);
|
||||
} else {
|
||||
noteReception(msg.getMessageId(), 0, msg);
|
||||
@ -378,7 +378,7 @@ class FragmentHandler {
|
||||
msg.setExpireEvent(evt);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_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));
|
||||
}
|
||||
if (msg.getExpireEvent() != null)
|
||||
SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
|
||||
msg.getExpireEvent().cancel();
|
||||
_context.statManager().addRateData("tunnel.fragmentedComplete", msg.getFragmentCount(), msg.getLifetime());
|
||||
receiveComplete(msg);
|
||||
} else {
|
||||
@ -447,7 +447,7 @@ class FragmentHandler {
|
||||
msg.setExpireEvent(evt);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_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);
|
||||
}
|
||||
|
||||
private class RemoveFailed implements SimpleTimer.TimedEvent {
|
||||
private class RemoveFailed extends SimpleTimer2.TimedEvent {
|
||||
private final FragmentedMessage _msg;
|
||||
|
||||
public RemoveFailed(FragmentedMessage msg) {
|
||||
super(_context.simpleTimer2());
|
||||
_msg = msg;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import net.i2p.data.Hash;
|
||||
import net.i2p.data.TunnelId;
|
||||
import net.i2p.util.ByteCache;
|
||||
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
|
||||
@ -28,7 +28,7 @@ class FragmentedMessage {
|
||||
private final long _createdOn;
|
||||
private boolean _completed;
|
||||
private long _releasedAfter;
|
||||
private SimpleTimer.TimedEvent _expireEvent;
|
||||
private SimpleTimer2.TimedEvent _expireEvent;
|
||||
|
||||
private static final ByteCache _cache = ByteCache.getInstance(512, TrivialPreprocessor.PREPROCESSED_SIZE);
|
||||
// 64 is pretty absurd, 32 is too, most likely
|
||||
@ -160,9 +160,11 @@ class FragmentedMessage {
|
||||
found++;
|
||||
return found;
|
||||
}
|
||||
|
||||
/** used in the fragment handler so we can cancel the expire event on success */
|
||||
SimpleTimer.TimedEvent getExpireEvent() { return _expireEvent; }
|
||||
void setExpireEvent(SimpleTimer.TimedEvent evt) { _expireEvent = evt; }
|
||||
public SimpleTimer2.TimedEvent getExpireEvent() { return _expireEvent; }
|
||||
|
||||
public void setExpireEvent(SimpleTimer2.TimedEvent evt) { _expireEvent = evt; }
|
||||
|
||||
/** have we received all of the fragments? */
|
||||
public boolean isComplete() {
|
||||
|
@ -10,7 +10,7 @@ import net.i2p.data.i2np.TunnelGatewayMessage;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
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
|
||||
@ -124,7 +124,7 @@ class TunnelGateway {
|
||||
}
|
||||
|
||||
if (delayedFlush) {
|
||||
_context.simpleTimer().addEvent(_delayedFlush, delayAmount);
|
||||
_delayedFlush.reschedule(delayAmount);
|
||||
}
|
||||
_context.statManager().addRateData("tunnel.lockedGatewayAdd", afterAdded-beforeLock, remaining);
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
@ -278,7 +278,11 @@ class TunnelGateway {
|
||||
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() {
|
||||
boolean wantRequeue = false;
|
||||
int remaining = 0;
|
||||
@ -304,7 +308,7 @@ class TunnelGateway {
|
||||
}
|
||||
|
||||
if (wantRequeue)
|
||||
_context.simpleTimer().addEvent(_delayedFlush, delayAmount);
|
||||
schedule(delayAmount);
|
||||
else
|
||||
_lastFlush = _context.clock().now();
|
||||
|
||||
|
@ -7,7 +7,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
|
||||
import org.xlattice.crypto.filters.BloomSHA1;
|
||||
|
||||
@ -38,7 +38,7 @@ public class DecayingBloomFilter {
|
||||
private final long _longToEntryMask;
|
||||
protected long _currentDuplicates;
|
||||
protected volatile boolean _keepDecaying;
|
||||
protected final SimpleTimer.TimedEvent _decayEvent;
|
||||
protected final SimpleTimer2.TimedEvent _decayEvent;
|
||||
/** just for logging */
|
||||
protected final String _name;
|
||||
/** synchronize against this lock when switching double buffers */
|
||||
@ -64,7 +64,7 @@ public class DecayingBloomFilter {
|
||||
context.addShutdownTask(new Shutdown());
|
||||
_decayEvent = new DecayEvent();
|
||||
_keepDecaying = true;
|
||||
SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
|
||||
_decayEvent.schedule(_durationMs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +118,7 @@ public class DecayingBloomFilter {
|
||||
}
|
||||
_decayEvent = new DecayEvent();
|
||||
_keepDecaying = true;
|
||||
SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
|
||||
_decayEvent.schedule(_durationMs);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("New DBF " + name + " m = " + m + " k = " + k + " entryBytes = " + entryBytes +
|
||||
" numExtenders = " + numExtenders + " cycle (s) = " + (durationMs / 1000));
|
||||
@ -274,7 +274,7 @@ public class DecayingBloomFilter {
|
||||
|
||||
public void stopDecaying() {
|
||||
_keepDecaying = false;
|
||||
SimpleTimer.getInstance().removeEvent(_decayEvent);
|
||||
_decayEvent.cancel();
|
||||
}
|
||||
|
||||
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() {
|
||||
if (_keepDecaying) {
|
||||
decay();
|
||||
SimpleTimer.getInstance().addEvent(DecayEvent.this, _durationMs);
|
||||
schedule(_durationMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user