com.mindbright.ssh2
Class SSH2Channel

java.lang.Object
  extended bycom.mindbright.ssh2.SSH2Channel
Direct Known Subclasses:
SSH2StreamChannel

public abstract class SSH2Channel
extends java.lang.Object

This is the abstract base class for all channels as defined in the connection protocol spec. Each channel has a specific type (e.g. session). Each channel type is implemented by a subclass to this class. This base class makes no assumptions as to how data is handled by the channel it only implements methods which are used from the multiplexing code in 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.

See Also:
SSH2Connection, SSH2StreamChannel

Field Summary
protected  int channelId
           
protected  int channelType
           
protected  java.util.Vector 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  int rxCurrWinSz
           
protected  int rxInitWinSz
           
protected  int rxMaxPktSz
           
static int STATUS_CLOSED
           
static int STATUS_FAILED
           
static int STATUS_OPEN
           
static int STATUS_UNDEFINED
           
protected  int txCurrWinSz
           
protected  int txInitWinSz
           
protected  int txMaxPktSz
           
 
Constructor Summary
protected SSH2Channel(int channelType, SSH2Connection connection, java.lang.Object creator)
          Create a new channel of the given type.
 
Method Summary
 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, int txInitWinSz, int 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()
          Wait until the channel is closed.
protected  void windowAdjust(SSH2TransportPDU pdu)
          Handle a window adjust message.
protected abstract  void windowAdjustImpl(int inc)
          Channel specific implementation of window adjust messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_UNDEFINED

public static final int STATUS_UNDEFINED
See Also:
Constant Field Values

STATUS_OPEN

public static final int STATUS_OPEN
See Also:
Constant Field Values

STATUS_CLOSED

public static final int STATUS_CLOSED
See Also:
Constant Field Values

STATUS_FAILED

public static final int STATUS_FAILED
See Also:
Constant Field Values

connection

protected SSH2Connection connection

closeListeners

protected java.util.Vector closeListeners

channelType

protected int channelType

channelId

protected int channelId

peerChanId

protected int peerChanId

rxMaxPktSz

protected int rxMaxPktSz

rxInitWinSz

protected int rxInitWinSz

rxCurrWinSz

protected int rxCurrWinSz

txInitWinSz

protected int txInitWinSz

txCurrWinSz

protected int txCurrWinSz

txMaxPktSz

protected int txMaxPktSz

eofSent

protected volatile boolean eofSent

eofReceived

protected volatile boolean eofReceived

closeReceived

protected volatile boolean closeReceived

closeSent

protected volatile boolean closeSent

deleted

protected volatile boolean deleted

creator

protected java.lang.Object creator

openMonitor

protected final java.lang.Object openMonitor

openStatus

protected int openStatus
Constructor Detail

SSH2Channel

protected SSH2Channel(int channelType,
                      SSH2Connection connection,
                      java.lang.Object creator)
Create a new channel of the given type. The channel is associated with an ssh connections.

Parameters:
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.
Method Detail

openConfirmation

protected final void openConfirmation(SSH2TransportPDU pdu)
Handle the open confirmation packet from the transport layer.

Parameters:
pdu - Confirmation packet.

openFailure

protected final void openFailure(int reasonCode,
                                 java.lang.String reasonText,
                                 java.lang.String langTag)
Called when the channel open failed.

Parameters:
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.

windowAdjust

protected final void windowAdjust(SSH2TransportPDU pdu)
Handle a window adjust message.

Parameters:
pdu - The window adjust packet.

data

protected void data(SSH2TransportPDU pdu)
Handle incoming data on the channel.

Parameters:
pdu - The data packet.

extData

protected void extData(SSH2TransportPDU pdu)
Handle incoming extended data on the channel.

Parameters:
pdu - The data packet.

handleRequest

protected final void handleRequest(SSH2TransportPDU pdu)
Handle incoming channel request.

Parameters:
pdu - The request packet.

requestSuccess

protected void requestSuccess(SSH2TransportPDU pdu)
Handle positive request response.

Parameters:
pdu - The response packet.

requestFailure

protected void requestFailure(SSH2TransportPDU pdu)
Handle negative request response.

Parameters:
pdu - The response packet.

recvEOF

protected final void recvEOF()
Handle the recipent of an EOF.


recvClose

protected final void recvClose()
Handle the recipent of an channel close message.


sendEOF

protected final void sendEOF()
Send channel EOF.


sendClose

protected final void sendClose()
Send a channel close request.


init

protected void init(int peerChanId,
                    int txInitWinSz,
                    int txMaxPktSz)

transmit

protected void transmit(SSH2TransportPDU pdu)

openStatus

public int openStatus()
Checks if the channel currently is open or not.

Returns:
The status. One of STATUS_OPEN, STATUS_CLOSED or STATUS_FAILED

waitUntilClosed

public void waitUntilClosed()
Wait until the channel is closed.


close

public final void close()
Close the channel.


getType

public java.lang.String getType()
Get the type of channel.

Returns:
The channel type.

getChannelId

public int getChannelId()
Get the local id of the channel.

Returns:
The local channel id.

getPeerId

public int getPeerId()
Get the peer if of the channel.

Returns:
The peer channel id.

getCreator

public java.lang.Object getCreator()
Get the channel creator object reference.

Returns:
The channel creator.

getConnection

public SSH2Connection getConnection()
Get the connection a channel is using.

Returns:
The connection object.

openConfirmationImpl

protected abstract void openConfirmationImpl(SSH2TransportPDU pdu)
Channel specific handling of open confirmations.

Parameters:
pdu - Confirmation packet.

openFailureImpl

protected abstract boolean openFailureImpl(int reasonCode,
                                           java.lang.String reasonText,
                                           java.lang.String langTag)
Channel specific handling of open failures.

Parameters:
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.

windowAdjustImpl

protected abstract void windowAdjustImpl(int inc)
Channel specific implementation of window adjust messages.

Parameters:
inc - The amount to increase the window with.

eofImpl

protected abstract void eofImpl()
Channel specific handler for the recipent of an EOF.


closeImpl

protected abstract void closeImpl()
Channel specific handler for the recipent of a channel close message.


handleRequestImpl

protected abstract void handleRequestImpl(java.lang.String reqType,
                                          boolean wantReply,
                                          SSH2TransportPDU pdu)
Channel specific handler for incoming channel requests.

Parameters:
reqType - The type of request.
wantReply - True if an reply is expected.
pdu - The actual channel request.

addCloseListener

public final void addCloseListener(SSH2ChannelCloseListener closeListener)
Add a listener which is notified when the channel is closed.

Parameters:
closeListener - The listener to add.

removeCloseListener

public void removeCloseListener(SSH2ChannelCloseListener closeListener)
Remove a listener which were to be notified when the channel were closed.

Parameters:
closeListener - The listener to remove.