Top Description Fields Constructors Methods
org.apache.sshd.server.shell

public Class InvertedShellWrapper

extends AbstractLoggingBean
implements Command, ServerSessionAware
Class Inheritance
All Implemented Interfaces
org.apache.sshd.server.session.ServerSessionAware, org.apache.sshd.server.command.Command, org.apache.sshd.server.command.CommandDirectStreamsAware, org.apache.sshd.server.command.CommandDirectErrorStreamAware, org.apache.sshd.server.command.CommandDirectOutputStreamAware, org.apache.sshd.server.command.CommandDirectInputStreamAware, org.apache.sshd.server.command.CommandLifecycle
Imports
java.io.IOException, .InputStream, .OutputStream, java.time.Duration, java.util.Objects, java.util.concurrent.Executor, .ExecutorService, org.apache.sshd.common.RuntimeSshException, org.apache.sshd.common.util.ExceptionUtils, .GenericUtils, .ValidateUtils, org.apache.sshd.common.util.logging.AbstractLoggingBean, org.apache.sshd.common.util.threads.ThreadUtils, org.apache.sshd.core.CoreModuleProperties, org.apache.sshd.server.Environment, .ExitCallback, org.apache.sshd.server.channel.ChannelSession, org.apache.sshd.server.command.Command, org.apache.sshd.server.session.ServerSession, .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

Modifier and TypeField and Description
private int
private ExitCallback
private OutputStream
private final Executor
private InputStream
private OutputStream
private Duration
private final InvertedShell
private InputStream
private OutputStream
private InputStream
private boolean
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
log

Constructor Summary

AccessConstructor and Description
public
InvertedShellWrapper(InvertedShell shell)

Auto-allocates an Executor in order to create the streams pump thread and uses the default CoreModuleProperties#BUFFER_SIZE

