com.mindbright.ssh2
Class SSH2StreamChannel

java.lang.Object
  extended by com.mindbright.ssh2.SSH2Channel
      extended by com.mindbright.ssh2.SSH2StreamChannel
All Implemented Interfaces:
NIOCallback
Direct Known Subclasses:
SSH2InternalChannel, SSH2ProcChannel, SSH2TCPChannel

public class SSH2StreamChannel
extends SSH2Channel
implements NIOCallback

Class implementing streams-based channels. That is channels which locally are connected to a pair of Input/Output streams. It is also possible to apply filters to the channels.


Field Summary
protected  java.io.InputStream in
           
protected  Log log
           
protected  NonBlockingInput nbin
           
protected  NonBlockingOutput nbout
           
protected  java.io.OutputStream out
           
protected  java.lang.Thread receiver
           
protected  long rxCounter
           
protected  Queue rxQueue
           
protected  java.lang.Thread transmitter
           
protected  long txCounter
           
 
Fields inherited from class com.mindbright.ssh2.SSH2Channel
channelId, channelType, closeListeners, closeReceived, closeSent, connection, creator, deleted, eofReceived, eofSent, openMonitor, openStatus, peerChanId, rxCurrWinSz, rxInitWinSz, rxMaxPktSz, STATUS_CLOSED, STATUS_FAILED, STATUS_OPEN, STATUS_UNDEFINED, txCurrWinSz, txInitWinSz, txMaxPktSz
 
Constructor Summary
protected SSH2StreamChannel(int channelType, SSH2Connection connection, java.lang.Object creator)
           
protected SSH2StreamChannel(int channelType, SSH2Connection connection, java.lang.Object creator, java.io.InputStream in, java.io.OutputStream out)
          Create a new stream channel of the given type.
protected SSH2StreamChannel(int channelType, SSH2Connection connection, java.lang.Object creator, NonBlockingInput in, NonBlockingOutput out)
           
protected SSH2StreamChannel(int channelType, SSH2Connection connection, java.lang.Object creator, java.net.Socket s)
           
 
Method Summary
 void applyFilter(SSH2StreamFilter filter)
          Apply the given filter to this channel.
protected  void checkRxWindowSize(int len)
           
protected  void closeImpl()
          Channel specific handler for the recipent of a channel close message.
 void completed(java.nio.ByteBuffer buf)
          Called once the network read operation has been completed
 void connected(boolean timeout)
          Called once the connection has been established (assuming interest for this has been registered by calling the NotifyWhenConnected method of Switchboard).
 void connectionFailed(java.lang.Exception e)
          Called if the connection failed (assuming interest for this has been registered by calling the NotifyWhenConnected method of Switchboard).
protected  void createStreams()
          Create the transmitter and receiver threads.
protected  void data(SSH2TransportPDU pdu)
          Handle incoming data on the channel.
protected  void eofImpl()
          Channel specific handler for the recipent of an EOF.
protected  void handleRequestImpl(java.lang.String type, boolean wantReply, SSH2TransportPDU pdu)
          Channel specific handler for incoming channel requests.
protected  void openConfirmationImpl(SSH2TransportPDU pdu)
          Channel specific handling of open confirmations.
protected  boolean openFailureImpl(int reasonCode, java.lang.String reasonText, java.lang.String langTag)
          Channel specific handling of open failures.
protected  void outputClosed()
          Called when no more data can be written to the channel.
 void readFailed(java.lang.Exception e)
          Called if the read failed
protected  void startStreams()
          Starts the transmitter and receiver threads.
 void waitUntilClosed()
           
 void waitUntilClosed(int timeout)
          Wait until the channel is closed.
protected  void windowAdjustImpl(long inc)
          Channel specific implementation of window adjust messages.
 void writeFailed()
          Called if the write failed
 
Methods inherited from class com.mindbright.ssh2.SSH2Channel
addCloseListener, close, extData, getChannelId, getConnection, getCreator, getPeerId, getType, handleRequest, init, openConfirmation, openFailure, openStatus, recvClose, recvEOF, removeCloseListener, requestFailure, requestSuccess, sendClose, sendEOF, transmit, windowAdjust
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.InputStream in

out

protected java.io.OutputStream out

nbin

protected NonBlockingInput nbin

nbout

protected NonBlockingOutput nbout

transmitter

protected java.lang.Thread transmitter

receiver

protected java.lang.Thread receiver

rxQueue

protected Queue rxQueue

txCounter

protected long txCounter

rxCounter

protected long rxCounter

log

protected Log log
Constructor Detail

SSH2StreamChannel

protected SSH2StreamChannel(int channelType,
                            SSH2Connection connection,
                            java.lang.Object creator)

SSH2StreamChannel

