From e31c0636aba2fe8ab410470d52170eab4aac159e Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 29 Mar 2010 21:13:45 +0000 Subject: [PATCH] - Implement destroy() in addressbook to prevent dups --- .../java/src/net/i2p/addressbook/Daemon.java | 11 ++++++++++- .../java/src/net/i2p/addressbook/DaemonThread.java | 7 ++++++- .../java/src/net/i2p/addressbook/Servlet.java | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java index 34b550df67..077acdb7f0 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java @@ -39,6 +39,7 @@ import net.i2p.I2PAppContext; public class Daemon { public static final String VERSION = "2.0.3"; private static final Daemon _instance = new Daemon(); + private boolean _running; /** * Update the router and published address books using remote data from the @@ -126,6 +127,7 @@ public class Daemon { } public void run(String[] args) { + _running = true; String settingsLocation = "config.txt"; File homeFile; if (args.length > 0) { @@ -166,7 +168,7 @@ public class Daemon { // Static method, and redundent Thread.currentThread().sleep(5*60*1000); } catch (InterruptedException ie) {} - while (true) { + while (_running) { long delay = Long.parseLong((String) settings.get("update_delay")); if (delay < 1) { delay = 1; @@ -179,6 +181,8 @@ public class Daemon { } } catch (InterruptedException exp) { } + if (!_running) + break; settings = ConfigParser.parse(settingsFile, defaultSettings); } } @@ -192,4 +196,9 @@ public class Daemon { _instance.notifyAll(); } } + + public static void stop() { + _instance._running = false; + wakeup(); + } } diff --git a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java index b5afaaa2f5..7c9e65994f 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java @@ -51,4 +51,9 @@ public class DaemonThread extends Thread { //} Daemon.main(this.args); } -} \ No newline at end of file + + public void halt() { + Daemon.stop(); + interrupt(); + } +} diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java index fceecfe539..beb225ca0d 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java @@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletResponse; * */ public class Servlet extends HttpServlet { - private Thread thread; + private DaemonThread thread; private String 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]); } + @Override + public void destroy() { + this.thread.halt(); + super.destroy(); + } } -- GitLab