com.mindbright.ssh2
Class SSH2SessionChannel

java.lang.Object
  extended by com.mindbright.ssh2.SSH2Channel
      extended by com.mindbright.ssh2.SSH2StreamChannel
          extended by com.mindbright.ssh2.SSH2InternalChannel
              extended by com.mindbright.ssh2.SSH2SessionChannel

public final class SSH2SessionChannel
extends SSH2InternalChannel

This class implements session channels as defined in the connection protocol spec. It can be used to start shells, commands, and subsystems on the server. An instance of this class is created with the newSession methods found in SSH2Connection.

See Also:
SSH2Channel, SSH2Connection

Field Summary
protected  boolean blocking
           
static int EXIT_ON_CLOSE
           
static int EXIT_ON_FAILURE
           
protected  boolean exited
           
protected  boolean exitedOnSignal
           
protected  java.lang.Object exitMonitor
           
protected  int exitStatus
           
protected  java.lang.Object reqMonitor
           
protected  int reqStatus
           
protected  boolean started
           
protected  InputStreamPipe stderr
           
protected  java.io.OutputStream stderrW
           
protected  boolean x11Mapping
           
 
Fields inherited from class com.mindbright.ssh2.SSH2InternalChannel
rxPipe, txPipe
 
Fields inherited from class com.mindbright.ssh2.SSH2StreamChannel
in, out, receiver, rxCounter, rxQueue, transmitter, 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 SSH2SessionChannel(SSH2Connection connection)
           
 
Method Summary
 void changeStdErr(java.io.OutputStream stderrW)
           
 void changeStdIn(java.io.InputStream in)
           
 void changeStdOut(java.io.OutputStream out)
           
protected  void closeImpl()
          Channel specific handler for the recipent of a channel close message.
 boolean doBreak(int length)
           
 void doExit(int status)
           
 void doExit(int status, boolean onSignal)
           
 void doExit(int status, boolean onSignal, java.lang.String signal)
           
 boolean doShell()
          Launch the users shell in this session
 boolean doSingleCommand(java.lang.String command)
          Launch a single command in this session
 boolean doSubsystem(java.lang.String subsystem)
          Launch a subsystem
 void enableStdErr()
           
protected  void extData(SSH2TransportPDU pdu)
          Handle incoming extended data on the channel.
 java.io.InputStream getStdErr()
           
 java.io.OutputStream getStdIn()
           
 java.io.InputStream getStdOut()
           
protected  void handleRequestImpl(java.lang.String type, boolean wantReply, SSH2TransportPDU pdu)
          Channel specific handler for incoming channel requests.
 boolean isFinished()
          Checks if the last command has already finished.
protected  boolean openFailureImpl(int reasonCode, java.lang.String reasonText, java.lang.String langTag)
          Channel specific handling of open failures.
protected  void requestFailure(SSH2TransportPDU pdu)
          Handle negative request response.
 boolean requestPTY(java.lang.String termType, int rows, int cols, byte[] terminalModes)
           
protected  void requestSuccess(SSH2TransportPDU pdu)
          Handle positive request response.
 boolean requestX11Forward(boolean single, int screen)
           
 boolean requestX11Forward(boolean single, int screen, byte[] cookie)
           
 boolean requestX11Forward(java.lang.String localAddr, int localPort, byte[] cookie, boolean single, int screen)
           
 void sendSignal(java.lang.String signal)
           
 void sendWindowChange(int rows, int cols)
           
 void setBlocking(boolean value)
           
 boolean setEnvironment(java.lang.String name, java.lang.String value)
           
 void stdinWriteNoLatency(byte[] buf, int off, int len)
           
 void stdinWriteNoLatency(int c)
           
 void stdinWriteNoLatency(java.lang.String str)
           
 int waitForExit()
          Wait for the last command to finish.
 int waitForExit(long timeout)
          Wait for the last command to exit but return after the specified time has passed even if the command has not exited.
 
Methods inherited from class com.mindbright.ssh2.SSH2InternalChannel
getInputStream, getOutputStream
 
Methods inherited from class com.mindbright.ssh2.SSH2StreamChannel
applyFilter, checkRxWindowSize, createStreams, data, eofImpl, openConfirmationImpl, outputClosed, startStreams, waitUntilClosed, windowAdjustImpl
 
