replace SimpleScheduler.getInstance() calls

This commit is contained in:
zzz
2012-08-03 17:13:17 +00:00
parent 00f9fea98c
commit b4a50ed03a
26 changed files with 60 additions and 44 deletions

View File

@ -67,7 +67,7 @@ public class ConnectionAcceptor implements Runnable
thread = new I2PAppThread(this, "I2PSnark acceptor");
thread.setDaemon(true);
thread.start();
SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), BAD_CLEAN_INTERVAL);
_util.getContext().simpleScheduler().addPeriodicEvent(new Cleaner(), BAD_CLEAN_INTERVAL);
}
}
}
@ -82,7 +82,7 @@ public class ConnectionAcceptor implements Runnable
thread = new I2PAppThread(this, "I2PSnark acceptor");
thread.setDaemon(true);
thread.start();
SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), BAD_CLEAN_INTERVAL);
_util.getContext().simpleScheduler().addPeriodicEvent(new Cleaner(), BAD_CLEAN_INTERVAL);
}
public void halt()

View File

@ -309,7 +309,7 @@ public class I2PSnarkUtil {
return rv;
} catch (I2PException ie) {
_shitlist.add(dest);
SimpleScheduler.getInstance().addEvent(new Unshitlist(dest), 10*60*1000);
_context.simpleScheduler().addEvent(new Unshitlist(dest), 10*60*1000);
throw new IOException("Unable to reach the peer " + peer + ": " + ie.getMessage());
}
}

View File

