diff --git a/apps/addressbook/build.xml b/apps/addressbook/build.xml index e7f563731..bf4e52713 100644 --- a/apps/addressbook/build.xml +++ b/apps/addressbook/build.xml @@ -1,5 +1,5 @@ - + diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java index 2fb20d2d7..36c9f6c0a 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java @@ -43,13 +43,13 @@ import net.i2p.util.SystemVersion; /** * Main class of addressbook. Performs updates, and runs the main loop. + * As of 0.9.30, package private, run with DaemonThread. * * @author Ragnarok * */ -public class Daemon { +class Daemon { public static final String VERSION = "2.0.4"; - private static final Daemon _instance = new Daemon(); private volatile boolean _running; private static final boolean DEBUG = false; private static final String DEFAULT_SUB = "http://i2p-projekt.i2p/hosts.txt"; @@ -787,14 +787,15 @@ public class Daemon { * others are ignored. */ public static void main(String[] args) { + Daemon daemon = new Daemon(); if (args != null && args.length > 0 && args[0].equals("test")) - _instance.test(args); + daemon.test(args); else - _instance.run(args); + daemon.run(args); } /** @since 0.9.26 */ - private static void test(String[] args) { + public static void test(String[] args) { Properties ctxProps = new Properties(); String PROP_FORCE = "i2p.naming.blockfile.writeInAppContext"; ctxProps.setProperty(PROP_FORCE, "true"); @@ -875,14 +876,14 @@ public class Daemon { * Call this to get the addressbook to reread its config and * refetch its subscriptions. */ - public static void wakeup() { - synchronized (_instance) { - _instance.notifyAll(); + public void wakeup() { + synchronized (this) { + notifyAll(); } } - public static void stop() { - _instance._running = false; + public void stop() { + _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 45a7893dd..a3ef36ce3 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java @@ -36,6 +36,7 @@ import net.i2p.util.I2PAppThread; public class DaemonThread extends I2PAppThread implements NamingServiceUpdater { private final String[] args; + private final Daemon daemon; /** * Construct a DaemonThread with the command line arguments args. @@ -44,6 +45,7 @@ public class DaemonThread extends I2PAppThread implements NamingServiceUpdater { */ public DaemonThread(String[] args) { this.args = args; + daemon = new Daemon(); } /* (non-Javadoc) @@ -56,18 +58,28 @@ public class DaemonThread extends I2PAppThread implements NamingServiceUpdater { //} catch (InterruptedException exp) { //} I2PAppContext.getGlobalContext().namingService().registerUpdater(this); - Daemon.main(this.args); - I2PAppContext.getGlobalContext().namingService().unregisterUpdater(this); + try { + if (args != null && args.length > 0 && args[0].equals("test")) + daemon.test(args); + else + daemon.run(args); + } finally { + I2PAppContext.getGlobalContext().namingService().unregisterUpdater(this); + } } public void halt() { - Daemon.stop(); + daemon.stop(); interrupt(); } /** - * The NamingServiceUpdater interface - * @param options ignored + * The NamingServiceUpdater interface. + * While this may be called directly, the recommended way + * is to call I2PAppContext.namingService().requestUpdate(Properties) + * which will call this. + * + * @param options ignored, may be null * @since 0.8.7 */ public void update(Properties options) {