Package org.apache.sshd.server.shell
Class InvertedShellWrapper
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.server.shell.InvertedShellWrapper
- All Implemented Interfaces:
Command
,CommandDirectErrorStreamAware
,CommandDirectInputStreamAware
,CommandDirectOutputStreamAware
,CommandDirectStreamsAware
,CommandLifecycle
,ServerSessionAware
public class InvertedShellWrapper
extends AbstractLoggingBean
implements Command, ServerSessionAware
A shell implementation that wraps an instance of
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.- Author:
- Apache MINA SSHD Project
-
Field Summary
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Constructor Summary
ConstructorDescriptionAuto-allocates anExecutor
in order to create the streams pump thread and uses the defaultCoreModuleProperties.BUFFER_SIZE
InvertedShellWrapper
(InvertedShell shell, int bufferSize) Auto-allocates anExecutor
in order to create the streams pump threadInvertedShellWrapper
(InvertedShell shell, Executor executor, boolean shutdownExecutor, int bufferSize) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy
(ChannelSession channel) This method is called by the SSH server to destroy the command because the client has disconnected somehow.protected boolean
pumpStream
(InputStream in, OutputStream out, byte[] buffer) protected void
void
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
Set the input stream that can be used by the shell to read input.void
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.toString()
-
Constructor Details
-
InvertedShellWrapper
Auto-allocates anExecutor
in order to create the streams pump thread and uses the defaultCoreModuleProperties.BUFFER_SIZE
- Parameters:
shell
- TheInvertedShell
- See Also:
-
InvertedShellWrapper
Auto-allocates anExecutor
in order to create the streams pump thread- Parameters:
shell
- TheInvertedShell
bufferSize
- Buffer size to use - must be above min. size (Byte.SIZE
)- See Also:
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell, Executor executor, boolean shutdownExecutor, int bufferSize) - Parameters:
shell
- TheInvertedShell
executor
- TheExecutor
to use in order to create the streams pump thread. Ifnull
one is auto-allocated and shutdown when wrapper isdestroy()
-ed.shutdownExecutor
- Iftrue
the executor is shut down when shell wrapper isdestroy()
-ed. Ignored if executor service auto-allocatedbufferSize
- Buffer size to use - must be above min. size (Byte.SIZE
)
-
-
Method Details
-
setInputStream
Description copied from interface:CommandDirectInputStreamAware
Set the input stream that can be used by the shell to read input.- Specified by:
setInputStream
in interfaceCommandDirectInputStreamAware
- Parameters:
in
- TheInputStream
used by the shell to read input.
-
setOutputStream
Description copied from interface:CommandDirectOutputStreamAware
Set the output stream that can be used by the shell to write its output.- Specified by:
setOutputStream
in interfaceCommandDirectOutputStreamAware
- Parameters:
out
- TheOutputStream
used by the shell to write its output
-
setErrorStream
Description copied from interface:CommandDirectErrorStreamAware
Set the error stream that can be used by the shell to write its errors.- Specified by:
setErrorStream
in interfaceCommandDirectErrorStreamAware
- Parameters:
err
- TheOutputStream
used by the shell to write its errors
-
setExitCallback
Description copied from interface:Command
Set the callback that the shell has to call when it is closed.- Specified by:
setExitCallback
in interfaceCommand
- Parameters:
callback
- TheExitCallback
to call when shell is closed
-
setSession
- Specified by:
setSession
in interfaceServerSessionAware
- Parameters:
session
- TheServerSession
in which this shell will be executed.
-
start
Description copied from interface:CommandLifecycle
Starts the command execution. All streams must have been set before calling this method. The command should implementRunnable
, and this method should spawn a new thread like:Thread(this).start();
- Specified by:
start
in interfaceCommandLifecycle
- Parameters:
channel
- TheChannelSession
through which the command has been receivedenv
- TheEnvironment
- Throws:
IOException
- If failed to start
-
destroy
Description copied from interface:CommandLifecycle
This method is called by the SSH server to destroy the command because the client has disconnected somehow.- Specified by:
destroy
in interfaceCommandLifecycle
- Parameters:
channel
- TheChannelSession
through which the command has been received- Throws:
Exception
- if failed to destroy
-
pumpStreams
protected void pumpStreams() -
pumpStream
- Throws:
IOException
-
toString
-