| Method from com.sshtools.j2ssh.connection.Channel Detail: |
public void addEventListener(ChannelEventListener eventListener) {
eventListeners.add(eventListener);
}
|
public void close() throws IOException {
synchronized (state) {
if (isOpen()) {
if ((connection != null) && !localHasClosed &&
connection.isConnected()) {
connection.closeChannel(this);
}
localHasClosed = true;
if (log.isDebugEnabled()) {
log.debug("Connection is " +
((connection == null) ? "null"
: (connection.isConnected()
? "connected" : "not connected")));
}
if (remoteHasClosed ||
((connection == null) || !connection.isConnected())) {
log.info("Finializing channel close");
finalizeClose();
}
}
}
}
|
protected void finalizeClose() throws IOException {
synchronized (state) {
state.setValue(ChannelState.CHANNEL_CLOSED);
onChannelClose();
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onChannelClose(this);
}
}
if (connection != null) {
connection.freeChannel(this);
}
}
}
|
abstract public byte[] getChannelConfirmationData()
|
abstract public byte[] getChannelOpenData()
|
abstract public String getChannelType()
|
public long getLocalChannelId() {
return localChannelId;
}
|
public long getLocalPacketSize() {
return localPacketSize;
}
|
public ChannelDataWindow getLocalWindow() {
return localWindow;
}
|
abstract protected int getMaximumPacketSize()
|
abstract protected int getMaximumWindowSpace()
|
abstract protected int getMinimumWindowSpace()
|
public String getName() {
return name;
}
|
public long getRemoteChannelId() {
return remoteChannelId;
}
|
public long getRemotePacketSize() {
return remotePacketSize;
}
|
public ChannelDataWindow getRemoteWindow() {
return remoteWindow;
}
|
public ChannelState getState() {
return state;
}
|
protected void init(ConnectionProtocol connection,
long localChannelId,
long senderChannelId,
long initialWindowSize,
long maximumPacketSize) throws IOException {
this.localChannelId = localChannelId;
this.remoteChannelId = senderChannelId;
this.remotePacketSize = maximumPacketSize;
this.remoteWindow.increaseWindowSpace(initialWindowSize);
this.connection = connection;
synchronized (state) {
state.setValue(ChannelState.CHANNEL_OPEN);
}
}
|
protected void init(ConnectionProtocol connection,
long localChannelId,
long senderChannelId,
long initialWindowSize,
long maximumPacketSize,
ChannelEventListener eventListener) throws IOException {
if (eventListener != null) {
addEventListener(eventListener);
}
init(connection, localChannelId, senderChannelId, initialWindowSize,
maximumPacketSize);
}
|
public boolean isClosed() {
synchronized (state) {
return state.getValue() == ChannelState.CHANNEL_CLOSED;
}
}
|
public boolean isLocalEOF() {
return isLocalEOF;
}
|
public boolean isOpen() {
synchronized (state) {
return state.getValue() == ChannelState.CHANNEL_OPEN;
}
}
|
public boolean isRemoteEOF() {
return isRemoteEOF;
}
|
abstract protected void onChannelClose() throws IOException
|
abstract protected void onChannelData(SshMsgChannelData msg) throws IOException
|
abstract protected void onChannelEOF() throws IOException
|
abstract protected void onChannelExtData(SshMsgChannelExtendedData msg) throws IOException
|
abstract protected void onChannelOpen() throws IOException
|
abstract protected void onChannelRequest(String requestType,
boolean wantReply,
byte[] requestData) throws IOException
|
protected void open() throws IOException {
synchronized (state) {
state.setValue(ChannelState.CHANNEL_OPEN);
onChannelOpen();
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onChannelOpen(this);
}
}
}
}
|
protected void processChannelData(SshMsgChannelData msg) throws IOException {
synchronized (state) {
if (!isClosed()) {
if (msg.getChannelDataLength() > localWindow.getWindowSpace()) {
throw new IOException(
"More data recieved than is allowed by the channel data window [" +
name + "]");
}
long windowSpace = localWindow.consumeWindowSpace(msg.getChannelData().length);
if (windowSpace < getMinimumWindowSpace()) {
if (log.isDebugEnabled()) {
log.debug("Channel " + String.valueOf(localChannelId) +
" requires more window space [" + name + "]");
}
windowSpace = getMaximumWindowSpace() - windowSpace;
log.debug("Requesting connection protocol increase window");
connection.sendChannelWindowAdjust(this, windowSpace);
localWindow.increaseWindowSpace(windowSpace);
}
onChannelData(msg);
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onDataReceived(this, msg.getChannelData());
}
}
} else {
throw new IOException(
"Channel data received but channel is closed [" + name +
"]");
}
}
}
|
protected void processChannelData(SshMsgChannelExtendedData msg) throws IOException {
synchronized (state) {
if (msg.getChannelData().length > localWindow.getWindowSpace()) {
throw new IOException(
"More data recieved than is allowed by the channel data window [" +
name + "]");
}
long windowSpace = localWindow.consumeWindowSpace(msg.getChannelData().length);
if (windowSpace < getMinimumWindowSpace()) {
if (log.isDebugEnabled()) {
log.debug("Channel " + String.valueOf(localChannelId) +
" requires more window space [" + name + "]");
}
windowSpace = getMaximumWindowSpace() - windowSpace;
connection.sendChannelWindowAdjust(this, windowSpace);
localWindow.increaseWindowSpace(windowSpace);
}
onChannelExtData(msg);
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onDataReceived(this, msg.getChannelData());
}
}
}
}
|
protected void remoteClose() throws IOException {
log.info("Remote side is closing channel");
synchronized (state) {
remoteHasClosed = true;
close();
}
}
|
protected void sendChannelData(byte[] data) throws IOException {
if (!connection.isConnected()) {
throw new IOException("The connection has been closed [" + name +
"]");
}
if (!isClosed()) {
connection.sendChannelData(this, data);
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onDataSent(this, data);
}
}
} else {
throw new IOException("The channel is closed [" + name + "]");
}
}
|
protected void sendChannelExtData(int type,
byte[] data) throws IOException {
if (!connection.isConnected()) {
throw new IOException("The connection has been closed [" + name +
"]");
}
if (!isClosed()) {
connection.sendChannelExtData(this, type, data);
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onDataSent(this, data);
}
}
} else {
throw new IOException("The channel is closed [" + name + "]");
}
}
|
public void setLocalEOF() throws IOException {
synchronized (state) {
isLocalEOF = true;
connection.sendChannelEOF(this);
}
}
|
public void setName(String name) {
this.name = name;
}
|
protected void setRemoteEOF() throws IOException {
synchronized (state) {
isRemoteEOF = true;
onChannelEOF();
Iterator it = eventListeners.iterator();
ChannelEventListener eventListener;
while (it.hasNext()) {
eventListener = (ChannelEventListener) it.next();
if (eventListener != null) {
eventListener.onChannelEOF(this);
}
}
}
}
|