Changeset 0f384c8
- Timestamp:
- Dec 5, 2011 4:18:35 PM (9 years ago)
- Branches:
- master
- Children:
- bd82a0c
- Parents:
- 5362e7cf
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java
r5362e7cf r0f384c8 343 343 344 344 Thread t = new I2PAppThread(new StatSummarizer(), "StatSummarizer", true); 345 t.setPriority(Thread.NORM_PRIORITY - 1); 345 346 t.start(); 346 347 … … 351 352 NewsFetcher fetcher = NewsFetcher.getInstance(ctx); 352 353 Thread newsThread = new I2PAppThread(fetcher, "NewsFetcher", true); 354 newsThread.setPriority(Thread.NORM_PRIORITY - 1); 353 355 newsThread.start(); 354 356 355 357 if (PluginStarter.pluginsEnabled(ctx)) { 356 358 t = new I2PAppThread(new PluginStarter(ctx), "PluginStarter", true); 359 t.setPriority(Thread.NORM_PRIORITY - 1); 357 360 t.start(); 358 361 ctx.addShutdownTask(new PluginStopper(ctx)); -
router/java/src/net/i2p/router/Router.java
r5362e7cf r0f384c8 276 276 //_sessionKeyPersistenceHelper = new SessionKeyPersistenceHelper(_context); 277 277 _killVMOnEnd = true; 278 _oomListener = new I2PThread.OOMEventListener() { 279 public void outOfMemory(OutOfMemoryError oom) { 280 clearCaches(); 281 _log.log(Log.CRIT, "Thread ran out of memory, shutting down I2P", oom); 282 // prevent multiple parallel shutdowns (when you OOM, you OOM a lot...) 283 if (_shutdownInProgress) 284 return; 285 for (int i = 0; i < 5; i++) { // try this 5 times, in case it OOMs 286 try { 287 _log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() + 288 " total mem: " + Runtime.getRuntime().totalMemory()); 289 break; // w00t 290 } catch (OutOfMemoryError oome) { 291 // gobble 292 } 293 } 294 _log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in $I2P/wrapper.config"); 295 shutdown(EXIT_OOM); 296 } 297 }; 278 _oomListener = new OOMListener(_context); 279 298 280 _shutdownHook = new ShutdownHook(_context); 299 _gracefulShutdownDetector = new I2PAppThread(new GracefulShutdown(), "Graceful shutdown hook", true); 281 _gracefulShutdownDetector = new I2PAppThread(new GracefulShutdown(_context), "Graceful shutdown hook", true); 282 _gracefulShutdownDetector.setPriority(Thread.NORM_PRIORITY + 1); 300 283 _gracefulShutdownDetector.start(); 301 284 302 285 _watchdog = new RouterWatchdog(_context); 303 286 _watchdogThread = new I2PAppThread(_watchdog, "RouterWatchdog", true); 287 _watchdogThread.setPriority(Thread.NORM_PRIORITY + 1); 304 288 _watchdogThread.start(); 305 289 … … 974 958 ******/ 975 959 976 /**977 * A non-daemon thread to let978 * the shutdown task get all the way to the end979 * @since 0.8.8980 */981 private static class Spinner extends Thread {982 983 public Spinner() {984 super();985 setName("Shutdown Spinner");986 setDaemon(false);987 }988 989 @Override990 public void run() {991 try {992 sleep(60*1000);993 } catch (InterruptedException ie) {}994 }995 }996 997 960 public static final int EXIT_GRACEFUL = 2; 998 961 public static final int EXIT_HARD = 3; … … 1171 1134 } 1172 1135 } 1136 1173 1137 /** 1174 1138 * What exit code do we plan on using when we shut down (or -1, if there isn't a graceful shutdown planned) 1175 1139 */ 1176 1140 public int scheduledGracefulExitCode() { return _gracefulExitCode; } 1141 1142 /** 1143 * Is a graceful shutdown in progress? This may be cancelled. 1144 */ 1177 1145 public boolean gracefulShutdownInProgress() { 1178 1146 return (null != _config.get(PROP_SHUTDOWN_IN_PROGRESS)); 1179 1147 } 1148 1149 /** 1150 * Is a final shutdown in progress? This may not be cancelled. 1151 * @since 0.8.12 1152 */ 1153 public boolean isFinalShutdownInProgress() { 1154 return _shutdownInProgress; 1155 } 1156 1180 1157 /** How long until the graceful shutdown will kill us? */ 1181 1158 public long getShutdownTimeRemaining() { … … 1188 1165 else 1189 1166 return exp + 2*CLOCK_FUDGE_FACTOR - _context.clock().now(); 1190 }1191 1192 /**1193 * Simple thread that sits and waits forever, managing the1194 * graceful shutdown "process" (describing it would take more text1195 * than just reading the code...)1196 *1197 */1198 private class GracefulShutdown implements Runnable {1199 public void run() {1200 while (true) {1201 boolean shutdown = (null != _config.get(PROP_SHUTDOWN_IN_PROGRESS));1202 if (shutdown) {1203 if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART ||1204 _context.tunnelManager().getParticipatingCount() <= 0) {1205 if (_gracefulExitCode == EXIT_HARD)1206 _log.log(Log.CRIT, "Shutting down after a brief delay");1207 else if (_gracefulExitCode == EXIT_HARD_RESTART)1208 _log.log(Log.CRIT, "Restarting after a brief delay");1209 else1210 _log.log(Log.CRIT, "Graceful shutdown progress - no more tunnels, safe to die");1211 // Allow time for a UI reponse1212 try {1213 synchronized (Thread.currentThread()) {1214 Thread.currentThread().wait(2*1000);1215 }1216 } catch (InterruptedException ie) {}1217 shutdown(_gracefulExitCode);1218 return;1219 } else {1220 try {1221 synchronized (Thread.currentThread()) {1222 Thread.currentThread().wait(10*1000);1223 }1224 } catch (InterruptedException ie) {}1225 }1226 } else {1227 try {1228 synchronized (Thread.currentThread()) {1229 Thread.currentThread().wait();1230 }1231 } catch (InterruptedException ie) {}1232 }1233 }1234 }1235 1167 } 1236 1168 … … 1309 1241 ((RouterClock) _context.clock()).removeShiftListener(this); 1310 1242 _isAlive = false; 1311 Thread t = new Thread(new Restarter(), "Router Restart"); 1243 _started = _context.clock().now(); 1244 Thread t = new Thread(new Restarter(_context), "Router Restart"); 1245 t.setPriority(Thread.NORM_PRIORITY + 1); 1312 1246 t.start(); 1313 1247 } 1314 1248 1315 1249 /** 1316 * @since 0.8.8 1317 */ 1318 private class Restarter implements Runnable { 1319 public void run() { 1320 _started = _context.clock().now(); 1321 _log.error("Stopping the router for a restart..."); 1322 _log.logAlways(Log.WARN, "Stopping the client manager"); 1323 // NOTE: DisconnectMessageHandler keys off "restart" 1324 try { _context.clientManager().shutdown("Router restart"); } catch (Throwable t) { _log.log(Log.CRIT, "Error stopping the client manager", t); } 1325 _log.logAlways(Log.WARN, "Stopping the comm system"); 1326 _context.bandwidthLimiter().reinitialize(); 1327 try { _context.messageRegistry().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the message registry", t); } 1328 try { _context.commSystem().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the comm system", t); } 1329 _log.logAlways(Log.WARN, "Stopping the tunnel manager"); 1330 try { _context.tunnelManager().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the tunnel manager", t); } 1331 1332 //try { _context.peerManager().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the peer manager", t); } 1333 //try { _context.netDb().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the networkDb", t); } 1334 //try { _context.jobQueue().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the job queue", t); } 1335 1336 _log.logAlways(Log.WARN, "Router teardown complete, restarting the router..."); 1337 try { Thread.sleep(10*1000); } catch (InterruptedException ie) {} 1338 1339 _log.logAlways(Log.WARN, "Restarting the comm system"); 1340 _log.logAlways(Log.WARN, "Restarting the tunnel manager"); 1341 _log.logAlways(Log.WARN, "Restarting the client manager"); 1342 try { _context.clientMessagePool().restart(); } catch (Throwable t) { _log.log(Log.CRIT, "Error restarting the CMP", t); } 1343 try { _context.clientManager().startup(); } catch (Throwable t) { _log.log(Log.CRIT, "Error starting the client manager", t); } 1344 1345 _isAlive = true; 1346 rebuildRouterInfo(); 1347 1348 _log.logAlways(Log.WARN, "Restart complete"); 1349 ((RouterClock) _context.clock()).addShiftListener(Router.this); 1350 } 1351 } 1352 1250 * Only for Restarter 1251 * @since 0.8.12 1252 */ 1253 public void setIsAlive() { 1254 _isAlive = true; 1255 } 1256 1353 1257 public static void main(String args[]) { 1354 1258 System.out.println("Starting I2P " + RouterVersion.FULL_VERSION);
Note: See TracChangeset
for help on using the changeset viewer.