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
,CommandLifecycle
,SessionAware
public class InvertedShellWrapper extends AbstractLoggingBean implements Command, SessionAware
A shell implementation that wraps an instance ofInvertedShell
as 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.
-
-
Field Summary
Fields Modifier and Type Field Description private int
bufferSize
private ExitCallback
callback
private java.io.OutputStream
err
private java.util.concurrent.Executor
executor
private java.io.InputStream
in
private java.io.OutputStream
out
private java.time.Duration
pumpSleepTime
private InvertedShell
shell
private java.io.InputStream
shellErr
private java.io.OutputStream
shellIn
private java.io.InputStream
shellOut
private boolean
shutdownExecutor
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description InvertedShellWrapper(InvertedShell shell)
Auto-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, java.util.concurrent.Executor executor, boolean shutdownExecutor, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Field Detail
-
shell
private final InvertedShell shell
-
executor
private final java.util.concurrent.Executor executor
-
bufferSize
private int bufferSize
-
pumpSleepTime
private java.time.Duration pumpSleepTime
-
in
private java.io.InputStream in
-
out
private java.io.OutputStream out
-
err
private java.io.OutputStream err
-
shellIn
private java.io.OutputStream shellIn
-
shellOut
private java.io.InputStream shellOut
-
shellErr
private java.io.InputStream shellErr
-
callback
private ExitCallback callback
-
shutdownExecutor
private boolean shutdownExecutor
-
-
Constructor Detail
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell)
Auto-allocates anExecutor
in 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 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(InvertedShell, Executor, boolean, int)
-
InvertedShellWrapper
public InvertedShellWrapper(InvertedShell shell, java.util.concurrent.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 Detail
-
setInputStream
public void setInputStream(java.io.InputStream in)
Description copied from interface:Command
Set the input stream that can be used by the shell to read input.- Specified by:
setInputStream
in interfaceCommand
- Parameters:
in
- TheInputStream
used by the shell to read input.
-
setOutputStream
public void setOutputStream(java.io.OutputStream out)
Description copied from interface:Command
Set the output stream that can be used by the shell to write its output.- Specified by:
setOutputStream
in interfaceCommand
- Parameters:
out
- TheOutputStream
used by the shell to write its output
-
setErrorStream
public void setErrorStream(java.io.OutputStream err)
Description copied from interface:Command
Set the error stream that can be used by the shell to write its errors.- Specified by:
setErrorStream
in interfaceCommand
- Parameters:
err
- TheOutputStream
used by the shell to write its errors
-
setExitCallback
public void setExitCallback(ExitCallback callback)
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
public void setSession(ServerSession session)
- Specified by:
setSession
in interfaceSessionAware
- Parameters:
session
- TheServerSession
in which this shell will be executed.
-
start
public void start(ChannelSession channel, Environment env) throws java.io.IOException
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:
java.io.IOException
- If failed to start
-
destroy
public void destroy(ChannelSession channel) throws java.lang.Exception
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:
java.lang.Exception
- if failed to destroy
-
pumpStreams
protected void pumpStreams()
-
pumpStream
protected boolean pumpStream(java.io.InputStream in, java.io.OutputStream out, byte[] buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-