public
InvertedShellWrapper(InvertedShell shell, int
Buffer size to use - must be above min. size (Byte#SIZE)
bufferSize
)

Auto-allocates an Executor in order to create the streams pump thread

public
InvertedShellWrapper(InvertedShell shell, 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.
executor
,
boolean
If true the executor is shut down when shell wrapper is destroy()-ed. Ignored if executor service auto-allocated
shutdownExecutor
,
int
Buffer size to use - must be above min. size (Byte#SIZE)
bufferSize
)

Method Summary

Modifier and TypeMethod and Description
public synchronized void
destroy(ChannelSession
The ChannelSession through which the command has been received
channel
)

Implements org.apache.sshd.server.command.CommandLifecycle.destroy.

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
public void
setErrorStream(OutputStream
The OutputStream used by the shell to write its errors
err
)

Implements org.apache.sshd.server.command.CommandDirectErrorStreamAware.setErrorStream.

Set the error stream that can be used by the shell to write its errors.

public void
setExitCallback(ExitCallback
The ExitCallback to call when shell is closed
callback
)

Implements org.apache.sshd.server.command.Command.setExitCallback.

Set the callback that the shell has to call when it is closed.

public void
setInputStream(InputStream
The InputStream used by the shell to read input.
in
)

Implements org.apache.sshd.server.command.CommandDirectInputStreamAware.setInputStream.

Set the input stream that can be used by the shell to read input.

public void
setOutputStream(OutputStream
The OutputStream used by the shell to write its output
out
)

Implements org.apache.sshd.server.command.CommandDirectOutputStreamAware.setOutputStream.

Set the output stream that can be used by the shell to write its output.

public void
setSession(ServerSession
The ServerSession in which this shell will be executed.
session
)

Implements org.apache.sshd.server.session.ServerSessionAware.setSession.

public synchronized void
start(ChannelSession
The ChannelSession through which the command has been received
channel
,
Environment env)

Implements org.apache.sshd.server.command.CommandLifecycle.start.

Starts the command execution.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
debugdebugdebugdebugdebugerrorerrorerrorerrorerrorgetSimplifiedLoggerinfoinfowarnwarnwarnwarnwarnwarnwarnwarn

Field Detail

bufferSizeback to summary
private int bufferSize
callbackback to summary
private ExitCallback callback
errback to summary
private OutputStream err
executorback to summary
private final Executor executor
inback to summary
private InputStream in
outback to summary
private OutputStream out
pumpSleepTimeback to summary
private Duration pumpSleepTime
shellback to summary
private final InvertedShell shell
shellErrback to summary
private InputStream shellErr
shellInback to summary
private OutputStream shellIn
shellOutback to summary
private InputStream shellOut
shutdownExecutorback to summary
private boolean shutdownExecutor

Constructor Detail

InvertedShellWrapperback to summary
public InvertedShellWrapper(InvertedShell shell)

Auto-allocates an Executor in order to create the streams pump thread and uses the default CoreModuleProperties#BUFFER_SIZE

Parameters
shell:InvertedShell

The InvertedShell

See Also
InvertedShellWrapper(InvertedShell, int)
InvertedShellWrapperback to summary
public InvertedShellWrapper(InvertedShell shell, int bufferSize)

Auto-allocates an Executor in order to create the streams pump thread

Parameters
shell:InvertedShell

The InvertedShell

bufferSize:int

Buffer size to use - must be above min. size (Byte#SIZE)

See Also
InvertedShellWrapper(InvertedShell, Executor, boolean, int)
InvertedShellWrapperback to summary
public InvertedShellWrapper(InvertedShell shell, Executor executor, boolean shutdownExecutor, int bufferSize)
Parameters
shell:InvertedShell

The InvertedShell

executor: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:boolean

If true the executor is shut down when shell wrapper is destroy()-ed. Ignored if executor service auto-allocated

bufferSize:int

Buffer size to use - must be above min. size (Byte#SIZE)

Method Detail

destroyback to summary
public synchronized void destroy(ChannelSession channel) throws Exception

Implements org.apache.sshd.server.command.CommandLifecycle.destroy.

Doc from org.apache.sshd.server.command.CommandLifecycle.destroy.

This method is called by the SSH server to destroy the command because the client has disconnected somehow.

Parameters
channel:ChannelSession

The ChannelSession through which the command has been received

Annotations
@Override
Exceptions
Exception:
if failed to destroy
pumpStreamback to summary
protected boolean pumpStream(InputStream in, OutputStream out, byte[] buffer) throws IOException
pumpStreamsback to summary
protected void pumpStreams()
setErrorStreamback to summary
public void setErrorStream(OutputStream err)

Implements org.apache.sshd.server.command.CommandDirectErrorStreamAware.setErrorStream.

Doc from org.apache.sshd.server.command.CommandDirectErrorStreamAware.setErrorStream.

Set the error stream that can be used by the shell to write its errors.

Parameters
err:OutputStream

The OutputStream used by the shell to write its errors

Annotations
@Override
setExitCallbackback to summary
public void setExitCallback(ExitCallback callback)

Implements org.apache.sshd.server.command.Command.setExitCallback.

Doc from org.apache.sshd.server.command.Command.setExitCallback.

Set the callback that the shell has to call when it is closed.

Parameters
callback:ExitCallback

The ExitCallback to call when shell is closed

Annotations
@Override
setInputStreamback to summary
public void setInputStream(InputStream in)

Implements org.apache.sshd.server.command.CommandDirectInputStreamAware.setInputStream.

Doc from org.apache.sshd.server.command.CommandDirectInputStreamAware.setInputStream.

Set the input stream that can be used by the shell to read input.

Parameters
in:InputStream

The InputStream used by the shell to read input.

Annotations
@Override
setOutputStreamback to summary
public void setOutputStream(OutputStream out)

Implements org.apache.sshd.server.command.CommandDirectOutputStreamAware.setOutputStream.

Doc from org.apache.sshd.server.command.CommandDirectOutputStreamAware.setOutputStream.

Set the output stream that can be used by the shell to write its output.

Parameters
out:OutputStream

The OutputStream used by the shell to write its output

Annotations
@Override
setSessionback to summary
public void setSession(ServerSession session)

Implements org.apache.sshd.server.session.ServerSessionAware.setSession.

Parameters
session:ServerSession

Doc from org.apache.sshd.server.session.ServerSessionAware.setSession.

The ServerSession in which this shell will be executed.

Annotations
@Override
startback to summary
public synchronized void start(ChannelSession channel, Environment env) throws IOException

Implements org.apache.sshd.server.command.CommandLifecycle.start.

Doc from org.apache.sshd.server.command.CommandLifecycle.start.

Starts the command execution. All streams must have been set before calling this method. The command should implement java.lang.Runnable, and this method should spawn a new thread like:

Thread(this).start();

Parameters
channel:ChannelSession

The ChannelSession through which the command has been received

env:Environment

The Environment

Annotations
@Override
Exceptions
IOException:
If failed to start
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override