public abstract class SessionChannel extends Channel implements IdleStateListener
This class provides an abstract session, it handles all the requests defined in the SSH Connection protocol for a session channel and passes the request to the concrete implementation through its abstract methods.
When creating a session implementation your processStdinData(byte[])
will receive data from the client and process as session input. To send
stdout data for your session you should use the
sendStdoutData(byte[])
method and any sdterr output should be send
using sendStderrData(byte[])
method.
As the server uses an asynchronous framework expensive blocking operations SHOULD NOT be performed within your session as this will cause a deadlock on the server.
The basic process of establishing a session is this
sendExitStatus(int)
.Channel.DataBlock, Channel.QueuedData
Modifier and Type | Field and Description |
---|---|
static String |
CHANNEL_TYPE |
protected int |
maximumWindowSpace |
protected int |
minimumWindowSpace |
static int |
SSH_EXTENDED_DATA_STDERR |
connection, localwindow, localWindowLock
Constructor and Description |
---|
SessionChannel() |
SessionChannel(int maximumPacket,
int maximumWindowSpace) |
SessionChannel(int maximumPacket,
int maximumWindowSpace,
int minimumWindowSpace) |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
allocatePseudoTerminal(String term,
int cols,
int rows,
int width,
int height,
byte[] modes)
If the client requests a pseudo terminal for the session this method will
be invoked before the shell, exec or subsystem is started.
|
protected abstract void |
changeWindowDimensions(int cols,
int rows,
int width,
int height)
When the window (terminal) size changes on the client side, it MAY send
notification in which case this method will be invoked to notify the
session that a change has occurred.
|
protected void |
close(boolean forceClose)
This method closes the channel and free's its resources.
|
protected byte[] |
createChannel()
Called when the channel is being created.
|
protected void |
evaluateWindowSpace(int remaining)
Called to evaluate the window space available.
|
protected abstract boolean |
executeCommand(String cmd)
Invoked when the user wants to execute a command
|
protected void |
executeTask(ConnectionAwareTask task) |
int |
getMaximumWindowSpace() |
int |
getMinimumWindowSpace() |
Subsystem |
getSubsystem() |
void |
haltIncomingData() |
boolean |
idle()
Process an idle event.
|
boolean |
isAgentForwardingRequested() |
boolean |
isIncomingDataHalted() |
protected void |
onChannelClosing()
Called when the channel is closing.
|
protected void |
onChannelData(byte[] data)
Called when data arrives on the channel.
|
protected void |
onChannelFree()
Free the session and its resources.
|
protected void |
onChannelOpen()
Called once the channel has been opened.
|
protected void |
onChannelOpenConfirmation()
Called when the channel is confirmed as open
|
protected void |
onChannelRequest(String type,
boolean wantreply,
byte[] requestdata)
Process session requests and invoke the relevant abstract methods of this
class to handle the requests.
|
protected void |
onExtendedData(byte[] data,
int type)
Called when extended data arrives on the channel - for a session channel
this would not normally be called.
|
protected void |
onRemoteEOF()
The remote side has reported EOF so no more data will be received.
|
protected abstract void |
onSessionOpen()
Called once the session is open and data can be sent/received.
|
protected byte[] |
openChannel(byte[] data)
Called when the channel is being opened.
|
protected abstract void |
processSignal(String signal)
A signal can be delivered to the process by the client.
|
protected abstract void |
processStdinData(byte[] data)
Data has arrived on the session's stdin stream.
|
protected boolean |
requestAgentForwarding(String requestType)
Implement this method to support agent forwarding.
|
void |
resumeIncomingData() |
void |
sendExitStatus(int exitcode)
When a command or shell exits its possible to send the client the exit
code of the process.
|
void |
sendStderrData(byte[] data)
Send stderr data to the remote client.
|
void |
sendStderrData(byte[] data,
int off,
int len)
Sends stderr data to the remote client.
|
void |
sendStdoutData(byte[] data)
Sends stdout data to the remote client
|
void |
sendStdoutData(byte[] data,
int off,
int len)
Sends stdout data to the remote client.
|
protected abstract boolean |
setEnvironmentVariable(String name,
String value)
If the client requests that an environment variable be set this method
will be invoked.
|
void |
setMaximumWindowSpace(int maximumWindowSpace) |
void |
setMinimumWindowSpace(int minimumWindowSpace) |
protected abstract boolean |
startShell()
Invoked when the user wants to start a shell.
|
protected boolean |
startSubsystem(String name) |
addEventListener, addInputListener, addOutputListener, canClose, clearIdleState, close, consumeWindowSpace, createCloseTask, getChannelType, getConnection, getContext, getLocalId, getLocalPacket, getLocalWindow, getQueueSize, getRemoteId, getRemotePacket, getRemoteWindow, getSessionIdentifier, isClosed, isClosing, isEOF, isOpen, isSelfManagedWindowSpace, markEOF, onChannelClosed, onChannelOpenFailure, onLocalEOF, onRemoteClose, onWindowAdjust, queueSize, registerExtendedData, resetIdleState, sendChannelData, sendChannelData, sendChannelData, sendChannelData, sendChannelDataAndBlock, sendChannelRequest, sendEOF, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust
protected int maximumWindowSpace
protected int minimumWindowSpace
public static final int SSH_EXTENDED_DATA_STDERR
public static final String CHANNEL_TYPE
public SessionChannel()
public SessionChannel(int maximumPacket, int maximumWindowSpace)
public SessionChannel(int maximumPacket, int maximumWindowSpace, int minimumWindowSpace)
public Subsystem getSubsystem()
protected final byte[] createChannel() throws IOException
Channel
createChannel
in class Channel
IOException
protected abstract boolean allocatePseudoTerminal(String term, int cols, int rows, int width, int height, byte[] modes)
term
- cols
- rows
- width
- height
- modes
- protected abstract void changeWindowDimensions(int cols, int rows, int width, int height)
cols
- rows
- width
- height
- protected abstract void processSignal(String signal)
signal
- protected abstract boolean setEnvironmentVariable(String name, String value)
name
- value
- protected abstract boolean startShell()
protected abstract boolean executeCommand(String cmd)
cmd
- protected abstract void processStdinData(byte[] data)
data
- protected abstract void onSessionOpen()
protected void onChannelOpen()
onChannelOpen
in class Channel
public boolean isAgentForwardingRequested()
public boolean idle()
IdleStateListener
idle
in interface IdleStateListener
protected void onChannelRequest(String type, boolean wantreply, byte[] requestdata)
onChannelRequest
in class Channel
type
- Stringwantreply
- booleanrequestdata
- byte[]protected boolean requestAgentForwarding(String requestType)
protected boolean startSubsystem(String name) throws IOException
IOException
protected void onChannelOpenConfirmation()
onChannelOpenConfirmation
in class Channel
protected void onRemoteEOF()
onRemoteEOF
in class Channel
protected void executeTask(ConnectionAwareTask task)
executeTask
in class Channel
protected void close(boolean forceClose)
Channel
protected void onChannelFree()
onChannelFree
in class Channel
protected void onChannelClosing()
onChannelClosing
in class Channel
protected void onChannelData(byte[] data)
onChannelData
in class Channel
data
- byte[]protected void onExtendedData(byte[] data, int type)
onExtendedData
in class Channel
data
- byte[]type
- intpublic void sendStdoutData(byte[] data, int off, int len)
data
- off
- len
- public void sendStdoutData(byte[] data)
data
- public void sendStderrData(byte[] data, int off, int len)
data
- off
- len
- public void sendStderrData(byte[] data)
data
- public void sendExitStatus(int exitcode)
exitcode
- protected final void evaluateWindowSpace(int remaining)
Channel
evaluateWindowSpace
in class Channel
public boolean isIncomingDataHalted()
public void haltIncomingData()
public void resumeIncomingData()
protected final byte[] openChannel(byte[] data) throws WriteOperationRequest, ChannelOpenException
Channel
openChannel
in class Channel
WriteOperationRequest
ChannelOpenException
public int getMaximumWindowSpace()
public void setMaximumWindowSpace(int maximumWindowSpace)
public int getMinimumWindowSpace()
public void setMinimumWindowSpace(int minimumWindowSpace)
Copyright © 2024. All rights reserved.