@ -1710,7 +1710,7 @@ public class SnarkManager implements Snark.CompleteListener {
if (count > 0) {
// Schedule this even for final shutdown, as there's a chance
// that it's just this webapp that is stopping.
SimpleScheduler.getInstance().addEvent(new Disconnector(), 60*1000);
_context.simpleScheduler().addEvent(new Disconnector(), 60*1000);
addMessage(_("Closing I2P tunnel after notifying trackers."));
if (finalShutdown) {
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}

View File

@ -123,7 +123,7 @@ public class PluginUpdateChecker extends UpdateHandler {
}
private void scheduleStatusClean(String msg) {
SimpleScheduler.getInstance().addEvent(new Cleaner(msg), 20*60*1000);
_context.simpleScheduler().addEvent(new Cleaner(msg), 20*60*1000);
}
private class Cleaner implements SimpleTimer.TimedEvent {

View File

@ -98,7 +98,7 @@ public class PluginUpdateHandler extends UpdateHandler {
}
private void scheduleStatusClean(String msg) {
SimpleScheduler.getInstance().addEvent(new Cleaner(msg), 20*60*1000);
_context.simpleScheduler().addEvent(new Cleaner(msg), 20*60*1000);
}
private class Cleaner implements SimpleTimer.TimedEvent {

View File

@ -279,7 +279,7 @@ class Connection {
void sendReset() {
if (_disconnectScheduledOn < 0) {
_disconnectScheduledOn = _context.clock().now();
SimpleScheduler.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
_context.simpleScheduler().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
}
long now = _context.clock().now();
if (_resetSentOn + 10*1000 > now) return; // don't send resets too fast
@ -534,7 +534,7 @@ class Connection {
void resetReceived() {
if (_disconnectScheduledOn < 0) {
_disconnectScheduledOn = _context.clock().now();
SimpleScheduler.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
_context.simpleScheduler().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
}
_resetReceived = true;
_outputStream.streamErrorOccurred(new IOException("Reset received"));
@ -578,7 +578,7 @@ class Connection {
if (removeFromConMgr) {
if (_disconnectScheduledOn < 0) {
_disconnectScheduledOn = _context.clock().now();
SimpleScheduler.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
_context.simpleScheduler().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
}
}
_connected = false;
@ -796,7 +796,7 @@ class Connection {
_closeSentOn = when;
if (_disconnectScheduledOn < 0) {
_disconnectScheduledOn = _context.clock().now();
SimpleScheduler.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
_context.simpleScheduler().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
}
}
public long getCloseReceivedOn() { return _closeReceivedOn; }

View File

@ -78,7 +78,7 @@ class ConnectionHandler {
// also check if expiration of the head is long past for overload detection with peek() ?
boolean success = _synQueue.offer(packet); // fail immediately if full
if (success) {
SimpleScheduler.getInstance().addEvent(new TimeoutSyn(packet), _acceptTimeout);
_context.simpleScheduler().addEvent(new TimeoutSyn(packet), _acceptTimeout);
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Dropping new SYN request, as the queue is full");

View File

@ -184,7 +184,7 @@ class ConnectionPacketHandler {
// take note of congestion
if (_log.shouldLog(Log.WARN))
_log.warn("congestion.. dup " + packet);
SimpleScheduler.getInstance().addEvent(new AckDup(con), con.getOptions().getSendAckDelay());
_context.simpleScheduler().addEvent(new AckDup(con), con.getOptions().getSendAckDelay());
//con.setNextSendTime(_context.clock().now() + con.getOptions().getSendAckDelay());
//fastAck = true;
} else {

View File

@ -17,7 +17,7 @@ abstract class SchedulerImpl implements TaskScheduler {
}
protected void reschedule(long msToWait, Connection con) {
SimpleScheduler.getInstance().addEvent(con.getConnectionEvent(), msToWait);
_context.simpleScheduler().addEvent(con.getConnectionEvent(), msToWait);
}
@Override

View File

@ -477,7 +477,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
* @since 0.9.1
*/
private void startVerifyUsage() {
SimpleScheduler.getInstance().addEvent(new VerifyUsage(), VERIFY_USAGE_TIME);
_context.simpleScheduler().addEvent(new VerifyUsage(), VERIFY_USAGE_TIME);
}
/**
@ -501,7 +501,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
toCheck.clear();
}
toCheck.addAll(_availableMessages.keySet());
SimpleScheduler.getInstance().addEvent(this, VERIFY_USAGE_TIME);
_context.simpleScheduler().addEvent(this, VERIFY_USAGE_TIME);
}
}
@ -967,7 +967,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
boolean close = Boolean.valueOf(_options.getProperty("i2cp.closeOnIdle")).booleanValue();
if (reduce || close) {
updateActivity();
SimpleScheduler.getInstance().addEvent(new SessionIdleTimer(_context, this, reduce, close), SessionIdleTimer.MINIMUM_TIME);
_context.simpleScheduler().addEvent(new SessionIdleTimer(_context, this, reduce, close), SessionIdleTimer.MINIMUM_TIME);
}
}

View File

@ -112,6 +112,6 @@ class SessionIdleTimer implements SimpleTimer.TimedEvent {
} else {
nextDelay = _minimumTime - (now - lastActivity);
}
SimpleScheduler.getInstance().addEvent(this, nextDelay);
_context.simpleScheduler().addEvent(this, nextDelay);
}
}

View File

@ -181,7 +181,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
context.statManager().createRateStat("crypto.sessionTagsExpired", "How many tags/sessions are expired?", "Encryption", new long[] { 10*60*1000, 60*60*1000, 3*60*60*1000 });
context.statManager().createRateStat("crypto.sessionTagsRemaining", "How many tags/sessions are remaining after a cleanup?", "Encryption", new long[] { 10*60*1000, 60*60*1000, 3*60*60*1000 });
_alive = true;
SimpleScheduler.getInstance().addEvent(new CleanupEvent(), 60*1000);
_context.simpleScheduler().addEvent(new CleanupEvent(), 60*1000);
}
@Override
@ -203,7 +203,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
int expired = aggressiveExpire();
long expireTime = _context.clock().now() - beforeExpire;
_context.statManager().addRateData("crypto.sessionTagsExpired", expired, expireTime);
SimpleScheduler.getInstance().addEvent(this, 60*1000);
_context.simpleScheduler().addEvent(this, 60*1000);
}
}

View File

@ -146,7 +146,7 @@ public class SimpleScheduler {
* Same as SimpleTimer.TimedEvent but use run() instead of timeReached(), and remembers the time
*/
private class RunnableEvent implements Runnable {
protected SimpleTimer.TimedEvent _timedEvent;
protected final SimpleTimer.TimedEvent _timedEvent;
protected long _scheduled;
public RunnableEvent(SimpleTimer.TimedEvent t, long timeoutMs) {

View File

@ -1,3 +1,19 @@
2012-08-03 zzz
* build.xml: Add buildI2PTunnelJar target for Android
* i2psnark: Finish migration to I2P logging to reduce object churn (ticket #673)
* LogManager: Add logger.logBufferSize and logger.dropOnOverflow options (ticket #662)
* JobQueue: Synch fix (ticket #670)
* OutNetMessage: Fix NPE when log level = INFO (ticket #676)
* SimpleScheduler, SimpleTimer2: Replace getInstance() calls
* UDP:
- Catch some cases where UDPPackets were not returned to the cache (ticket #675)
- Fix inverted logging logic (ticket #663)
- Remove check in UDPPacket.getLifetime() (ticket #664)
- RemoteHostID cleanup, cache hashcode
- Remove udp.fetchRemoteSlow stat
- Remove some time stamping in UDPPacket
- Other cleanups - see http://zzz.i2p/topics/1198
2012-07-30 zzz
* build.xml: Move more default properties to build.properties
* DecayingBloomFilter, DecayingHashSet, xlattice filters:

View File

@ -431,7 +431,7 @@ public class Router implements RouterClock.ClockShiftListener {
_context.inNetMessagePool().startup();
startupQueue();
//_context.jobQueue().addJob(new CoalesceStatsJob(_context));
SimpleScheduler.getInstance().addPeriodicEvent(new CoalesceStatsEvent(_context), COALESCE_TIME);
_context.simpleScheduler().addPeriodicEvent(new CoalesceStatsEvent(_context), COALESCE_TIME);
_context.jobQueue().addJob(new UpdateRoutingKeyModifierJob(_context));
warmupCrypto();
//_sessionKeyPersistenceHelper.startup();
@ -538,7 +538,7 @@ public class Router implements RouterClock.ClockShiftListener {
if (blockingRebuild)
r.timeReached();
else
SimpleScheduler.getInstance().addEvent(r, 0);
_context.simpleScheduler().addEvent(r, 0);
} catch (DataFormatException dfe) {
_log.log(Log.CRIT, "Internal error - unable to sign our own address?!", dfe);
}
@ -1348,7 +1348,7 @@ public class Router implements RouterClock.ClockShiftListener {
*/
private void beginMarkingLiveliness() {
File f = getPingFile();
SimpleScheduler.getInstance().addPeriodicEvent(new MarkLiveliness(this, f), 0, LIVELINESS_DELAY - (5*1000));
_context.simpleScheduler().addPeriodicEvent(new MarkLiveliness(this, f), 0, LIVELINESS_DELAY - (5*1000));
}
public static final String PROP_BANDWIDTH_SHARE_PERCENTAGE = "router.sharePercentage";

View File

@ -45,7 +45,7 @@ class RouterThrottleImpl implements RouterThrottle {
_context = context;
_log = context.logManager().getLog(RouterThrottleImpl.class);
setTunnelStatus();
SimpleScheduler.getInstance().addEvent(new ResetStatus(), REJECT_STARTUP_TIME + 120*1000);
_context.simpleScheduler().addEvent(new ResetStatus(), REJECT_STARTUP_TIME + 120*1000);
_context.statManager().createRateStat("router.throttleNetworkCause", "How lagged the jobQueue was when an I2NP was throttled", "Throttle", new long[] { 60*1000, 10*60*1000, 60*60*1000, 24*60*60*1000 });
//_context.statManager().createRateStat("router.throttleNetDbCause", "How lagged the jobQueue was when a networkDb request was throttled", "Throttle", new long[] { 60*1000, 10*60*1000, 60*60*1000, 24*60*60*1000 });
//_context.statManager().createRateStat("router.throttleTunnelCause", "How lagged the jobQueue was when a tunnel request was throttled", "Throttle", new long[] { 60*1000, 10*60*1000, 60*60*1000, 24*60*60*1000 });

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 1;
public final static long BUILD = 2;
/** for example "-test" */
public final static String EXTRA = "";

View File

@ -446,7 +446,7 @@ class ClientConnectionRunner {
// theirs is newer
} else {
// ours is newer, so wait a few secs and retry
SimpleScheduler.getInstance().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
_context.simpleScheduler().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
}
// fire onCreated?
return; // already requesting

View File

@ -102,7 +102,7 @@ public class OutboundCache {
public OutboundCache(RouterContext ctx) {
_context = ctx;
SimpleScheduler.getInstance().addPeriodicEvent(new OCMOSJCacheCleaner(), CLEAN_INTERVAL, CLEAN_INTERVAL);
_context.simpleScheduler().addPeriodicEvent(new OCMOSJCacheCleaner(), CLEAN_INTERVAL, CLEAN_INTERVAL);
}
/**

View File

@ -416,7 +416,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
private static final int LOOKUP_TIME = 30*60*1000;
private void startGeoIP() {
_geoIP = new GeoIP(_context);
SimpleScheduler.getInstance().addEvent(new QueueAll(), START_DELAY);
_context.simpleScheduler().addEvent(new QueueAll(), START_DELAY);
}
/**
@ -434,7 +434,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
continue;
_geoIP.add(host);
}
SimpleScheduler.getInstance().addPeriodicEvent(new Lookup(), 5000, LOOKUP_TIME);
_context.simpleScheduler().addPeriodicEvent(new Lookup(), 5000, LOOKUP_TIME);
}
}
@ -556,7 +556,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
private static final int TIME_REPEAT_DELAY = 10*60*1000;
/** @since 0.7.12 */
private void startTimestamper() {
SimpleScheduler.getInstance().addPeriodicEvent(new Timestamper(), TIME_START_DELAY, TIME_REPEAT_DELAY);
_context.simpleScheduler().addPeriodicEvent(new Timestamper(), TIME_START_DELAY, TIME_REPEAT_DELAY);
}
/**

View File

@ -74,7 +74,7 @@ public abstract class TransportImpl implements Transport {
_sendPool = new ArrayList(16);
_unreachableEntries = new HashMap(16);
_wasUnreachableEntries = new ConcurrentHashSet(16);
SimpleScheduler.getInstance().addPeriodicEvent(new CleanupUnreachable(), 2 * UNREACHABLE_PERIOD, UNREACHABLE_PERIOD / 2);
_context.simpleScheduler().addPeriodicEvent(new CleanupUnreachable(), 2 * UNREACHABLE_PERIOD, UNREACHABLE_PERIOD / 2);
}
/**

View File

@ -217,7 +217,7 @@ class EstablishmentManager {
// whoops, somebody beat us to it, throw out the state we just created
state = oldState;
else
SimpleScheduler.getInstance().addEvent(new Expire(to, state), 10*1000);
_context.simpleScheduler().addEvent(new Expire(to, state), 10*1000);
}
}
if (state != null) {
@ -465,7 +465,7 @@ class EstablishmentManager {
msg.getTarget().getIdentity(),
new SessionKey(addr.getIntroKey()), addr);
_outboundStates.put(to, qstate);
SimpleScheduler.getInstance().addEvent(new Expire(to, qstate), 10*1000);
_context.simpleScheduler().addEvent(new Expire(to, qstate), 10*1000);
for (int i = 0; i < queued.size(); i++) {
OutNetMessage m = (OutNetMessage)queued.get(i);
@ -544,7 +544,7 @@ class EstablishmentManager {
dsm.setMessageExpiration(_context.clock().now()+10*1000);
dsm.setMessageId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
_transport.send(dsm, peer);
SimpleScheduler.getInstance().addEvent(new PublishToNewInbound(peer), 0);
_context.simpleScheduler().addEvent(new PublishToNewInbound(peer), 0);
}
private class PublishToNewInbound implements SimpleTimer.TimedEvent {
private PeerState _peer;
@ -696,7 +696,7 @@ class EstablishmentManager {
break;
}
}
SimpleScheduler.getInstance().addEvent(new FailIntroduction(state, nonce), INTRO_ATTEMPT_TIMEOUT);
_context.simpleScheduler().addEvent(new FailIntroduction(state, nonce), INTRO_ATTEMPT_TIMEOUT);
state.setIntroNonce(nonce);
_context.statManager().addRateData("udp.sendIntroRelayRequest", 1, 0);
UDPPacket requests[] = _builder.buildRelayRequest(_transport, state, _transport.getIntroKey());

View File

@ -158,7 +158,7 @@ class PeerTestManager {
sendTestToBob();
SimpleScheduler.getInstance().addEvent(new ContinueTest(), RESEND_TIMEOUT);
_context.simpleScheduler().addEvent(new ContinueTest(), RESEND_TIMEOUT);
}
private class ContinueTest implements SimpleTimer.TimedEvent {
@ -183,7 +183,7 @@ class PeerTestManager {
// second message from Charlie yet
sendTestToCharlie();
}
SimpleScheduler.getInstance().addEvent(ContinueTest.this, RESEND_TIMEOUT);
_context.simpleScheduler().addEvent(ContinueTest.this, RESEND_TIMEOUT);
}
}
}
@ -538,7 +538,7 @@ class PeerTestManager {
if (isNew) {
_activeTests.put(Long.valueOf(nonce), state);
SimpleScheduler.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
_context.simpleScheduler().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
}
UDPPacket packet = _packetBuilder.buildPeerTestToBob(bobIP, from.getPort(), aliceIP, alicePort, aliceIntroKey, nonce, state.getBobCipherKey(), state.getBobMACKey());
@ -617,7 +617,7 @@ class PeerTestManager {
if (isNew) {
_activeTests.put(Long.valueOf(nonce), state);
SimpleScheduler.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
_context.simpleScheduler().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
}
UDPPacket packet = _packetBuilder.buildPeerTestToCharlie(aliceIP, from.getPort(), aliceIntroKey, nonce,

View File

@ -228,7 +228,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_context.statManager().createRateStat("udp.dropPeerDroplist", "How many peers currently have their packets dropped outright when a new peer is added to the list?", "udp", RATES);
_context.statManager().createRateStat("udp.dropPeerConsecutiveFailures", "How many consecutive failed sends to a peer did we attempt before giving up and reestablishing a new session (lifetime is inactivity perood)", "udp", RATES);
SimpleScheduler.getInstance().addPeriodicEvent(new PingIntroducers(), MIN_EXPIRE_TIMEOUT * 3 / 4);
_context.simpleScheduler().addPeriodicEvent(new PingIntroducers(), MIN_EXPIRE_TIMEOUT * 3 / 4);
}
public void startup() {
@ -832,7 +832,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
RemoteHostId remote = peer.getRemoteHostId();
_dropList.add(remote);
_context.statManager().addRateData("udp.dropPeerDroplist", 1, 0);
SimpleScheduler.getInstance().addEvent(new RemoveDropList(remote), DROPLIST_PERIOD);
_context.simpleScheduler().addEvent(new RemoveDropList(remote), DROPLIST_PERIOD);
}
markUnreachable(peerHash);
_context.shitlist().shitlistRouter(peerHash, "Part of the wrong network, version = " + ((RouterInfo) entry).getOption("router.version"));

View File

@ -42,7 +42,7 @@ class ParticipatingThrottler {
ParticipatingThrottler(RouterContext ctx) {
this.context = ctx;
this.counter = new ObjectCounter();
SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), CLEAN_TIME);
ctx.simpleScheduler().addPeriodicEvent(new Cleaner(), CLEAN_TIME);
}
/** increments before checking */

View File

@ -435,7 +435,7 @@ public class TunnelPoolManager implements TunnelManagerFacade {
// don't delay the outbound if it already exists, as this opens up a large
// race window with removeTunnels() below
if (delayOutbound)
SimpleScheduler.getInstance().addEvent(new DelayedStartup(outbound), 1000);
_context.simpleScheduler().addEvent(new DelayedStartup(outbound), 1000);
else
outbound.startup();
}
@ -523,7 +523,7 @@ public class TunnelPoolManager implements TunnelManagerFacade {
outboundSettings.setIsExploratory(true);
outboundSettings.setIsInbound(false);
_outboundExploratory = new TunnelPool(_context, this, outboundSettings, selector);
SimpleScheduler.getInstance().addEvent(new DelayedStartup(_outboundExploratory), 3*1000);
_context.simpleScheduler().addEvent(new DelayedStartup(_outboundExploratory), 3*1000);
// try to build up longer tunnels
_context.jobQueue().addJob(new BootstrapPool(_context, _inboundExploratory));