com.maverick.sshd.platform
Class ExecutableCommand

java.lang.Object
  extended by com.maverick.sshd.platform.ExecutableCommand
Direct Known Subclasses:
NativeExecutableCommand, ScpCommand

public abstract class ExecutableCommand
extends java.lang.Object

This class can be extended to provide a single executable command. Commands are configured in the com.maverick.sshd.ConfigurationContext and they make use of the input/output streams provided to communicate with the client.

Author:
Lee David Painter

Field Summary
protected  SessionChannel session
          The session channel instance on which this command is being executed
protected  java.io.OutputStream stderr
          Write STDERR data to this OutputStream
protected  java.io.InputStream stdin
          Receive STDIN from this InputStream
protected  java.io.OutputStream stdout
          Write STDOUT data to this OutputStream *
static int STILL_ACTIVE
          Value returned from getExitCode() to indicate that the process is still active.
 
Constructor Summary
ExecutableCommand()
           
ExecutableCommand(int incomingBufferSize)
           
 
Method Summary
abstract  boolean createProcess(java.lang.String cmd, java.util.Map environment)
          Create the process but wait for the onStart() method before performing any IO.
abstract  int getExitCode()
          Get the exit code for this process.
 java.io.InputStream getInputStream()
          Get the STDIN InputStream for this process.
 java.io.OutputStream getOutputStream()
          Get the STDOUT OutputStream for this process.
 java.io.OutputStream getStderrOutputStream()
          Get the STDERR OutputStream for this process.
 void init(SessionChannel session)
          Initialize the command.
abstract  void kill()
          Kill the command.
abstract  void onStart()
          Called once the command has been started.
 void processStdinData(byte[] data)
          Called by the session to pass incoming data into the process.
 void start()
          Start the command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STILL_ACTIVE

public static final int STILL_ACTIVE
Value returned from getExitCode() to indicate that the process is still active.

See Also:
Constant Field Values

session

protected SessionChannel session
The session channel instance on which this command is being executed


stdout

protected java.io.OutputStream stdout
Write STDOUT data to this OutputStream *


stderr

protected java.io.OutputStream stderr
Write STDERR data to this OutputStream


stdin

protected java.io.InputStream stdin
Receive STDIN from this InputStream

Constructor Detail

ExecutableCommand

public ExecutableCommand()

ExecutableCommand

public ExecutableCommand(int incomingBufferSize)
Method Detail

init

public void init(SessionChannel session)
Initialize the command. This can be overridden but always call this super method with the command's session.

Parameters:
session -

createProcess

public abstract boolean createProcess(java.lang.String cmd,
                                      java.util.Map environment)
Create the process but wait for the onStart() method before performing any IO.

Parameters:
cmd -
environment -
Returns:
boolean

start

public void start()
Start the command.


onStart

public abstract void onStart()
Called once the command has been started. Operations within this method SHOULD NOT block as this will cause the connection to lockup.


kill

public abstract void kill()
Kill the command.


getExitCode

public abstract int getExitCode()
Get the exit code for this process. If the process has not completed return STILL_ACTIVE.

Returns:
int

getOutputStream

public java.io.OutputStream getOutputStream()
Get the STDOUT OutputStream for this process.

Returns:
OutputStream

getStderrOutputStream

public java.io.OutputStream getStderrOutputStream()
Get the STDERR OutputStream for this process.

Returns:
OutputStream

getInputStream

public java.io.InputStream getInputStream()
Get the STDIN InputStream for this process.

Returns:
InputStream

processStdinData

public void processStdinData(byte[] data)
                      throws java.io.IOException
Called by the session to pass incoming data into the process. This implementation will place the data into the processes InputStream however you may want to change this behaviour by overriding this method. If you override this method DO NOT block.

Parameters:
data -
Throws:
java.io.IOException


Copyright © 2003-2004 3SP LTD. All Rights Reserved.