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 ofInvertedShellas aCommand. 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
Constructors Constructor Description InvertedShellWrapper(InvertedShell shell)Auto-allocates anExecutorin order to create the streams pump thread and uses the defaultCoreModuleProperties.BUFFER_SIZEInvertedShellWrapper(InvertedShell shell, int bufferSize)Auto-allocates anExecutorin order to create the streams pump threadInvertedShellWrapper(InvertedShell shell, Executor executor, boolean shutdownExecutor, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy(ChannelSession channel)This method is called by the SSH server to destroy the command because the client has disconnected somehow.protected booleanpumpStream(InputStream in, OutputStream out, byte[] buffer)protected voidpumpStreams()voidsetErrorStream(OutputStream err)Set the error stream that can be used by the shell to write its errors.voidsetExitCallback(ExitCallback callback)Set the callback that the shell has to call when it is closed.voidsetInputStream(InputStream in)Set the input stream that can be used by the shell to read input.voidsetOutputStream(OutputStream out)Set the output stream that can be used by the shell to write its output.voidsetSession(ServerSession session)voidstart(ChannelSession channel, Environment env)Starts the command execution.StringtoString()
-
-
-
Constructor Detail
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell)
Auto-allocates anExecutorin order to create the streams pump thread and uses the defaultCoreModuleProperties.BUFFER_SIZE- Parameters:
shell- TheInvertedShell- See Also:
InvertedShellWrapper(InvertedShell, int)
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell, int bufferSize)
Auto-allocates anExecutorin order to create the streams pump thread- Parameters:
shell- TheInvertedShellbufferSize- Buffer size to use - must be above min. size (Byte.SIZE)- See Also:
InvertedShellWrapper(InvertedShell, Executor, boolean, int)
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell, Executor executor, boolean shutdownExecutor, int bufferSize)
- Parameters:
shell- TheInvertedShellexecutor- TheExecutorto use in order to create the streams pump thread. Ifnullone is auto-allocated and shutdown when wrapper isdestroy()-ed.shutdownExecutor- Iftruethe 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 Detail
-
setInputStream
public void setInputStream(InputStream in)
Description copied from interface:CommandDirectInputStreamAwareSet the input stream that can be used by the shell to read input.- Specified by:
setInputStreamin interfaceCommandDirectInputStreamAware- Parameters:
in- TheInputStreamused by the shell to read input.
-
setOutputStream
public void setOutputStream(OutputStream out)
Description copied from interface:CommandDirectOutputStreamAwareSet the output stream that can be used by the shell to write its output.- Specified by:
setOutputStreamin interfaceCommandDirectOutputStreamAware- Parameters:
out- TheOutputStreamused by the shell to write its output
-
setErrorStream
public void setErrorStream(OutputStream err)
Description copied from interface:CommandDirectErrorStreamAwareSet the error stream that can be used by the shell to write its errors.- Specified by:
setErrorStreamin interfaceCommandDirectErrorStreamAware- Parameters:
err- TheOutputStreamused by the shell to write its errors
-
setExitCallback
public void setExitCallback(ExitCallback callback)
Description copied from interface:CommandSet the callback that the shell has to call when it is closed.- Specified by:
setExitCallbackin interfaceCommand- Parameters:
callback- TheExitCallbackto call when shell is closed
-
setSession
public void setSession(ServerSession session)
- Specified by:
setSessionin interfaceServerSessionAware- Parameters:
session- TheServerSessionin which this shell will be executed.
-
start
public void start(ChannelSession channel, Environment env) throws IOException
Description copied from interface:CommandLifecycleStarts 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:
startin interfaceCommandLifecycle- Parameters:
channel- TheChannelSessionthrough which the command has been receivedenv- TheEnvironment- Throws:
IOException- If failed to start
-
destroy
public void destroy(ChannelSession channel) throws Exception
Description copied from interface:CommandLifecycleThis method is called by the SSH server to destroy the command because the client has disconnected somehow.- Specified by:
destroyin interfaceCommandLifecycle- Parameters:
channel- TheChannelSessionthrough which the command has been received- Throws:
Exception- if failed to destroy
-
pumpStreams
protected void pumpStreams()
-
pumpStream
protected boolean pumpStream(InputStream in, OutputStream out, byte[] buffer) throws IOException
- Throws:
IOException
-
-