Better naming for some AbstractChannel's lock/event members

This commit is contained in:
Shikhar Bhushan
2012-06-06 22:51:25 +01:00
parent a50962ba2f
commit b44631ea97
3 changed files with 22 additions and 22 deletions

View File

@@ -81,11 +81,11 @@ public abstract class AbstractChannel
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>(); private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();
/* The lock used by to create the open & close events */ /* The lock used by to create the open & close events */
private final ReentrantLock lock = new ReentrantLock(); private final ReentrantLock openCloseLock = new ReentrantLock();
/** Channel open event */ /** Channel open event */
protected final Event<ConnectionException> open; protected final Event<ConnectionException> openEvent;
/** Channel close event */ /** Channel close event */
protected final Event<ConnectionException> close; protected final Event<ConnectionException> closeEvent;
/* Access to these fields should be synchronized using this object */ /* Access to these fields should be synchronized using this object */
private boolean eofSent; private boolean eofSent;
@@ -114,8 +114,8 @@ public abstract class AbstractChannel
lwin = new Window.Local(conn.getWindowSize(), conn.getMaxPacketSize()); lwin = new Window.Local(conn.getWindowSize(), conn.getMaxPacketSize());
in = new ChannelInputStream(this, trans, lwin); in = new ChannelInputStream(this, trans, lwin);
open = new Event<ConnectionException>("chan#" + id + " / " + "open", ConnectionException.chainer, lock); openEvent = new Event<ConnectionException>("chan#" + id + " / " + "open", ConnectionException.chainer, openCloseLock);
close = new Event<ConnectionException>("chan#" + id + " / " + "close", ConnectionException.chainer, lock); closeEvent = new Event<ConnectionException>("chan#" + id + " / " + "close", ConnectionException.chainer, openCloseLock);
} }
protected void init(int recipient, long remoteWinSize, long remoteMaxPacketSize) { protected void init(int recipient, long remoteWinSize, long remoteMaxPacketSize) {
@@ -238,7 +238,7 @@ public abstract class AbstractChannel
public void notifyError(SSHException error) { public void notifyError(SSHException error) {
log.debug("Channel #{} got notified of {}", getID(), error.toString()); log.debug("Channel #{} got notified of {}", getID(), error.toString());
ErrorDeliveryUtil.alertEvents(error, open, close); ErrorDeliveryUtil.alertEvents(error, openEvent, closeEvent);
ErrorDeliveryUtil.alertEvents(error, chanReqResponseEvents); ErrorDeliveryUtil.alertEvents(error, chanReqResponseEvents);
in.notifyError(error); in.notifyError(error);
@@ -256,28 +256,28 @@ public abstract class AbstractChannel
@Override @Override
public void close() public void close()
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
lock.lock(); openCloseLock.lock();
try { try {
try { try {
sendClose(); sendClose();
} catch (TransportException e) { } catch (TransportException e) {
if (!close.inError()) if (!closeEvent.inError())
throw e; throw e;
} }
close.await(conn.getTimeout(), TimeUnit.SECONDS); closeEvent.await(conn.getTimeout(), TimeUnit.SECONDS);
} finally { } finally {
lock.unlock(); openCloseLock.unlock();
} }
} }
public void join() public void join()
throws ConnectionException { throws ConnectionException {
close.await(); closeEvent.await();
} }
public void join(int timeout, TimeUnit unit) public void join(int timeout, TimeUnit unit)
throws ConnectionException { throws ConnectionException {
close.await(timeout, unit); closeEvent.await(timeout, unit);
} }
protected synchronized void sendClose() protected synchronized void sendClose()
@@ -294,11 +294,11 @@ public abstract class AbstractChannel
@Override @Override
public synchronized boolean isOpen() { public synchronized boolean isOpen() {
lock.lock(); openCloseLock.lock();
try { try {
return open.isSet() && !close.isSet() && !closeRequested; return openEvent.isSet() && !closeEvent.isSet() && !closeRequested;
} finally { } finally {
lock.unlock(); openCloseLock.unlock();
} }
} }
@@ -329,7 +329,7 @@ public abstract class AbstractChannel
protected void finishOff() { protected void finishOff() {
conn.forget(this); conn.forget(this);
close.set(); closeEvent.set();
} }
protected void gotExtendedData(SSHPacket buf) protected void gotExtendedData(SSHPacket buf)

View File

@@ -65,7 +65,7 @@ public abstract class AbstractDirectChannel
public void open() public void open()
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
trans.write(buildOpenReq()); trans.write(buildOpenReq());
open.await(conn.getTimeout(), TimeUnit.SECONDS); openEvent.await(conn.getTimeout(), TimeUnit.SECONDS);
} }
private void gotOpenConfirmation(SSHPacket buf) private void gotOpenConfirmation(SSHPacket buf)
@@ -75,13 +75,13 @@ public abstract class AbstractDirectChannel
} catch (Buffer.BufferException be) { } catch (Buffer.BufferException be) {
throw new ConnectionException(be); throw new ConnectionException(be);
} }
open.set(); openEvent.set();
} }
private void gotOpenFailure(SSHPacket buf) private void gotOpenFailure(SSHPacket buf)
throws ConnectionException { throws ConnectionException {
try { try {
open.deliverError(new OpenFailException(getType(), buf.readUInt32AsInt(), buf.readString())); openEvent.deliverError(new OpenFailException(getType(), buf.readUInt32AsInt(), buf.readString()));
} catch (Buffer.BufferException be) { } catch (Buffer.BufferException be) {
throw new ConnectionException(be); throw new ConnectionException(be);
} }

View File

@@ -73,7 +73,7 @@ public abstract class AbstractForwardedChannel
.putUInt32(getID()) .putUInt32(getID())
.putUInt32(getLocalWinSize()) .putUInt32(getLocalWinSize())
.putUInt32(getLocalMaxPacketSize())); .putUInt32(getLocalMaxPacketSize()));
open.set(); openEvent.set();
} }
@Override @Override