I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit d99a39e5 authored by zzz's avatar zzz
Browse files

convert to ClientApp interface. Untested.

parent 0b897fdc
No related branches found
No related tags found
No related merge requests found
...@@ -23,10 +23,14 @@ import java.util.concurrent.ThreadFactory; ...@@ -23,10 +23,14 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientAppState;
import static net.i2p.app.ClientAppState.*;
import net.i2p.apps.systray.SysTray; import net.i2p.apps.systray.SysTray;
import net.i2p.data.Base32; import net.i2p.data.Base32;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.router.app.RouterApp;
import net.i2p.util.Addresses; import net.i2p.util.Addresses;
import net.i2p.util.FileUtil; import net.i2p.util.FileUtil;
import net.i2p.util.I2PAppThread; import net.i2p.util.I2PAppThread;
...@@ -61,8 +65,10 @@ import org.mortbay.thread.concurrent.ThreadPool; ...@@ -61,8 +65,10 @@ import org.mortbay.thread.concurrent.ThreadPool;
/** /**
* Start the router console. * Start the router console.
*/ */
public class RouterConsoleRunner { public class RouterConsoleRunner implements RouterApp {
private final RouterContext _context; private final RouterContext _context;
private final ClientAppManager _mgr;
private volatile ClientAppState _state = UNINITIALIZED;
private static Server _server; private static Server _server;
private String _listenPort; private String _listenPort;
private String _listenHost; private String _listenHost;
...@@ -127,7 +133,9 @@ public class RouterConsoleRunner { ...@@ -127,7 +133,9 @@ public class RouterConsoleRunner {
* to both, we can't connect to [::1]:7657 for some reason. * to both, we can't connect to [::1]:7657 for some reason.
* So the wise choice is ::1,127.0.0.1 * So the wise choice is ::1,127.0.0.1
*/ */
public RouterConsoleRunner(String args[]) { public RouterConsoleRunner(RouterContext ctx, ClientAppManager mgr, String args[]) {
_context = ctx;
_mgr = mgr;
if (args.length == 0) { if (args.length == 0) {
// _listenHost and _webAppsDir are defaulted below // _listenHost and _webAppsDir are defaulted below
_listenPort = Integer.toString(DEFAULT_LISTEN_PORT); _listenPort = Integer.toString(DEFAULT_LISTEN_PORT);
...@@ -163,18 +171,61 @@ public class RouterConsoleRunner { ...@@ -163,18 +171,61 @@ public class RouterConsoleRunner {
System.err.println(USAGE); System.err.println(USAGE);
throw new IllegalArgumentException(USAGE); throw new IllegalArgumentException(USAGE);
} }
_state = INITIALIZED;
}
public static void main(String args[]) {
List<RouterContext> contexts = RouterContext.listContexts(); List<RouterContext> contexts = RouterContext.listContexts();
if (contexts == null || contexts.isEmpty()) if (contexts == null || contexts.isEmpty())
throw new IllegalStateException("no router context"); throw new IllegalStateException("no router context");
_context = contexts.get(0); RouterConsoleRunner runner = new RouterConsoleRunner(contexts.get(0), null, args);
runner.startup();
} }
public static void main(String args[]) { /////// ClientApp methods
RouterConsoleRunner runner = new RouterConsoleRunner(args);
startTrayApp(runner._context); /** @since 0.9.4 */
runner.startConsole(); public void startup() {
changeState(STARTING);
startTrayApp(_context);
startConsole();
} }
/** @since 0.9.4 */
public void shutdown(String[] args) {
changeState(STOPPING);
try {
_server.stop();
} catch (Exception ie) {}
PortMapper portMapper = _context.portMapper();
portMapper.unregister(PortMapper.SVC_CONSOLE);
portMapper.unregister(PortMapper.SVC_HTTPS_CONSOLE);
changeState(STOPPED);
}
/** @since 0.9.4 */
public ClientAppState getState() {
return _state;
}
/** @since 0.9.4 */
public String getName() {
return "console";
}
/** @since 0.9.4 */
public String getDisplayName() {
return "Router Console";
}
/////// end ClientApp methods
private synchronized void changeState(ClientAppState state) {
_state = state;
if (_mgr != null)
_mgr.notify(this, state, null, null);
}
/** /**
* SInce _server is now static * SInce _server is now static
* @return may be null or stopped perhaps * @return may be null or stopped perhaps
...@@ -513,9 +564,11 @@ public class RouterConsoleRunner { ...@@ -513,9 +564,11 @@ public class RouterConsoleRunner {
notStarted.add(appName); notStarted.add(appName);
} }
} }
changeState(RUNNING);
} }
} else { } else {
System.err.println("ERROR: Router console did not start, not starting webapps"); System.err.println("ERROR: Router console did not start, not starting webapps");
changeState(START_FAILED);
} }
if (rewrite) if (rewrite)
...@@ -559,7 +612,7 @@ public class RouterConsoleRunner { ...@@ -559,7 +612,7 @@ public class RouterConsoleRunner {
} }
_context.addShutdownTask(new NewsShutdown(fetcher, newsThread)); _context.addShutdownTask(new NewsShutdown(fetcher, newsThread));
// stat summarizer registers its own hook // stat summarizer registers its own hook
_context.addShutdownTask(new ServerShutdown(_context)); _context.addShutdownTask(new ServerShutdown());
ConfigServiceHandler.registerSignalHandler(_context); ConfigServiceHandler.registerSignalHandler(_context);
} }
...@@ -706,20 +759,9 @@ public class RouterConsoleRunner { ...@@ -706,20 +759,9 @@ public class RouterConsoleRunner {
} }
/** @since 0.8.8 */ /** @since 0.8.8 */
private static class ServerShutdown implements Runnable { private class ServerShutdown implements Runnable {
private final I2PAppContext _ctx;
public ServerShutdown(I2PAppContext ctx) {
_ctx = ctx;
}
public void run() { public void run() {
try { shutdown(null);
_server.stop();
} catch (Exception ie) {}
PortMapper portMapper = _ctx.portMapper();
portMapper.unregister(PortMapper.SVC_CONSOLE);
portMapper.unregister(PortMapper.SVC_HTTPS_CONSOLE);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment