new shutdown(exitCode) usage
This commit is contained in:
@ -109,7 +109,7 @@ class JobQueueRunner implements Runnable {
|
|||||||
if (_log.shouldLog(Log.CRIT))
|
if (_log.shouldLog(Log.CRIT))
|
||||||
_log.log(Log.CRIT, "Router ran out of memory, shutting down", oom);
|
_log.log(Log.CRIT, "Router ran out of memory, shutting down", oom);
|
||||||
_log.log(Log.CRIT, _currentJob.getClass().getName());
|
_log.log(Log.CRIT, _currentJob.getClass().getName());
|
||||||
_context.router().shutdown();
|
_context.router().shutdown(Router.EXIT_OOM);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.err.println("***Router ran out of memory, shutting down hard");
|
System.err.println("***Router ran out of memory, shutting down hard");
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ public class Router {
|
|||||||
// gobble
|
// gobble
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shutdown();
|
shutdown(EXIT_OOM);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_shutdownHook = new ShutdownHook();
|
_shutdownHook = new ShutdownHook();
|
||||||
@ -534,7 +534,11 @@ public class Router {
|
|||||||
buf.setLength(0);
|
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;
|
_isAlive = false;
|
||||||
I2PThread.removeOOMEventListener(_oomListener);
|
I2PThread.removeOOMEventListener(_oomListener);
|
||||||
try { _context.jobQueue().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the job queue", t); }
|
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); }
|
try { _sessionKeyPersistenceHelper.shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); }
|
||||||
_context.listContexts().remove(_context);
|
_context.listContexts().remove(_context);
|
||||||
dumpStats();
|
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) { }
|
try { _context.logManager().shutdown(); } catch (Throwable t) { }
|
||||||
if (_killVMOnEnd) {
|
if (_killVMOnEnd) {
|
||||||
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
|
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 (_context.tunnelManager().getParticipatingCount() <= 0) {
|
||||||
if (_log.shouldLog(Log.CRIT))
|
if (_log.shouldLog(Log.CRIT))
|
||||||
_log.log(Log.CRIT, "Graceful shutdown progress - no more tunnels, safe to die");
|
_log.log(Log.CRIT, "Graceful shutdown progress - no more tunnels, safe to die");
|
||||||
shutdown();
|
shutdown(EXIT_GRACEFUL);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -693,7 +697,7 @@ public class Router {
|
|||||||
public void run() {
|
public void run() {
|
||||||
setName("Router " + _id + " shutdown");
|
setName("Router " + _id + " shutdown");
|
||||||
_log.log(Log.CRIT, "Shutting down the router...");
|
_log.log(Log.CRIT, "Shutting down the router...");
|
||||||
shutdown();
|
shutdown(EXIT_HARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
import net.i2p.router.Router;
|
||||||
import net.i2p.util.I2PThread;
|
import net.i2p.util.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ class AdminRunner implements Runnable {
|
|||||||
I2PThread t = new I2PThread(new Runnable() {
|
I2PThread t = new I2PThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
||||||
_context.router().shutdown();
|
_context.router().shutdown(Router.EXIT_HARD);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
|
Reference in New Issue
Block a user