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:
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, Runnable, ExecutorServiceCarrier, ServerSessionAware, SessionHolder<ServerSession>, ServerSessionHolder
Provides a basic useful skeleton forCommandexecutions- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancbCalledprotected ThreadcmdRunnerprotected CloseableExecutorServiceexecutorService-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCommandSupport(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.StringgetCommand()EnvironmentgetEnvironment()OutputStreamgetErrorStream()CloseableExecutorServicegetExecutorService()ExitCallbackgetExitCallback()InputStreamgetInputStream()OutputStreamgetOutputStream()ServerSessiongetServerSession()ServerSessiongetSession()protected Future<?>getStartedCommandFuture()protected voidonExit(int exitValue)protected voidonExit(int exitValue, String exitMessage)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()-
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 Thread cmdRunner
-
executorService
protected CloseableExecutorService executorService
-
cbCalled
protected boolean cbCalled
-
-
Constructor Detail
-
AbstractCommandSupport
protected AbstractCommandSupport(String command, CloseableExecutorService executorService)
-
-
Method Detail
-
getCommand
public 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
-
getInputStream
public InputStream getInputStream()
-
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.
-
getOutputStream
public OutputStream getOutputStream()
-
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
-
getErrorStream
public OutputStream getErrorStream()
-
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
-
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 Future<?> getStartedCommandFuture()
-
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
-
onExit
protected void onExit(int exitValue)
-
onExit
protected void onExit(int exitValue, String exitMessage)
-
-