Class ExampleSession

java.lang.Object
  extended by com.maverick.sshd.Channel
      extended by com.maverick.sshd.SessionChannel
          extended by ExampleSession
All Implemented Interfaces:
IdleStateListener

public class ExampleSession
extends SessionChannel

If your server is to support an interactive shell or the execution of commands you need to implement this abstract class and set your class in the ConfigurationContext. context.setSessionProvider(ExampleSession.class); This example session will simply echo all input until the 'exit' command is received.

Author:
Lee David Painter

Nested Class Summary
 
Nested classes/interfaces inherited from class com.maverick.sshd.Channel
Channel.QueuedData
 
Field Summary
 
Fields inherited from class com.maverick.sshd.SessionChannel
MAX_WINDOW_SPACE, MIN_WINDOW_SPACE
 
Fields inherited from class com.maverick.sshd.Channel
connection, localwindow, localWindowLock
 
Constructor Summary
ExampleSession()
           
 
Method Summary
protected  boolean allocatePseudoTerminal(String term, int cols, int rows, int width, int height, byte[] encoded)
          The client requested that a pty (pseudo terminal) is allocated for the session
protected  void changeWindowDimensions(int cols, int rows, int width, int height)
          Change the dimensions of the terminal window.
protected  boolean executeCommand(String cmd)
          The user has requested the execution of a command.
protected  void onChannelClosed()
          The channel has been closed.
protected  void onLocalEOF()
          The local side has sent an EOF message.
protected  void onSessionOpen()
          The session has now been opened.
protected  void processSignal(String signal)
          Process a signal sent by the client.
protected  void processStderrData(byte[] data)
          Process stderr data.
protected  void processStdinData(byte[] data)
          Process stdin data.
protected  boolean setEnvironmentVariable(String name, String value)
          Set an environment variable
protected  boolean startShell()
          The user has requested that the session start an interactive shell.
 
Methods inherited from class com.maverick.sshd.SessionChannel
createChannel, evaluateWindowSpace, haltIncomingData, idle, onChannelClosing, onChannelData, onChannelFree, onChannelOpen, onChannelOpenConfirmation, onChannelRequest, onExtendedData, onRemoteEOF, openChannel, resumeIncomingData, sendChannelDataWithBuffering, sendExitStatus, sendStderrData, sendStderrData, sendStdoutData, sendStdoutData
 
Methods inherited from class com.maverick.sshd.Channel
addEventListener, addInputListener, addOutputListener, canClose, clearIdleState, close, getChannelType, getConnection, getContext, getLocalId, getLocalPacket, getLocalWindow, getQueueSize, getRemoteId, getRemotePacket, getRemoteWindow, getSessionIdentifier, hasQueuedData, isClosed, isClosing, isEOF, isOpen, onChannelOpenFailure, onRemoteClose, onWindowAdjust, queueSize, registerExtendedData, removeEventListener, resetIdleState, sendChannelData, sendChannelData, sendChannelData, sendChannelData, sendChannelDataWithBuffering, sendChannelRequest, sendEOF, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExampleSession

public ExampleSession()
Method Detail

processStdinData

protected void processStdinData(byte[] data)
Process stdin data. This is data sent from the client to the server.

Specified by:
processStdinData in class SessionChannel
Parameters:
data -

processStderrData

protected void processStderrData(byte[] data)
Process stderr data. This is not something that happens as the stderr stream goes from server to client; however since the extended data types work in both directions we have to provide a method. This will never be called in real life.

Parameters:
data -

onChannelClosed

protected void onChannelClosed()
The channel has been closed. Perform any cleanup operations in here however you cannot send any data now that the channel has been closed.

Specified by:
onChannelClosed in class Channel

executeCommand

protected boolean executeCommand(String cmd)
The user has requested the execution of a command.

Specified by:
executeCommand in class SessionChannel
Parameters:
cmd -
Returns:

changeWindowDimensions

protected void changeWindowDimensions(int cols,
                                      int rows,
                                      int width,
                                      int height)
Change the dimensions of the terminal window.

Specified by:
changeWindowDimensions in class SessionChannel
Parameters:
cols -
rows -
width -
height -

onSessionOpen

protected void onSessionOpen()
The session has now been opened. This is called after the command or shell has been executed. i.e. after executeCommand(java.lang.String) or startShell()

Specified by:
onSessionOpen in class SessionChannel

onLocalEOF

protected void onLocalEOF()
The local side has sent an EOF message. No more data can be sent to the remote side.

Specified by:
onLocalEOF in class Channel

startShell

protected boolean startShell()
The user has requested that the session start an interactive shell.

Specified by:
startShell in class SessionChannel
Returns:
true if the shell has been started

allocatePseudoTerminal

protected boolean allocatePseudoTerminal(String term,
                                         int cols,
                                         int rows,
                                         int width,
                                         int height,
                                         byte[] encoded)
The client requested that a pty (pseudo terminal) is allocated for the session

Specified by:
allocatePseudoTerminal in class SessionChannel
Parameters:
term - the terminal type
cols - the number of columns in characters
rows - the number of rows in characters
width - the width in pixels (informational only)
height - the heigh in pixels( informational only)
encoded - encoded terminal modes
Returns:

processSignal

protected void processSignal(String signal)
Process a signal sent by the client.

Specified by:
processSignal in class SessionChannel
Parameters:
signal -

setEnvironmentVariable

protected boolean setEnvironmentVariable(String name,
                                         String value)
Set an environment variable

Specified by:
setEnvironmentVariable in class SessionChannel
Parameters:
name -
value -
Returns:


Copyright © 2012. All Rights Reserved.