- Implement destroy() in addressbook to prevent dups

This commit is contained in:
zzz
2010-03-29 21:13:45 +00:00
parent e9fe80f8e5
commit e31c0636ab
3 changed files with 22 additions and 3 deletions

View File

@@ -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();
}
}

View File

@@ -51,4 +51,9 @@ public class DaemonThread extends Thread {
//}
Daemon.main(this.args);
}
}
public void halt() {
Daemon.stop();
interrupt();
}
}

View File

@@ -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();
}
}