Package org.apache.sshd.server.command
Class AbstractCommandSupport
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.server.command.AbstractCommandSupport
-
- All Implemented Interfaces:
java.lang.Runnable,SessionContextHolder,SessionHolder<ServerSession>,ExecutorServiceCarrier,Command,CommandDirectErrorStreamAware,CommandDirectInputStreamAware,CommandDirectOutputStreamAware,CommandDirectStreamsAware,CommandLifecycle,ServerSessionAware,ServerSessionHolder
- Direct Known Subclasses:
AbstractFileSystemCommand
public abstract class AbstractCommandSupport extends AbstractLoggingBean implements Command, java.lang.Runnable, ExecutorServiceCarrier, ServerSessionAware, SessionHolder<ServerSession>, ServerSessionHolder
Provides a basic useful skeleton forCommandexecutions
-
-
Field Summary
Fields Modifier and Type Field Description private ExitCallbackcallbackprotected booleancbCalledprivate java.util.concurrent.Future<?>cmdFutureprotected java.lang.ThreadcmdRunnerprivate java.lang.Stringcommandprivate Environmentenvironmentprivate java.io.OutputStreamerrprotected CloseableExecutorServiceexecutorServiceprivate java.io.InputStreaminprivate java.io.OutputStreamoutprivate ServerSessionserverSession-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCommandSupport(java.lang.String command, CloseableExecutorService executorService)
-
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.java.lang.StringgetCommand()EnvironmentgetEnvironment()java.io.OutputStreamgetErrorStream()CloseableExecutorServicegetExecutorService()ExitCallbackgetExitCallback()java.io.InputStreamgetInputStream()java.io.OutputStreamgetOutputStream()ServerSessiongetServerSession()ServerSessiongetSession()protected java.util.concurrent.Future<?>getStartedCommandFuture()protected voidonExit(int exitValue)protected voidonExit(int exitValue, java.lang.String exitMessage)voidsetErrorStream(java.io.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(java.io.InputStream in)Set the input stream that can be used by the shell to read input.voidsetOutputStream(java.io.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.java.lang.StringtoString()-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
cmdRunner
protected volatile java.lang.Thread cmdRunner
-
executorService
protected CloseableExecutorService executorService
-
cbCalled
protected boolean cbCalled
-
command
private final java.lang.String command
-
in
private java.io.InputStream in
-
out
private java.io.OutputStream out
-
err
private java.io.OutputStream err
-
callback
private ExitCallback callback
-
environment
private Environment environment
-
cmdFuture
private java.util.concurrent.Future<?> cmdFuture
-
serverSession
private ServerSession serverSession
-
-
Constructor Detail
-
AbstractCommandSupport
protected AbstractCommandSupport(java.lang.String command, CloseableExecutorService executorService)
-
-
Method Detail
-
getCommand
public java.lang.String getCommand()
-
getSession
public ServerSession getSession()
- Specified by:
getSessionin interfaceSessionHolder<ServerSession>
-
getServerSession
public ServerSession getServerSession()
- Specified by:
getServerSessionin interfaceServerSessionHolder- Returns:
- The underlying
ServerSessionused
-
setSession
public void setSession(ServerSession session)
- Specified by:
setSessionin interfaceServerSessionAware- Parameters:
session- TheServerSessionin which this shell will be executed.
-
getExecutorService
public CloseableExecutorService getExecutorService()
- Specified by:
getExecutorServicein interfaceExecutorServiceCarrier- Returns:
- The
CloseableExecutorServiceto use
-
getInputStream
public java.io.InputStream getInputStream()
-
setInputStream
public void setInputStream(java.io.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.
-
getOutputStream
public java.io.OutputStream getOutputStream()
-
setOutputStream
public void setOutputStream(java.io.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
-
getErrorStream
public java.io.OutputStream getErrorStream()
-
setErrorStream
public void setErrorStream(java.io.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
-
getExitCallback
public ExitCallback getExitCallback()
-
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
-
getEnvironment
public Environment getEnvironment()
-
getStartedCommandFuture
protected java.util.concurrent.Future<?> getStartedCommandFuture()
-
start
public void start(ChannelSession channel, Environment env) throws java.io.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:
java.io.IOException- If failed to start
-
destroy
public void destroy(ChannelSession channel) throws java.lang.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:
java.lang.Exception- if failed to destroy
-
onExit
protected void onExit(int exitValue)
-
onExit
protected void onExit(int exitValue, java.lang.String exitMessage)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-