use of net.i2p.util.Log in project i2p.i2p by i2p.
the class GracefulShutdown method run.
public void run() {
Log log = _context.logManager().getLog(Router.class);
while (true) {
boolean shutdown = _context.router().gracefulShutdownInProgress();
if (shutdown) {
int gracefulExitCode = _context.router().scheduledGracefulExitCode();
if (gracefulExitCode == Router.EXIT_HARD || gracefulExitCode == Router.EXIT_HARD_RESTART || _context.tunnelManager().getParticipatingCount() <= 0) {
if (gracefulExitCode == Router.EXIT_HARD)
log.log(Log.CRIT, "Shutting down after a brief delay");
else if (gracefulExitCode == Router.EXIT_HARD_RESTART)
log.log(Log.CRIT, "Restarting after a brief delay");
else
log.log(Log.CRIT, "Graceful shutdown progress: No more tunnels, starting final shutdown");
// Allow time for a UI reponse
try {
synchronized (Thread.currentThread()) {
Thread.currentThread().wait(2 * 1000);
}
} catch (InterruptedException ie) {
}
_context.router().shutdown(gracefulExitCode);
return;
} else {
try {
synchronized (Thread.currentThread()) {
Thread.currentThread().wait(10 * 1000);
}
} catch (InterruptedException ie) {
}
}
} else {
try {
synchronized (Thread.currentThread()) {
Thread.currentThread().wait();
}
} catch (InterruptedException ie) {
}
}
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class GetBidsJob method getBids.
static void getBids(RouterContext context, TransportManager tmgr, OutNetMessage msg) {
Log log = context.logManager().getLog(GetBidsJob.class);
Hash to = msg.getTarget().getIdentity().getHash();
msg.timestamp("bid");
if (context.banlist().isBanlisted(to)) {
if (log.shouldLog(Log.WARN))
log.warn("Attempt to send a message to a banlisted peer - " + to);
// context.messageRegistry().peerFailed(to);
context.statManager().addRateData("transport.bidFailBanlisted", msg.getLifetime());
fail(context, msg);
return;
}
Hash us = context.routerHash();
if (to.equals(us)) {
if (log.shouldLog(Log.ERROR))
log.error("send a message to ourselves? nuh uh. msg = " + msg);
context.statManager().addRateData("transport.bidFailSelf", msg.getLifetime());
fail(context, msg);
return;
}
TransportBid bid = tmgr.getNextBid(msg);
if (bid == null) {
int failedCount = msg.getFailedTransports().size();
if (failedCount == 0) {
context.statManager().addRateData("transport.bidFailNoTransports", msg.getLifetime());
// This used to be "no common transports" but it is almost always no transports at all
context.banlist().banlistRouter(to, _x("No transports (hidden or starting up?)"));
} else if (failedCount >= tmgr.getTransportCount()) {
context.statManager().addRateData("transport.bidFailAllTransports", msg.getLifetime());
// fail after all transports were unsuccessful
context.netDb().fail(to);
}
fail(context, msg);
} else {
if (log.shouldLog(Log.INFO))
log.info("Attempting to send on transport " + bid.getTransport().getStyle() + ": " + bid);
bid.getTransport().send(msg);
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class PersistRouterInfoJob method runJob.
public void runJob() {
Log _log = getContext().logManager().getLog(PersistRouterInfoJob.class);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Persisting updated router info");
File infoFile = new File(getContext().getRouterDir(), CreateRouterInfoJob.INFO_FILENAME);
RouterInfo info = getContext().router().getRouterInfo();
FileOutputStream fos = null;
synchronized (getContext().router().routerInfoFileLock) {
try {
fos = new SecureFileOutputStream(infoFile);
info.writeBytes(fos);
} catch (DataFormatException dfe) {
_log.error("Error rebuilding the router information", dfe);
} catch (IOException ioe) {
_log.error("Error writing out the rebuilt router information", ioe);
} finally {
if (fos != null)
try {
fos.close();
} catch (IOException ioe) {
}
}
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class ReadConfigJob method runJob.
public void runJob() {
File configFile = new File(getContext().router().getConfigFilename());
if (shouldReread(configFile)) {
getContext().router().readConfig();
_lastRead = getContext().clock().now();
Log log = getContext().logManager().getLog(ReadConfigJob.class);
if (log.shouldDebug())
log.debug("Reloaded " + configFile);
}
requeue(DELAY);
}
use of net.i2p.util.Log 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);
}
Aggregations