don't create two contexts just for this I2PTunnel (one implicit from the static new Log(I2PTunnel.class) and one explicit)

This commit is contained in:
jrandom
2004-04-24 12:51:15 +00:00
committed by zzz
parent a52cea29f4
commit e73eb55d75

View File

@ -64,9 +64,9 @@ import net.i2p.util.EventDispatcherImpl;
import net.i2p.util.Log; import net.i2p.util.Log;
public class I2PTunnel implements Logging, EventDispatcher { public class I2PTunnel implements Logging, EventDispatcher {
private final static Log _log = new Log(I2PTunnel.class); private Log _log;
private final EventDispatcherImpl _event = new EventDispatcherImpl(); private EventDispatcherImpl _event;
private static I2PAppContext _context = new I2PAppContext(); private I2PAppContext _context;
public static final int PACKET_DELAY = 100; public static final int PACKET_DELAY = 100;
@ -98,6 +98,9 @@ public class I2PTunnel implements Logging, EventDispatcher {
} }
public I2PTunnel(String[] args, ConnectionEventListener lsnr) { public I2PTunnel(String[] args, ConnectionEventListener lsnr) {
_context = new I2PAppContext();
_log = _context.logManager().getLog(I2PTunnel.class);
_event = new EventDispatcherImpl();
addConnectionEventListener(lsnr); addConnectionEventListener(lsnr);
boolean gui = true; boolean gui = true;
boolean checkRunByE = true; boolean checkRunByE = true;
@ -921,6 +924,9 @@ public class I2PTunnel implements Logging, EventDispatcher {
if ((name == null) || (name.trim().length() <= 0)) throw new DataFormatException("Empty destination provided"); if ((name == null) || (name.trim().length() <= 0)) throw new DataFormatException("Empty destination provided");
I2PAppContext ctx = I2PAppContext.getGlobalContext();
Log log = ctx.logManager().getLog(I2PTunnel.class);
if (name.startsWith("file:")) { if (name.startsWith("file:")) {
Destination result = new Destination(); Destination result = new Destination();
byte content[] = null; byte content[] = null;
@ -944,19 +950,21 @@ public class I2PTunnel implements Logging, EventDispatcher {
result.fromByteArray(content); result.fromByteArray(content);
return result; return result;
} catch (Exception ex) { } catch (Exception ex) {
if (_log.shouldLog(Log.INFO)) _log.info("File is not a binary destination - trying base64"); if (log.shouldLog(Log.INFO))
log.info("File is not a binary destination - trying base64");
try { try {
byte decoded[] = Base64.decode(new String(content)); byte decoded[] = Base64.decode(new String(content));
result.fromByteArray(decoded); result.fromByteArray(decoded);
return result; return result;
} catch (DataFormatException dfe) { } catch (DataFormatException dfe) {
if (_log.shouldLog(Log.WARN)) _log.warn("File is not a base64 destination either - failing!"); if (log.shouldLog(Log.WARN))
log.warn("File is not a base64 destination either - failing!");
return null; return null;
} }
} }
} else { } else {
// ask naming service // ask naming service
NamingService inst = _context.namingService(); NamingService inst = ctx.namingService();
return inst.lookup(name); return inst.lookup(name);
} }
} }