always use class name for making Loggers

This commit is contained in:
Shikhar Bhushan
2010-07-20 23:39:51 +01:00
parent efc7702195
commit 7874e7dbfd
5 changed files with 18 additions and 24 deletions

View File

@@ -32,8 +32,9 @@ import java.util.concurrent.locks.ReentrantLock;
*/
public class Future<V, T extends Throwable> {
private final Logger log;
private final Logger log = LoggerFactory.getLogger(getClass());
private final String name;
private final ExceptionChainer<T> chainer;
private final ReentrantLock lock;
private final Condition cond;
@@ -60,7 +61,7 @@ public class Future<V, T extends Throwable> {
* @param lock lock to use
*/
public Future(String name, ExceptionChainer<T> chainer, ReentrantLock lock) {
this.log = LoggerFactory.getLogger("<< " + name + " >>");
this.name = name;
this.chainer = chainer;
this.lock = lock == null ? new ReentrantLock() : lock;
this.cond = this.lock.newCondition();
@@ -74,7 +75,7 @@ public class Future<V, T extends Throwable> {
public void set(V val) {
lock();
try {
log.debug("Setting to `{}`", val);
log.debug("Setting <<{}>> to `{}`", name, val);
this.val = val;
cond.signalAll();
} finally {
@@ -139,14 +140,14 @@ public class Future<V, T extends Throwable> {
throw pendingEx;
if (val != null)
return val;
log.debug("Awaiting");
log.debug("Awaiting <<{}>>", name);
while (val == null && pendingEx == null)
if (timeout == 0)
cond.await();
else if (!cond.await(timeout, unit))
throw chainer.chain(new TimeoutException("Timeout expired"));
if (pendingEx != null) {
log.error("Woke to: {}", pendingEx.toString());
log.error("<<{}>> woke to: {}", name, pendingEx.toString());
throw pendingEx;
}
return val;

View File

@@ -86,7 +86,7 @@ public class StreamCopier
return sb.toString();
}
private final Logger log;
private final Logger log = LoggerFactory.getLogger(getClass());
private final InputStream in;
private final OutputStream out;
@@ -103,9 +103,7 @@ public class StreamCopier
public StreamCopier(String name, InputStream in, OutputStream out) {
this.in = in;
this.out = out;
setName("streamCopier");
log = LoggerFactory.getLogger(name);
setName(name);
}
public StreamCopier bufSize(int size) {

View File

@@ -62,7 +62,7 @@ public abstract class AbstractChannel
implements Channel {
/** Logger */
protected final Logger log;
protected final Logger log = LoggerFactory.getLogger(getClass());
/** Transport layer */
protected final Transport trans;
@@ -109,9 +109,7 @@ public abstract class AbstractChannel
id = conn.nextID();
log = LoggerFactory.getLogger("chan#" + id);
lwin = new Window.Local(id, conn.getWindowSize(), conn.getMaxPacketSize());
lwin = new Window.Local(conn.getWindowSize(), conn.getMaxPacketSize());
in = new ChannelInputStream(this, trans, lwin);
open = new Event<ConnectionException>("chan#" + id + " / " + "open", ConnectionException.chainer, lock);
@@ -120,7 +118,7 @@ public abstract class AbstractChannel
protected void init(int recipient, int remoteWinSize, int remoteMaxPacketSize) {
this.recipient = recipient;
rwin = new Window.Remote(id, remoteWinSize, remoteMaxPacketSize);
rwin = new Window.Remote(remoteWinSize, remoteMaxPacketSize);
out = new ChannelOutputStream(this, trans, rwin);
log.info("Initialized - {}", this);
}

View File

@@ -59,7 +59,7 @@ public final class ChannelInputStream
extends InputStream
implements ErrorNotifiable {
private final Logger log;
private final Logger log = LoggerFactory.getLogger(getClass());
private final Channel chan;
private final Transport trans;
@@ -71,8 +71,6 @@ public final class ChannelInputStream
private SSHException error;
public ChannelInputStream(Channel chan, Transport trans, Window.Local win) {
log = LoggerFactory.getLogger("<< chan#" + chan.getID() + " / input stream >>");
this.chan = chan;
this.trans = trans;
this.win = win;

View File

@@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
public abstract class Window {
protected final Logger log;
protected final Logger log = LoggerFactory.getLogger(getClass());
protected final Object lock = new Object();
@@ -30,8 +30,7 @@ public abstract class Window {
protected int size;
public Window(int chanID, String kindOfWindow, int initialWinSize, int maxPacketSize) {
log = LoggerFactory.getLogger("<< chan#" + chanID + " / " + kindOfWindow + " >>");
public Window(int initialWinSize, int maxPacketSize) {
size = initialWinSize;
this.maxPacketSize = maxPacketSize;
}
@@ -70,8 +69,8 @@ public abstract class Window {
public static final class Remote
extends Window {
public Remote(int chanID, int initialWinSize, int maxPacketSize) {
super(chanID, "remote win", initialWinSize, maxPacketSize);
public Remote(int initialWinSize, int maxPacketSize) {
super(initialWinSize, maxPacketSize);
}
public void waitAndConsume(int howMuch)
@@ -98,8 +97,8 @@ public abstract class Window {
private final int initialSize;
private final int threshold;
public Local(int chanID, int initialWinSize, int maxPacketSize) {
super(chanID, "local win", initialWinSize, maxPacketSize);
public Local(int initialWinSize, int maxPacketSize) {
super(initialWinSize, maxPacketSize);
this.initialSize = initialWinSize;
threshold = Math.min(maxPacketSize * 20, initialSize / 4);
}