fix SimpleTimer logging

This commit is contained in:
zzz
2012-06-29 14:05:39 +00:00
parent 5a1d52d82c
commit ebb6609a2b

View File

@ -9,12 +9,13 @@ import net.i2p.I2PAppContext;
*/
class Executor implements Runnable {
private final I2PAppContext _context;
private Log _log;
private final List _readyEvents;
private final Log _log;
private final List<SimpleTimer.TimedEvent> _readyEvents;
private final SimpleStore runn;
public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) {
public Executor(I2PAppContext ctx, Log log, List<SimpleTimer.TimedEvent> events, SimpleStore x) {
_context = ctx;
_log = log;
_readyEvents = events;
runn = x;
}
@ -26,7 +27,7 @@ class Executor implements Runnable {
if (_readyEvents.isEmpty())
try { _readyEvents.wait(); } catch (InterruptedException ie) {}
if (!_readyEvents.isEmpty())
evt = (SimpleTimer.TimedEvent)_readyEvents.remove(0);
evt = _readyEvents.remove(0);
}
if (evt != null) {
@ -34,21 +35,12 @@ class Executor implements Runnable {
try {
evt.timeReached();
} catch (Throwable t) {
log("Executing task " + evt + " exited unexpectedly, please report", t);
_log.error("Executing task " + evt + " exited unexpectedly, please report", t);
}
long time = _context.clock().now() - before;
// FIXME _log won't be non-null unless we already had a CRIT
if ( (time > 1000) && (_log != null) && (_log.shouldLog(Log.WARN)) )
if ( (time > 1000) && (_log.shouldLog(Log.WARN)) )
_log.warn("wtf, event execution took " + time + ": " + evt);
}
}
}
private void log(String msg, Throwable t) {
synchronized (this) {
if (_log == null)
_log = I2PAppContext.getGlobalContext().logManager().getLog(SimpleTimer.class);
}
_log.log(Log.CRIT, msg, t);
}
}