forked from I2P_Developers/i2p.i2p
* AppContext: Add hasWrapper() method
* Shutdown: - Clear more resources in peer manager, netdb, stat manager, session key manager, naming service, tunnel dispatcher, OCMOSJ (result of testing with jvisualvm) - Don't call wrapper on shutdown (starting two threads) if we were started with runplain
This commit is contained in:
@ -271,7 +271,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
if (switchRequired) {
|
||||
hiddenSwitch();
|
||||
} else if (restartRequired) {
|
||||
if (System.getProperty("wrapper.version") == null) {
|
||||
if (_context.hasWrapper()) {
|
||||
// Wow this dumps all conns immediately and really isn't nice
|
||||
addFormNotice("Performing a soft restart");
|
||||
_context.router().restart();
|
||||
@ -289,6 +289,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
// There's a few changes that don't really require restart (e.g. enabling inbound TCP)
|
||||
// But it would be hard to get right, so just do a restart.
|
||||
addFormError(_("Gracefully restarting I2P to change published router address"));
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
}
|
||||
@ -297,6 +298,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
|
||||
private void hiddenSwitch() {
|
||||
// Full restart required to generate new keys
|
||||
// FIXME don't call wrapper if not present, only rekey
|
||||
_context.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class ConfigRestartBean {
|
||||
if ( (nonce != null) && (systemNonce.equals(nonce)) && (action != null) ) {
|
||||
// Normal browsers send value, IE sends button label
|
||||
if ("shutdownImmediate".equals(action) || _("Shutdown immediately", ctx).equals(action)) {
|
||||
if (ctx.hasWrapper())
|
||||
ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_HARD));
|
||||
//ctx.router().shutdown(Router.EXIT_HARD); // never returns
|
||||
ctx.router().shutdownGracefully(Router.EXIT_HARD); // give the UI time to respond
|
||||
@ -37,13 +38,16 @@ public class ConfigRestartBean {
|
||||
_("Cancel restart", ctx).equals(action)) {
|
||||
ctx.router().cancelGracefulShutdown();
|
||||
} else if ("restartImmediate".equals(action) || _("Restart immediately", ctx).equals(action)) {
|
||||
if (ctx.hasWrapper())
|
||||
ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART));
|
||||
//ctx.router().shutdown(Router.EXIT_HARD_RESTART); // never returns
|
||||
ctx.router().shutdownGracefully(Router.EXIT_HARD_RESTART); // give the UI time to respond
|
||||
} else if ("restart".equals(action) || _("Restart", ctx).equals(action)) {
|
||||
if (ctx.hasWrapper())
|
||||
ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
ctx.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
} else if ("shutdown".equals(action) || _("Shutdown", ctx).equals(action)) {
|
||||
if (ctx.hasWrapper())
|
||||
ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL));
|
||||
ctx.router().shutdownGracefully();
|
||||
}
|
||||
@ -71,7 +75,7 @@ public class ConfigRestartBean {
|
||||
buf.append("</b></center><br>");
|
||||
buttons(ctx, buf, urlBase, systemNonce, SET2);
|
||||
} else {
|
||||
if (System.getProperty("wrapper.version") != null)
|
||||
if (ctx.hasWrapper())
|
||||
buttons(ctx, buf, urlBase, systemNonce, SET3);
|
||||
else
|
||||
buttons(ctx, buf, urlBase, systemNonce, SET4);
|
||||
|
@ -51,10 +51,12 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
if (_action == null) return;
|
||||
|
||||
if (_("Shutdown gracefully").equals(_action)) {
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL));
|
||||
_context.router().shutdownGracefully();
|
||||
addFormNotice(_("Graceful shutdown initiated"));
|
||||
} else if (_("Shutdown immediately").equals(_action)) {
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD));
|
||||
_context.router().shutdown(Router.EXIT_HARD);
|
||||
addFormNotice(_("Shutdown immediately! boom bye bye bad bwoy"));
|
||||
@ -62,19 +64,25 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
_context.router().cancelGracefulShutdown();
|
||||
addFormNotice(_("Graceful shutdown cancelled"));
|
||||
} else if (_("Graceful restart").equals(_action)) {
|
||||
// should have wrapper if restart button is visible
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
addFormNotice(_("Graceful restart requested"));
|
||||
} else if (_("Hard restart").equals(_action)) {
|
||||
// should have wrapper if restart button is visible
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART));
|
||||
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
||||
addFormNotice(_("Hard restart requested"));
|
||||
} else if (_("Rekey and Restart").equals(_action)) {
|
||||
addFormNotice(_("Rekeying after graceful restart"));
|
||||
// FIXME don't call wrapper if not present, only rekey
|
||||
_context.addShutdownTask(new UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
} else if (_("Rekey and Shutdown").equals(_action)) {
|
||||
addFormNotice(_("Rekeying after graceful shutdown"));
|
||||
// FIXME don't call wrapper if not present, only rekey
|
||||
_context.addShutdownTask(new UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL);
|
||||
} else if (_("Run I2P on startup").equals(_action)) {
|
||||
|
@ -117,7 +117,7 @@ public class ConfigUpdateHelper extends HelperBase {
|
||||
buf.append(" selected=\"true\"");
|
||||
buf.append('>').append(_("Download and verify only")).append("</option>");
|
||||
|
||||
if (System.getProperty("wrapper.version") != null) {
|
||||
if (_context.hasWrapper()) {
|
||||
buf.append("<option value=\"install\"");
|
||||
if (_dontInstall)
|
||||
buf.append(" disabled=\"true\"");
|
||||
|
@ -115,7 +115,7 @@ public class UnsignedUpdateHandler extends UpdateHandler {
|
||||
_log.log(Log.CRIT, "Update was downloaded, will be installed at next restart");
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("<b>").append(_("Update downloaded")).append("</b><br>");
|
||||
if (System.getProperty("wrapper.version") != null)
|
||||
if (_context.hasWrapper())
|
||||
buf.append(_("Click Restart to install"));
|
||||
else
|
||||
buf.append(_("Click Shutdown and restart to install"));
|
||||
|
@ -285,7 +285,7 @@ public class UpdateHandler {
|
||||
_log.log(Log.CRIT, "Update was VERIFIED, will be installed at next restart");
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("<b>").append(_("Update downloaded")).append("<br>");
|
||||
if (System.getProperty("wrapper.version") != null)
|
||||
if (_context.hasWrapper())
|
||||
buf.append(_("Click Restart to install"));
|
||||
else
|
||||
buf.append(_("Click Shutdown and restart to install"));
|
||||
@ -312,6 +312,7 @@ public class UpdateHandler {
|
||||
}
|
||||
|
||||
protected void restart() {
|
||||
if (_context.hasWrapper())
|
||||
_context.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
||||
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
||||
}
|
||||
|
@ -888,4 +888,12 @@ public class I2PAppContext {
|
||||
public InternalClientManager internalClientManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the wrapper present?
|
||||
* @since 0.8.8
|
||||
*/
|
||||
public boolean hasWrapper() {
|
||||
return System.getProperty("wrapper.version") != null;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
*
|
||||
* If not in router context, the database will be opened read-only
|
||||
* unless the property i2p.naming.blockfile.writeInAppContext is true.
|
||||
* Not designed for simultaneous access by multiple processes.
|
||||
* Not designed for multiple instantiations or simultaneous use by multple JVMs.
|
||||
*
|
||||
* @throws RuntimeException on fatal error
|
||||
*/
|
||||
@ -780,6 +780,7 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
}
|
||||
_isClosed = true;
|
||||
}
|
||||
clearCache();
|
||||
}
|
||||
|
||||
/** for logging errors in the static serializers below */
|
||||
|
@ -57,6 +57,12 @@ public class StatManager {
|
||||
_statLog = new BufferedStatLog(context);
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
public void shutdown() {
|
||||
_frequencyStats.clear();
|
||||
_rateStats.clear();
|
||||
}
|
||||
|
||||
/** may be null */
|
||||
public StatLog getStatLog() { return _statLog; }
|
||||
public void setStatLog(StatLog log) {
|
||||
|
@ -77,4 +77,12 @@ public class LogConsoleBuffer {
|
||||
public List<String> getMostRecentCriticalMessages() {
|
||||
return new ArrayList(_critBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.8.8
|
||||
*/
|
||||
public void clear() {
|
||||
_buffer.clear();
|
||||
_critBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
@ -660,6 +660,10 @@ public class LogManager {
|
||||
_writer.notifyAll();
|
||||
}
|
||||
}
|
||||
_records.clear();
|
||||
_limits.clear();
|
||||
_logs.clear();
|
||||
_consoleBuffer.clear();
|
||||
}
|
||||
|
||||
private static int __id = 0;
|
||||
|
@ -1,3 +1,12 @@
|
||||
2011-07-03 zzz
|
||||
* AppContext: Add hasWrapper() method
|
||||
* Shutdown:
|
||||
- Clear more resources in peer manager, netdb, stat manager,
|
||||
session key manager, naming service, tunnel dispatcher,
|
||||
OCMOSJ (result of testing with jvisualvm)
|
||||
- Don't call wrapper on shutdown (starting two threads) if we
|
||||
were started with runplain
|
||||
|
||||
2011-07-01 zzz
|
||||
* EepGet:
|
||||
- Fix error output bug
|
||||
|
@ -32,6 +32,13 @@ public class ClientMessagePool {
|
||||
OutboundClientMessageOneShotJob.init(_context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.8.8
|
||||
*/
|
||||
public void shutdown() {
|
||||
OutboundClientMessageOneShotJob.clearAllCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new message to the pool. The message can either be locally or
|
||||
* remotely destined.
|
||||
|
@ -258,7 +258,7 @@ public class Router {
|
||||
// but this is the same method used in LogsHelper and we have no complaints.
|
||||
// (we could look for the wrapper.config file and parse it I guess...)
|
||||
// If we don't have a wrapper, RouterLaunch does this for us.
|
||||
if (System.getProperty("wrapper.version") != null) {
|
||||
if (_context.hasWrapper()) {
|
||||
File f = new File(System.getProperty("java.io.tmpdir"), "wrapper.log");
|
||||
if (!f.exists())
|
||||
f = new File(_context.getBaseDir(), "wrapper.log");
|
||||
@ -650,7 +650,7 @@ public class Router {
|
||||
}
|
||||
_context.removeShutdownTasks();
|
||||
// hard and ugly
|
||||
if (System.getProperty("wrapper.version") != null)
|
||||
if (_context.hasWrapper())
|
||||
_log.log(Log.CRIT, "Restarting with new router identity");
|
||||
else
|
||||
_log.log(Log.CRIT, "Shutting down because old router identity was invalid - restart I2P");
|
||||
@ -981,7 +981,8 @@ public class Router {
|
||||
try { _context.namingService().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the naming service", t); }
|
||||
try { _context.jobQueue().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the job queue", t); }
|
||||
//try { _context.adminManager().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the admin manager", t); }
|
||||
try { _context.statPublisher().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the stats manager", t); }
|
||||
try { _context.statPublisher().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the stats publisher", t); }
|
||||
try { _context.statManager().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the stats manager", t); }
|
||||
try { _context.tunnelManager().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the tunnel manager", t); }
|
||||
try { _context.tunnelDispatcher().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the tunnel dispatcher", t); }
|
||||
try { _context.netDb().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the networkDb", t); }
|
||||
@ -991,7 +992,8 @@ public class Router {
|
||||
try { _context.messageRegistry().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the message registry", t); }
|
||||
try { _context.messageValidator().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the message validator", t); }
|
||||
try { _context.inNetMessagePool().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the inbound net pool", t); }
|
||||
//try { _sessionKeyPersistenceHelper.shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); }
|
||||
try { _context.clientMessagePool().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the client msg pool", t); }
|
||||
try { _context.sessionKeyManager().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); }
|
||||
_context.deleteTempDir();
|
||||
List<RouterContext> contexts = RouterContext.getContexts();
|
||||
contexts.remove(_context);
|
||||
@ -1054,6 +1056,8 @@ public class Router {
|
||||
if (_killVMOnEnd) {
|
||||
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
|
||||
Runtime.getRuntime().halt(exitCode);
|
||||
} else {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1301,7 +1305,7 @@ public class Router {
|
||||
}
|
||||
}
|
||||
// exit whether ok or not
|
||||
if (System.getProperty("wrapper.version") != null)
|
||||
if (_context.hasWrapper())
|
||||
System.out.println("INFO: Restarting after update");
|
||||
else
|
||||
System.out.println("WARNING: Exiting after update, restart I2P");
|
||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 3;
|
||||
public final static long BUILD = 4;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
@ -711,6 +711,22 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.8.8
|
||||
*/
|
||||
public static void clearAllCaches() {
|
||||
synchronized(_leaseSetCache) {
|
||||
_leaseSetCache.clear();
|
||||
}
|
||||
synchronized(_leaseCache) {
|
||||
_leaseCache.clear();
|
||||
}
|
||||
synchronized(_tunnelCache) {
|
||||
_backloggedTunnelCache.clear();
|
||||
_tunnelCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean out old leaseSets
|
||||
* Caller must synchronize on tc.
|
||||
|
@ -90,6 +90,15 @@ class KBucketSet {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
public void clear() {
|
||||
for (int i = 0; i < _buckets.length; i++) {
|
||||
_buckets[i].setEntries(Collections.EMPTY_SET);
|
||||
}
|
||||
_size = 0;
|
||||
_us.clearXorCache();
|
||||
}
|
||||
|
||||
public Set<Hash> getAll() { return getAll(Collections.EMPTY_SET); };
|
||||
public Set<Hash> getAll(Set<Hash> toIgnore) {
|
||||
Set<Hash> all = new HashSet(1024);
|
||||
|
@ -193,6 +193,8 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
|
||||
public void shutdown() {
|
||||
_initialized = false;
|
||||
if (_kb != null)
|
||||
_kb.clear();
|
||||
// don't null out _kb, it can cause NPEs in concurrent operations
|
||||
//_kb = null;
|
||||
if (_ds != null)
|
||||
|
@ -107,9 +107,10 @@ class LocalHash extends Hash {
|
||||
return distance;
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
public void clearXorCache() {
|
||||
_xorCache = null;
|
||||
synchronized (_xorCache) {
|
||||
_xorCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/********
|
||||
|
@ -229,7 +229,8 @@ public class ProfileOrganizer {
|
||||
|
||||
/** @since 0.8.8 */
|
||||
void clearProfiles() {
|
||||
getReadLock();
|
||||
if (!getWriteLock())
|
||||
return;
|
||||
try {
|
||||
_failingPeers.clear();
|
||||
_fastPeers.clear();
|
||||
@ -237,7 +238,8 @@ public class ProfileOrganizer {
|
||||
_notFailingPeers.clear();
|
||||
_notFailingPeersList.clear();
|
||||
_wellIntegratedPeers.clear();
|
||||
} finally { releaseReadLock(); }
|
||||
_strictCapacityOrder.clear();
|
||||
} finally { releaseWriteLock(); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -722,7 +722,13 @@ public class TunnelDispatcher implements Service {
|
||||
_validator.destroy();
|
||||
_validator = null;
|
||||
_pumper.stopPumping();
|
||||
_outboundGateways.clear();
|
||||
_outboundEndpoints.clear();
|
||||
_participants.clear();
|
||||
_inboundGateways.clear();
|
||||
_participatingConfig.clear();
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
shutdown();
|
||||
startup();
|
||||
|
Reference in New Issue
Block a user