forked from I2P_Developers/i2p.i2p
GeoIP: Thread the periodic lookup so it doesn't clog the timer queue
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user