protected SSH2StreamChannel(int channelType,
                            SSH2Connection connection,
                            java.lang.Object creator,
                            java.io.InputStream in,
                            java.io.OutputStream out)
Create a new stream channel of the given type. The channel is associated with an ssh connection. Channel types are defined in SSH2Connection and starts with CH_TYPE.

Parameters:
channelType - Type of channel to create.
connection - The ssh connection to associate the channel with.
creator - The object the channel is created from.
in - The input stream from which data to be sent over the channel is read.
out - The output stream onto which data received from the channel is written.

SSH2StreamChannel

protected SSH2StreamChannel(int channelType,
                            SSH2Connection connection,
                            java.lang.Object creator,
                            java.net.Socket s)
                     throws java.io.IOException
Throws:
java.io.IOException

SSH2StreamChannel

protected SSH2StreamChannel(int channelType,
                            SSH2Connection connection,
                            java.lang.Object creator,
                            NonBlockingInput in,
                            NonBlockingOutput out)
Method Detail

applyFilter

public void applyFilter(SSH2StreamFilter filter)
Apply the given filter to this channel. Filters are not yet supported on non-blocking channels.

Parameters:
filter - Filter to apply.

checkRxWindowSize

protected final void checkRxWindowSize(int len)

data

protected void data(SSH2TransportPDU pdu)
Description copied from class: SSH2Channel
Handle incoming data on the channel.

Overrides:
data in class SSH2Channel
Parameters:
pdu - The data packet.

openConfirmationImpl

protected void openConfirmationImpl(SSH2TransportPDU pdu)
Description copied from class: SSH2Channel
Channel specific handling of open confirmations.

Specified by:
openConfirmationImpl in class SSH2Channel
Parameters:
pdu - Confirmation packet.

openFailureImpl

protected boolean openFailureImpl(int reasonCode,
                                  java.lang.String reasonText,
                                  java.lang.String langTag)
Description copied from class: SSH2Channel
Channel specific handling of open failures.

Specified by:
openFailureImpl in class SSH2Channel
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 void windowAdjustImpl(long inc)
Description copied from class: SSH2Channel
Channel specific implementation of window adjust messages.

Specified by:
windowAdjustImpl in class SSH2Channel
Parameters:
inc - The amount to increase the window with.

eofImpl

protected void eofImpl()
Description copied from class: SSH2Channel
Channel specific handler for the recipent of an EOF.

Specified by:
eofImpl in class SSH2Channel

closeImpl

protected void closeImpl()
Description copied from class: SSH2Channel
Channel specific handler for the recipent of a channel close message.

Specified by:
closeImpl in class SSH2Channel

outputClosed

protected void outputClosed()
Called when no more data can be written to the channel.


handleRequestImpl

protected void handleRequestImpl(java.lang.String type,
                                 boolean wantReply,
                                 SSH2TransportPDU pdu)
Description copied from class: SSH2Channel
Channel specific handler for incoming channel requests.

Specified by:
handleRequestImpl in class SSH2Channel
Parameters:
type - The type of request.
wantReply - True if an reply is expected.
pdu - The actual channel request.

createStreams

protected void createStreams()
Create the transmitter and receiver threads.


startStreams

protected void startStreams()
Starts the transmitter and receiver threads.


waitUntilClosed

public void waitUntilClosed(int timeout)
Description copied from class: SSH2Channel
Wait until the channel is closed.

Overrides:
waitUntilClosed in class SSH2Channel
Parameters:
timeout - maximum time to wait in milliseconds

waitUntilClosed

public void waitUntilClosed()

completed

public void completed(java.nio.ByteBuffer buf)
Description copied from interface: NIOCallback
Called once the network read operation has been completed

Specified by:
completed in interface NIOCallback
Parameters:
buf - the buffer provided to the read call

readFailed

public void readFailed(java.lang.Exception e)
Description copied from interface: NIOCallback
Called if the read failed

Specified by:
readFailed in interface NIOCallback

writeFailed

public void writeFailed()
Description copied from interface: NIOCallback
Called if the write failed

Specified by:
writeFailed in interface NIOCallback

connected

public void connected(boolean timeout)
Description copied from interface: NIOCallback
Called once the connection has been established (assuming interest for this has been registered by calling the NotifyWhenConnected method of Switchboard).

Specified by:
connected in interface NIOCallback
Parameters:
timeout - true if the connection attempt timed out

connectionFailed

public void connectionFailed(java.lang.Exception e)
Description copied from interface: NIOCallback
Called if the connection failed (assuming interest for this has been registered by calling the NotifyWhenConnected method of Switchboard).

Specified by:
connectionFailed in interface NIOCallback
Parameters:
e - the exception the connection failed with.