From 434b9fa0d1e5936d619d4f1afa461d1b130f489c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Tue, 26 Nov 2013 16:28:24 +0000 Subject: [PATCH] GeoIP: Thread the periodic lookup so it doesn't clog the timer queue --- .../transport/CommSystemFacadeImpl.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index 88ad248d7a..53053b6d29 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -26,6 +26,7 @@ import net.i2p.router.RouterContext; import net.i2p.router.transport.udp.UDPTransport; import net.i2p.router.util.EventLog; import net.i2p.util.Addresses; +import net.i2p.util.I2PThread; import net.i2p.util.Log; import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer2; @@ -223,6 +224,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade { /* We hope the routerinfos are read in and things have settled down by now, but it's not required to be so */ private static final int START_DELAY = 5*60*1000; private static final int LOOKUP_TIME = 30*60*1000; + private void startGeoIP() { _context.simpleScheduler().addEvent(new QueueAll(), START_DELAY); } @@ -248,7 +250,26 @@ public class CommSystemFacadeImpl extends CommSystemFacade { private class Lookup implements SimpleTimer.TimedEvent { public void timeReached() { + (new LookupThread()).start(); + } + } + + /** + * This takes too long to run on the SimpleTimer2 queue + * @since 0.9.10 + */ + private class LookupThread extends I2PThread { + + public LookupThread() { + super("GeoIP Lookup"); + setDaemon(true); + } + + public void run() { + long start = System.currentTimeMillis(); _geoIP.blockingLookup(); + if (_log.shouldLog(Log.INFO)) + _log.info("GeoIP lookup took " + (System.currentTimeMillis() - start)); } } -- GitLab