Methods inherited from class com.mindbright.ssh2.SSH2Channel
addCloseListener, close, getChannelId, getConnection, getCreator, getPeerId, getType, handleRequest, init, openConfirmation, openFailure, openStatus, recvClose, recvEOF, removeCloseListener, sendClose, sendEOF, transmit, windowAdjust
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXIT_ON_CLOSE

public static final int EXIT_ON_CLOSE
See Also:
Constant Field Values

EXIT_ON_FAILURE

public static final int EXIT_ON_FAILURE
See Also:
Constant Field Values

started

protected boolean started

blocking

protected boolean blocking

exited

protected boolean exited

exitMonitor

protected java.lang.Object exitMonitor

reqMonitor

protected java.lang.Object reqMonitor

exitedOnSignal

protected boolean exitedOnSignal

exitStatus

protected int exitStatus

reqStatus

protected int reqStatus

x11Mapping

protected boolean x11Mapping

stderr

protected InputStreamPipe stderr

stderrW

protected java.io.OutputStream stderrW
Constructor Detail

SSH2SessionChannel

protected SSH2SessionChannel(SSH2Connection connection)
Method Detail

doShell

public boolean doShell()
Launch the users shell in this session

Returns:
true if the shell was started and false of failure

doSingleCommand

public boolean doSingleCommand(java.lang.String command)
Launch a single command in this session

Returns:
true if the command was started and false of failure

doSubsystem

public boolean doSubsystem(java.lang.String subsystem)
Launch a subsystem

Returns:
true if the subsystem was started and false of failure

doBreak

public boolean doBreak(int length)

waitForExit

public int waitForExit()
Wait for the last command to finish. There is no timeout with this call.


waitForExit

public int waitForExit(long timeout)
Wait for the last command to exit but return after the specified time has passed even if the command has not exited.

Parameters:
timeout - how long to wait in milliseconds
Returns:
the exit status of the command if it has finished. This value is random if the call timed out. See the isFinished() method to help determine which is the case.

isFinished

public boolean isFinished()
Checks if the last command has already finished. This can be used with the waitForExit(long timeout) method to know if that method has exited because the command was finished or because a the timeout.


changeStdOut

public void changeStdOut(java.io.OutputStream out)

changeStdIn

public void changeStdIn(java.io.InputStream in)

changeStdErr

public void changeStdErr(java.io.OutputStream stderrW)

enableStdErr

public void enableStdErr()

getStdOut

public java.io.InputStream getStdOut()

getStdIn

public java.io.OutputStream getStdIn()

getStdErr

public java.io.InputStream getStdErr()

stdinWriteNoLatency

public void stdinWriteNoLatency(java.lang.String str)

stdinWriteNoLatency

public void stdinWriteNoLatency(byte[] buf,
                                int off,
                                int len)

stdinWriteNoLatency

public void stdinWriteNoLatency(int c)

setBlocking

public void setBlocking(boolean value)

requestPTY

public boolean requestPTY(java.lang.String termType,
                          int rows,
                          int cols,
                          byte[] terminalModes)

requestX11Forward

public boolean requestX11Forward(java.lang.String localAddr,
                                 int localPort,
                                 byte[] cookie,
                                 boolean single,
                                 int screen)

requestX11Forward

public boolean requestX11Forward(boolean single,
                                 int screen)

requestX11Forward

public boolean requestX11Forward(boolean single,
                                 int screen,
                                 byte[] cookie)

setEnvironment

public boolean setEnvironment(java.lang.String name,
                              java.lang.String value)

sendWindowChange

public void sendWindowChange(int rows,
                             int cols)

sendSignal

public void sendSignal(java.lang.String signal)

doExit

public void doExit(int status)

doExit

public void doExit(int status,
                   boolean onSignal)

doExit

public void doExit(int status,
                   boolean onSignal,
                   java.lang.String signal)

extData

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

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

closeImpl

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

Overrides:
closeImpl in class SSH2StreamChannel

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.

Overrides:
openFailureImpl in class SSH2StreamChannel
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.

requestSuccess

protected void requestSuccess(SSH2TransportPDU pdu)
Description copied from class: SSH2Channel
Handle positive request response.

Overrides:
requestSuccess in class SSH2Channel
Parameters:
pdu - The response packet.

requestFailure

protected void requestFailure(SSH2TransportPDU pdu)
Description copied from class: SSH2Channel
Handle negative request response.

Overrides:
requestFailure in class SSH2Channel
Parameters:
pdu - The response packet.

handleRequestImpl

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

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