diff --git a/router/java/src/net/i2p/router/JobQueueRunner.java b/router/java/src/net/i2p/router/JobQueueRunner.java index f5ea41a329c0d119ab24502c6dc57b4fbe235795..e75ef3b0d0b4dd262cbfb44b4d3888841f4cda6f 100644 --- a/router/java/src/net/i2p/router/JobQueueRunner.java +++ b/router/java/src/net/i2p/router/JobQueueRunner.java @@ -109,7 +109,7 @@ class JobQueueRunner implements Runnable { if (_log.shouldLog(Log.CRIT)) _log.log(Log.CRIT, "Router ran out of memory, shutting down", oom); _log.log(Log.CRIT, _currentJob.getClass().getName()); - _context.router().shutdown(); + _context.router().shutdown(Router.EXIT_OOM); } catch (Throwable t) { System.err.println("***Router ran out of memory, shutting down hard"); } diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 17c02cde5c83182b1ad9fd9273b329643fa84b43..345b935d5b0ad0b24426bb663bb92c69a0740ca6 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -106,7 +106,7 @@ public class Router { // gobble } } - shutdown(); + shutdown(EXIT_OOM); } }; _shutdownHook = new ShutdownHook(); @@ -534,7 +534,11 @@ public class Router { buf.setLength(0); } - public void shutdown() { + public static final int EXIT_GRACEFUL = 2; + public static final int EXIT_HARD = 3; + public static final int EXIT_OOM = 10; + + public void shutdown(int exitCode) { _isAlive = false; I2PThread.removeOOMEventListener(_oomListener); try { _context.jobQueue().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the job queue", t); } @@ -550,11 +554,11 @@ public class Router { try { _sessionKeyPersistenceHelper.shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); } _context.listContexts().remove(_context); dumpStats(); - _log.log(Log.CRIT, "Shutdown complete", new Exception("Shutdown")); + _log.log(Log.CRIT, "Shutdown(" + exitCode + ") complete", new Exception("Shutdown")); try { _context.logManager().shutdown(); } catch (Throwable t) { } if (_killVMOnEnd) { try { Thread.sleep(1000); } catch (InterruptedException ie) {} - Runtime.getRuntime().halt(-1); + Runtime.getRuntime().halt(exitCode); } } @@ -603,7 +607,7 @@ public class Router { if (_context.tunnelManager().getParticipatingCount() <= 0) { if (_log.shouldLog(Log.CRIT)) _log.log(Log.CRIT, "Graceful shutdown progress - no more tunnels, safe to die"); - shutdown(); + shutdown(EXIT_GRACEFUL); return; } else { try { @@ -693,7 +697,7 @@ public class Router { public void run() { setName("Router " + _id + " shutdown"); _log.log(Log.CRIT, "Shutting down the router..."); - shutdown(); + shutdown(EXIT_HARD); } } diff --git a/router/java/src/net/i2p/router/admin/AdminRunner.java b/router/java/src/net/i2p/router/admin/AdminRunner.java index f8e16e560638c68fb64f044840897825e6b70ad6..471fb148faa98978bfc1bd53679ee844f748b3fa 100644 --- a/router/java/src/net/i2p/router/admin/AdminRunner.java +++ b/router/java/src/net/i2p/router/admin/AdminRunner.java @@ -11,6 +11,7 @@ import java.util.Set; import net.i2p.data.Hash; import net.i2p.router.RouterContext; +import net.i2p.router.Router; import net.i2p.util.I2PThread; import net.i2p.util.Log; @@ -135,7 +136,7 @@ class AdminRunner implements Runnable { I2PThread t = new I2PThread(new Runnable() { public void run() { try { Thread.sleep(30*1000); } catch (InterruptedException ie) {} - _context.router().shutdown(); + _context.router().shutdown(Router.EXIT_HARD); } }); t.start();