public class InvertedShellWrapper extends AbstractLoggingBean implements Command, SessionAware
InvertedShell
as a Command
. This is useful when
using external processes. When starting the shell, this wrapper will also create a thread used to pump the streams
and also to check if the shell is alive.Modifier and Type | Field and Description |
---|---|
private int |
bufferSize |
private ExitCallback |
callback |
static int |
DEFAULT_BUFFER_SIZE
Default buffer size for the I/O pumps.
|
static long |
DEFAULT_PUMP_SLEEP_TIME
Default value for
PUMP_SLEEP_TIME if none set |
private java.io.OutputStream |
err |
private java.util.concurrent.Executor |
executor |
private java.io.InputStream |
in |
private java.io.OutputStream |
out |
static java.lang.String |
PUMP_SLEEP_TIME
Value used to control the "busy-wait" sleep time (millis) on the pumping loop if nothing was pumped -
must be positive
|
private long |
pumpSleepTime |
private InvertedShell |
shell |
private java.io.InputStream |
shellErr |
private java.io.OutputStream |
shellIn |
private java.io.InputStream |
shellOut |
private boolean |
shutdownExecutor |
log
Constructor and Description |
---|
InvertedShellWrapper(InvertedShell shell)
Auto-allocates an
Executor in order to create the streams pump thread and uses the
DEFAULT_BUFFER_SIZE |
InvertedShellWrapper(InvertedShell shell,
java.util.concurrent.Executor executor,
boolean shutdownExecutor,
int bufferSize) |
InvertedShellWrapper(InvertedShell shell,
int bufferSize)
Auto-allocates an
Executor in order to create the streams pump thread |
Modifier and Type | Method and Description |
---|---|
void |
destroy(ChannelSession channel)
This method is called by the SSH server to destroy the command because the client has disconnected somehow.
|
protected boolean |
pumpStream(java.io.InputStream in,
java.io.OutputStream out,
byte[] buffer) |
protected void |
pumpStreams() |
void |
setErrorStream(java.io.OutputStream err)
Set the error stream that can be used by the shell to write its errors.
|
void |
setExitCallback(ExitCallback callback)
Set the callback that the shell has to call when it is closed.
|
void |
setInputStream(java.io.InputStream in)
Set the input stream that can be used by the shell to read input.
|
void |
setOutputStream(java.io.OutputStream out)
Set the output stream that can be used by the shell to write its output.
|
void |
setSession(ServerSession session) |
void |
start(ChannelSession channel,
Environment env)
Starts the command execution.
|
java.lang.String |
toString() |
getSimplifiedLogger
public static final int DEFAULT_BUFFER_SIZE
public static final java.lang.String PUMP_SLEEP_TIME
DEFAULT_PUMP_SLEEP_TIME
,
Constant Field Valuespublic static final long DEFAULT_PUMP_SLEEP_TIME
PUMP_SLEEP_TIME
if none setprivate final InvertedShell shell
private final java.util.concurrent.Executor executor
private final int bufferSize
private java.io.InputStream in
private java.io.OutputStream out
private java.io.OutputStream err
private java.io.OutputStream shellIn
private java.io.InputStream shellOut
private java.io.InputStream shellErr
private ExitCallback callback
private boolean shutdownExecutor
private long pumpSleepTime
public InvertedShellWrapper(InvertedShell shell)
Executor
in order to create the streams pump thread and uses the
DEFAULT_BUFFER_SIZE
shell
- The InvertedShell
InvertedShellWrapper(InvertedShell, int)
public InvertedShellWrapper(InvertedShell shell, int bufferSize)
Executor
in order to create the streams pump threadshell
- The InvertedShell
bufferSize
- Buffer size to use - must be above min. size (Byte.SIZE
)InvertedShellWrapper(InvertedShell, Executor, boolean, int)
public InvertedShellWrapper(InvertedShell shell, java.util.concurrent.Executor executor, boolean shutdownExecutor, int bufferSize)
shell
- The InvertedShell
executor
- The Executor
to use in order to create the streams pump thread. If null
one is auto-allocated and shutdown when wrapper is destroy()
-ed.shutdownExecutor
- If true
the executor is shut down when shell wrapper is destroy()
-ed.
Ignored if executor service auto-allocatedbufferSize
- Buffer size to use - must be above min. size (Byte.SIZE
)public void setInputStream(java.io.InputStream in)
Command
setInputStream
in interface Command
in
- The InputStream
used by the shell to read input.public void setOutputStream(java.io.OutputStream out)
Command
setOutputStream
in interface Command
out
- The OutputStream
used by the shell to write its outputpublic void setErrorStream(java.io.OutputStream err)
Command
setErrorStream
in interface Command
err
- The OutputStream
used by the shell to write its errorspublic void setExitCallback(ExitCallback callback)
Command
setExitCallback
in interface Command
callback
- The ExitCallback
to call when shell is closedpublic void setSession(ServerSession session)
setSession
in interface SessionAware
session
- The ServerSession
in which this shell will be executed.public void start(ChannelSession channel, Environment env) throws java.io.IOException
CommandLifecycle
Runnable
, and this method should spawn a new thread like:
Thread(this).start();
start
in interface CommandLifecycle
channel
- The ChannelSession
through which the command has been receivedenv
- The Environment
java.io.IOException
- If failed to startpublic void destroy(ChannelSession channel) throws java.lang.Exception
CommandLifecycle
destroy
in interface CommandLifecycle
channel
- The ChannelSession
through which the command has been receivedjava.lang.Exception
- if failed to destroyprotected void pumpStreams()
protected boolean pumpStream(java.io.InputStream in, java.io.OutputStream out, byte[] buffer) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object