mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
AbstractChannel - make chanReqResponseEvents a ConcurrentLinkedQueue, so don't have to have sendChannelRequest() & gotResponse() as synchronized methods. #27
This commit is contained in:
@@ -53,8 +53,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public abstract class AbstractChannel
|
|||||||
/** Remote recipient ID */
|
/** Remote recipient ID */
|
||||||
private int recipient;
|
private int recipient;
|
||||||
|
|
||||||
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();
|
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new ConcurrentLinkedQueue<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 lock = new ReentrantLock();
|
||||||
@@ -364,7 +364,7 @@ public abstract class AbstractChannel
|
|||||||
stream.receive(buf.array(), buf.rpos(), len);
|
stream.receive(buf.array(), buf.rpos(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized Event<ConnectionException> sendChannelRequest(String reqType, boolean wantReply,
|
protected Event<ConnectionException> sendChannelRequest(String reqType, boolean wantReply,
|
||||||
Buffer.PlainBuffer reqSpecific)
|
Buffer.PlainBuffer reqSpecific)
|
||||||
throws TransportException {
|
throws TransportException {
|
||||||
log.info("Sending channel request for `{}`", reqType);
|
log.info("Sending channel request for `{}`", reqType);
|
||||||
@@ -383,7 +383,7 @@ public abstract class AbstractChannel
|
|||||||
return responseEvent;
|
return responseEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void gotResponse(boolean success)
|
private void gotResponse(boolean success)
|
||||||
throws ConnectionException {
|
throws ConnectionException {
|
||||||
final Event<ConnectionException> responseEvent = chanReqResponseEvents.poll();
|
final Event<ConnectionException> responseEvent = chanReqResponseEvents.poll();
|
||||||
if (responseEvent != null) {
|
if (responseEvent != null) {
|
||||||
@@ -392,8 +392,7 @@ public abstract class AbstractChannel
|
|||||||
else
|
else
|
||||||
responseEvent.deliverError(new ConnectionException("Request failed"));
|
responseEvent.deliverError(new ConnectionException("Request failed"));
|
||||||
} else
|
} else
|
||||||
throw new ConnectionException(
|
throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR,
|
||||||
DisconnectReason.PROTOCOL_ERROR,
|
|
||||||
"Received response to channel request when none was requested");
|
"Received response to channel request when none was requested");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user