use of net.i2p.router.util.EventLog in project i2p.i2p by i2p.
the class EventLogHelper method getEvents.
public String getEvents() {
EventLog ev = _context.router().eventLog();
// oldest first
Map<Long, String> events;
boolean isAll = ALL.equals(_event);
if (isAll)
events = ev.getEvents(_from);
else
events = ev.getEvents(_event, _from);
String xev = _xevents.get(_event);
if (xev == null)
xev = _event;
xev = DataHelper.escapeHTML(xev);
if (events.isEmpty()) {
if (isAll) {
if (_age == 0)
return ("<table id=\"eventlog\"><tr><td class=\"infohelp\">") + _t("No events found") + ("</td></tr></table>");
;
return ("<table id=\"eventlog\"><tr><td>") + _t("No events found in previous {0}", DataHelper.formatDuration2(_age)) + ("</td></tr></table>");
}
if (_age == 0)
return ("<table id=\"eventlog\"><tr><td class=\"infohelp\">") + _t("No \"{0}\" events found", xev) + ("</td></tr></table>");
return ("<table id=\"eventlog\"><tr><td class=\"infohelp\">") + _t("No \"{0}\" events found in previous {1}", xev, DataHelper.formatDuration2(_age)) + ("</td></tr></table>");
}
StringBuilder buf = new StringBuilder(2048);
buf.append("<table id=\"eventlog\"><tr><th>");
buf.append(_t("Time"));
buf.append("</th><th>");
if (isAll) {
buf.append(_t("Event"));
buf.append("</th><th>");
buf.append(_t("Details"));
} else {
buf.append(xev);
}
buf.append("</th></tr>");
SimpleDateFormat fmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
// the router sets the JVM time zone to UTC but saves the original here so we can get it
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(events.entrySet());
Collections.reverse(entries);
for (Map.Entry<Long, String> e : entries) {
long time = e.getKey().longValue();
String event = e.getValue();
buf.append("<tr><td>");
buf.append(fmt.format(new Date(time)));
buf.append("</td><td>");
if (isAll) {
String[] s = DataHelper.split(event, " ", 2);
String xs = _xevents.get(s[0]);
if (xs == null)
xs = s[0];
buf.append(xs);
buf.append("</td><td>");
if (s.length > 1)
buf.append(s[1]);
} else {
buf.append(event);
}
buf.append("</td></tr>");
}
buf.append("</table>");
return buf.toString();
}
use of net.i2p.router.util.EventLog in project i2p.i2p by i2p.
the class ShutdownHook method run.
@Override
public void run() {
setName("Router " + _id + " shutdown");
Log l = _context.logManager().getLog(Router.class);
l.log(Log.CRIT, "Shutting down the router...");
// Needed to make the wrapper happy, otherwise it gets confused
// and thinks we haven't shut down, possibly because it
// prevents other shutdown hooks from running
_context.router().eventLog().addEvent(EventLog.CRASHED, RouterVersion.FULL_VERSION);
_context.router().setKillVMOnEnd(false);
_context.router().shutdown2(Router.EXIT_HARD);
}
use of net.i2p.router.util.EventLog in project i2p.i2p by i2p.
the class OOMListener method outOfMemory.
public void outOfMemory(OutOfMemoryError oom) {
try {
// prevent multiple parallel shutdowns (when you OOM, you OOM a lot...)
if (_context.router().isFinalShutdownInProgress())
return;
} catch (OutOfMemoryError oome) {
}
try {
// Only do this once
if (_wasCalled.getAndSet(true))
return;
} catch (OutOfMemoryError oome) {
}
try {
// boost priority to help us shut down
// this may or may not do anything...
Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);
} catch (OutOfMemoryError oome) {
}
try {
Router.clearCaches();
} catch (OutOfMemoryError oome) {
}
Log log = null;
try {
log = _context.logManager().getLog(Router.class);
log.log(Log.CRIT, "Thread ran out of memory, shutting down I2P", oom);
log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() + " total mem: " + Runtime.getRuntime().totalMemory());
// Can't find any System property or wrapper property that gives
// you the actual config file path, have to guess
String path;
if (SystemVersion.isLinuxService()) {
if (SystemVersion.isGentoo())
path = "/usr/share/i2p";
else
path = "/etc/i2p";
} else {
path = _context.getBaseDir().toString();
}
if (_context.hasWrapper()) {
log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in " + path + File.separatorChar + "wrapper.config");
} else if (!SystemVersion.isWindows()) {
log.log(Log.CRIT, "To prevent future shutdowns, increase MAXMEMOPT in " + path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper");
} else {
log.log(Log.CRIT, "To prevent future shutdowns, run the restartable version of I2P, and increase wrapper.java.maxmemory in " + path + File.separatorChar + "wrapper.config");
}
} catch (OutOfMemoryError oome) {
}
try {
ThreadDump.dump(_context, 1);
} catch (OutOfMemoryError oome) {
}
try {
_context.router().eventLog().addEvent(EventLog.OOM);
} catch (OutOfMemoryError oome) {
}
try {
_context.router().shutdown(Router.EXIT_OOM);
} catch (OutOfMemoryError oome) {
}
}
use of net.i2p.router.util.EventLog in project i2p.i2p by i2p.
the class Restarter method run.
public void run() {
_context.router().eventLog().addEvent(EventLog.SOFT_RESTART);
Log log = _context.logManager().getLog(Router.class);
log.error("Stopping the router for a restart...");
log.logAlways(Log.WARN, "Stopping the client manager");
// NOTE: DisconnectMessageHandler keys off "restart"
try {
_context.clientManager().shutdown("Router restart");
} catch (Throwable t) {
log.log(Log.CRIT, "Error stopping the client manager", t);
}
log.logAlways(Log.WARN, "Stopping the comm system");
_context.bandwidthLimiter().reinitialize();
try {
_context.messageRegistry().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the message registry", t);
}
try {
_context.commSystem().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the comm system", t);
}
log.logAlways(Log.WARN, "Stopping the tunnel manager");
try {
_context.tunnelManager().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the tunnel manager", t);
}
// try { _context.peerManager().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the peer manager", t); }
// try { _context.netDb().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the networkDb", t); }
// try { _context.jobQueue().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the job queue", t); }
log.logAlways(Log.WARN, "Router teardown complete, restarting the router...");
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException ie) {
}
log.logAlways(Log.WARN, "Restarting the comm system");
log.logAlways(Log.WARN, "Restarting the tunnel manager");
log.logAlways(Log.WARN, "Restarting the client manager");
try {
_context.clientMessagePool().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the CMP", t);
}
try {
_context.clientManager().startup();
} catch (Throwable t) {
log.log(Log.CRIT, "Error starting the client manager", t);
}
_context.router().setIsAlive();
_context.router().rebuildRouterInfo();
log.logAlways(Log.WARN, "Restart complete");
((RouterClock) _context.clock()).addShiftListener(_context.router());
}
Aggregations