From 592680302fb53678e2e40fd0aceb89d61c2bc7de Mon Sep 17 00:00:00 2001 From: zab2 Date: Sun, 8 Sep 2013 12:55:05 +0000 Subject: [PATCH] make the logCloseLoop() methods members of the Log class so they can be used everywhere --- .../i2p/client/streaming/I2PSocketFull.java | 2 +- .../streaming/I2PSocketManagerFull.java | 2 +- .../src/net/i2p/client/streaming/LogUtil.java | 41 ------------------- .../client/streaming/MessageOutputStream.java | 6 +-- core/java/src/net/i2p/util/Log.java | 28 +++++++++++++ 5 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 apps/streaming/java/src/net/i2p/client/streaming/LogUtil.java diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java index 95d551d73..c4675c172 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java @@ -36,7 +36,7 @@ class I2PSocketFull implements I2PSocket { public void close() throws IOException { if (!_closed.compareAndSet(false,true)) { // log a trace to find out why - LogUtil.logCloseLoop(log, "I2PSocket",_localPeer,"-->",_remotePeer,_connection); + log.logCloseLoop("I2PSocket",_localPeer,"-->",_remotePeer,_connection); return; } Connection c = _connection; diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java index 01d62b609..58aaa0f2f 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java @@ -316,7 +316,7 @@ public class I2PSocketManagerFull implements I2PSocketManager { public void destroySocketManager() { if (!_isDestroyed.compareAndSet(false,true)) { // shouldn't happen, log a stack trace to find out why it happened - LogUtil.logCloseLoop(_log, "I2PSocketManager", getName()); + _log.logCloseLoop("I2PSocketManager", getName()); return; } _connectionManager.setAllowIncomingConnections(false); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/LogUtil.java b/apps/streaming/java/src/net/i2p/client/streaming/LogUtil.java deleted file mode 100644 index 1b55bd1a1..000000000 --- a/apps/streaming/java/src/net/i2p/client/streaming/LogUtil.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.i2p.client.streaming; - -import net.i2p.util.Log; - -/** - * Debug logging utility - * @since 0.9.7 - */ -class LogUtil { - private LogUtil() {} - - /** - * logs a loop when closing a resource with level INFO - * @param desc vararg description - * @param log logger for the class we're intersted in - */ - static void logCloseLoop(Log log, Object... desc) { - logCloseLoop(log, Log.INFO, desc); - } - - /** - * Logs a close loop when closing a resource - * @param desc vararg description of the resource - * @param log logger to use - * @param level level at which to log - */ - static void logCloseLoop(Log log, int level, Object... desc) { - if (!log.shouldLog(level)) - return; - - // catenate all toString()s - String descString = "close() loop in"; - for (Object o : desc) { - descString += " "; - descString += String.valueOf(o); - } - - Exception e = new Exception("check stack trace"); - log.log(level,descString,e); - } -} diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java index 1a6e961f8..ee361e5c3 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java @@ -372,7 +372,7 @@ class MessageOutputStream extends OutputStream { public void close() throws IOException { if (!_closed.compareAndSet(false,true)) { synchronized (_dataLock) { _dataLock.notifyAll(); } - LogUtil.logCloseLoop(_log, "MOS"); + _log.logCloseLoop("MOS"); return; } // setting _closed before flush() will force flush() to send a CLOSE packet @@ -410,7 +410,7 @@ class MessageOutputStream extends OutputStream { */ public void closeInternal() { if (!_closed.compareAndSet(false,true)) { - LogUtil.logCloseLoop(_log, "close internal"); + _log.logCloseLoop("close internal"); return; } _flusher.cancel(); @@ -501,7 +501,7 @@ class MessageOutputStream extends OutputStream { void destroy() { if (!_closed.compareAndSet(false,true)) { - LogUtil.logCloseLoop(_log, "destroy()"); + _log.logCloseLoop("destroy()"); return; } _flusher.cancel(); diff --git a/core/java/src/net/i2p/util/Log.java b/core/java/src/net/i2p/util/Log.java index 59dd2b38b..57af14316 100644 --- a/core/java/src/net/i2p/util/Log.java +++ b/core/java/src/net/i2p/util/Log.java @@ -184,6 +184,34 @@ public class Log { public boolean shouldLog(int priority) { return priority >= _minPriority; } + + /** + * logs a loop when closing a resource with level INFO + * @param desc vararg description + */ + public void logCloseLoop(Object... desc) { + logCloseLoop(Log.INFO, desc); + } + + /** + * Logs a close loop when closing a resource + * @param desc vararg description of the resource + * @param level level at which to log + */ + public void logCloseLoop(int level, Object... desc) { + if (!shouldLog(level)) + return; + + // catenate all toString()s + String descString = "close() loop in"; + for (Object o : desc) { + descString += " "; + descString += String.valueOf(o); + } + + Exception e = new Exception("check stack trace"); + log(level,descString,e); + } public String getName() { if (_className != null) return _className;