com.mindbright.ssh2
public abstract class SSH2Channel extends java.lang.Object
SSH2Connection
.
When implementing a new channel type or implementing an existing one
differently from what available one typically subclasses
SSH2StreamChannel
instead of SSH2Channel
directly
since it implements the notion of streams (through use of
java.io.InputStream
and java.io.OutputStream
) and
flow control. Only a very specific implementation of a channel would need to
subclass SSH2Channel
directly.
SSH2Connection
,
SSH2StreamChannel
Modifier and Type | Field and Description |
---|---|
protected int |
channelId |
protected int |
channelType |
protected java.util.Vector<SSH2ChannelCloseListener> |
closeListeners |
protected boolean |
closeReceived |
protected boolean |
closeSent |
protected SSH2Connection |
connection |
protected java.lang.Object |
creator |
protected boolean |
deleted |
protected boolean |
eofReceived |
protected boolean |
eofSent |
protected java.lang.Object |
openMonitor |
protected int |
openStatus |
protected int |
peerChanId |
protected long |
rxCurrWinSz |
protected long |
rxInitWinSz |
protected long |
rxMaxPktSz |
static int |
STATUS_CLOSED |
static int |
STATUS_FAILED |
static int |
STATUS_OPEN |
static int |
STATUS_UNDEFINED |
protected long |
txCurrWinSz |
protected long |
txInitWinSz |
protected long |
txMaxPktSz |
Modifier | Constructor and Description |
---|---|
protected |
SSH2Channel(int channelType,
SSH2Connection connection,
java.lang.Object creator,
boolean pty)
Create a new channel of the given type.
|
Modifier and Type | Method and Description |
---|---|
void |
addCloseListener(SSH2ChannelCloseListener closeListener)
Add a listener which is notified when the channel is closed.
|
void |
close()
Close the channel.
|
protected abstract void |
closeImpl()
Channel specific handler for the recipent of a channel close message.
|
protected void |
data(SSH2TransportPDU pdu)
Handle incoming data on the channel.
|
protected abstract void |
eofImpl()
Channel specific handler for the recipent of an EOF.
|
protected void |
extData(SSH2TransportPDU pdu)
Handle incoming extended data on the channel.
|
int |
getChannelId()
Get the local id of the channel.
|
SSH2Connection |
getConnection()
Get the connection a channel is using.
|
java.lang.Object |
getCreator()
Get the channel creator object reference.
|
int |
getPeerId()
Get the peer if of the channel.
|
java.lang.String |
getType()
Get the type of channel.
|
protected void |
handleRequest(SSH2TransportPDU pdu)
Handle incoming channel request.
|
protected abstract void |
handleRequestImpl(java.lang.String reqType,
boolean wantReply,
SSH2TransportPDU pdu)
Channel specific handler for incoming channel requests.
|
protected void |
init(int peerChanId,
long txInitWinSz,
long txMaxPktSz) |
protected void |
openConfirmation(SSH2TransportPDU pdu)
Handle the open confirmation packet from the transport layer.
|
protected abstract void |
openConfirmationImpl(SSH2TransportPDU pdu)
Channel specific handling of open confirmations.
|
protected void |
openFailure(int reasonCode,
java.lang.String reasonText,
java.lang.String langTag)
Called when the channel open failed.
|
protected abstract boolean |
openFailureImpl(int reasonCode,
java.lang.String reasonText,
java.lang.String langTag)
Channel specific handling of open failures.
|
int |
openStatus()
Checks if the channel currently is open or not.
|
protected void |
recvClose()
Handle the recipent of an channel close message.
|
protected void |
recvEOF()
Handle the recipent of an EOF.
|
void |
removeCloseListener(SSH2ChannelCloseListener closeListener)
Remove a listener which were to be notified when the channel
were closed.
|
protected void |
requestFailure(SSH2TransportPDU pdu)
Handle negative request response.
|
protected void |
requestSuccess(SSH2TransportPDU pdu)
Handle positive request response.
|
protected void |
sendClose()
Send a channel close request.
|
protected void |
sendEOF()
Send channel EOF.
|
protected void |
transmit(SSH2TransportPDU pdu) |
void |
waitUntilClosed(int timeout)
Wait until the channel is closed.
|
protected void |
windowAdjust(SSH2TransportPDU pdu)
Handle a window adjust message.
|
protected abstract void |
windowAdjustImpl(long inc)
Channel specific implementation of window adjust messages.
|
public static final int STATUS_UNDEFINED
public static final int STATUS_OPEN
public static final int STATUS_CLOSED
public static final int STATUS_FAILED
protected SSH2Connection connection
protected java.util.Vector<SSH2ChannelCloseListener> closeListeners
protected int channelType
protected int channelId
protected int peerChanId
protected long rxMaxPktSz
protected long rxInitWinSz
protected long rxCurrWinSz
protected long txInitWinSz
protected long txCurrWinSz
protected long txMaxPktSz
protected volatile boolean eofSent
protected volatile boolean eofReceived
protected volatile boolean closeReceived
protected volatile boolean closeSent
protected volatile boolean deleted
protected java.lang.Object creator
protected final java.lang.Object openMonitor
protected int openStatus
protected SSH2Channel(int channelType, SSH2Connection connection, java.lang.Object creator, boolean pty)
channelType
- Type of channel to create. Channel types are
defined in SSH2Connection
and
starts with CH_TYPE
.connection
- The ssh connection to associate the channel with.creator
- The object the channel is created from.pty
- If pty will be allocated for this sessionprotected final void openConfirmation(SSH2TransportPDU pdu)
pdu
- Confirmation packet.protected final void openFailure(int reasonCode, java.lang.String reasonText, java.lang.String langTag)
reasonCode
- Code which tells why the open failed. See the
ssh protocol drafts for values.reasonText
- A text explaining why the open failed.langTag
- Tag identifying the language of the reason text.protected final void windowAdjust(SSH2TransportPDU pdu)
pdu
- The window adjust packet.protected void data(SSH2TransportPDU pdu)
pdu
- The data packet.protected void extData(SSH2TransportPDU pdu)
pdu
- The data packet.protected final void handleRequest(SSH2TransportPDU pdu)
pdu
- The request packet.protected void requestSuccess(SSH2TransportPDU pdu)
pdu
- The response packet.protected void requestFailure(SSH2TransportPDU pdu)
pdu
- The response packet.protected final void recvEOF()
protected final void recvClose()
protected final void sendEOF()
protected final void sendClose()
protected void init(int peerChanId, long txInitWinSz, long txMaxPktSz)
protected void transmit(SSH2TransportPDU pdu)
public int openStatus()
STATUS_OPEN
,
STATUS_CLOSED
or STATUS_FAILED
public void waitUntilClosed(int timeout)
timeout
- maximum time to wait in millisecondspublic final void close()
public java.lang.String getType()
public int getChannelId()
public int getPeerId()
public java.lang.Object getCreator()
public SSH2Connection getConnection()
protected abstract void openConfirmationImpl(SSH2TransportPDU pdu)
pdu
- Confirmation packet.protected abstract boolean openFailureImpl(int reasonCode, java.lang.String reasonText, java.lang.String langTag)
reasonCode
- Code which tells why the open failed. See the
ssh protocol drafts for values.reasonText
- A text explaining why the open failed.langTag
- Tag identifying the language of the reason text.protected abstract void windowAdjustImpl(long inc)
inc
- The amount to increase the window with.protected abstract void eofImpl()
protected abstract void closeImpl()
protected abstract void handleRequestImpl(java.lang.String reqType, boolean wantReply, SSH2TransportPDU pdu)
reqType
- The type of request.wantReply
- True if an reply is expected.pdu
- The actual channel request.public final void addCloseListener(SSH2ChannelCloseListener closeListener)
closeListener
- The listener to add.public void removeCloseListener(SSH2ChannelCloseListener closeListener)
closeListener
- The listener to remove.