forked from I2P_Developers/i2p.i2p
- Implement destroy() in addressbook to prevent dups
This commit is contained in:
@@ -39,6 +39,7 @@ import net.i2p.I2PAppContext;
|
|||||||
public class Daemon {
|
public class Daemon {
|
||||||
public static final String VERSION = "2.0.3";
|
public static final String VERSION = "2.0.3";
|
||||||
private static final Daemon _instance = new Daemon();
|
private static final Daemon _instance = new Daemon();
|
||||||
|
private boolean _running;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the router and published address books using remote data from the
|
* Update the router and published address books using remote data from the
|
||||||
@@ -126,6 +127,7 @@ public class Daemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run(String[] args) {
|
public void run(String[] args) {
|
||||||
|
_running = true;
|
||||||
String settingsLocation = "config.txt";
|
String settingsLocation = "config.txt";
|
||||||
File homeFile;
|
File homeFile;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
@@ -166,7 +168,7 @@ public class Daemon {
|
|||||||
// Static method, and redundent Thread.currentThread().sleep(5*60*1000);
|
// Static method, and redundent Thread.currentThread().sleep(5*60*1000);
|
||||||
} catch (InterruptedException ie) {}
|
} catch (InterruptedException ie) {}
|
||||||
|
|
||||||
while (true) {
|
while (_running) {
|
||||||
long delay = Long.parseLong((String) settings.get("update_delay"));
|
long delay = Long.parseLong((String) settings.get("update_delay"));
|
||||||
if (delay < 1) {
|
if (delay < 1) {
|
||||||
delay = 1;
|
delay = 1;
|
||||||
@@ -179,6 +181,8 @@ public class Daemon {
|
|||||||
}
|
}
|
||||||
} catch (InterruptedException exp) {
|
} catch (InterruptedException exp) {
|
||||||
}
|
}
|
||||||
|
if (!_running)
|
||||||
|
break;
|
||||||
settings = ConfigParser.parse(settingsFile, defaultSettings);
|
settings = ConfigParser.parse(settingsFile, defaultSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,4 +196,9 @@ public class Daemon {
|
|||||||
_instance.notifyAll();
|
_instance.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void stop() {
|
||||||
|
_instance._running = false;
|
||||||
|
wakeup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,4 +51,9 @@ public class DaemonThread extends Thread {
|
|||||||
//}
|
//}
|
||||||
Daemon.main(this.args);
|
Daemon.main(this.args);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void halt() {
|
||||||
|
Daemon.stop();
|
||||||
|
interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Servlet extends HttpServlet {
|
public class Servlet extends HttpServlet {
|
||||||
private Thread thread;
|
private DaemonThread thread;
|
||||||
private String nonce;
|
private String nonce;
|
||||||
private static final String PROP_NONCE = "addressbook.nonce";
|
private static final String PROP_NONCE = "addressbook.nonce";
|
||||||
|
|
||||||
@@ -88,4 +88,9 @@ public class Servlet extends HttpServlet {
|
|||||||
//System.out.println("INFO: config root under " + args[0]);
|
//System.out.println("INFO: config root under " + args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
this.thread.halt();
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user