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
,CommandLifecycle
,ServerSessionHolder
,SessionAware
- Direct Known Subclasses:
AbstractFileSystemCommand
public abstract class AbstractCommandSupport extends AbstractLoggingBean implements Command, java.lang.Runnable, ExecutorServiceCarrier, SessionAware, SessionHolder<ServerSession>, ServerSessionHolder
Provides a basic useful skeleton forCommand
executions
-
-
Field Summary
Fields Modifier and Type Field Description protected ExitCallback
callback
protected boolean
cbCalled
protected java.util.concurrent.Future<?>
cmdFuture
protected java.lang.Thread
cmdRunner
protected java.lang.String
command
protected Environment
environment
protected java.io.OutputStream
err
protected CloseableExecutorService
executorService
protected java.io.InputStream
in
protected java.io.OutputStream
out
protected ServerSession
serverSession
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCommandSupport(java.lang.String command, CloseableExecutorService executorService)
-
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.java.lang.String
getCommand()
Environment
getEnvironment()
java.io.OutputStream
getErrorStream()
CloseableExecutorService
getExecutorService()
ExitCallback
getExitCallback()
java.io.InputStream
getInputStream()
java.io.OutputStream
getOutputStream()
ServerSession
getServerSession()
ServerSession
getSession()
protected java.util.concurrent.Future<?>
getStartedCommandFuture()
protected void
onExit(int exitValue)
protected void
onExit(int exitValue, java.lang.String exitMessage)
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()
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
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
-
command
protected final java.lang.String command
-
in
protected java.io.InputStream in
-
out
protected java.io.OutputStream out
-
err
protected java.io.OutputStream err
-
callback
protected ExitCallback callback
-
environment
protected Environment environment
-
cmdFuture
protected java.util.concurrent.Future<?> cmdFuture
-
cmdRunner
protected volatile java.lang.Thread cmdRunner
-
executorService
protected CloseableExecutorService executorService
-
cbCalled
protected boolean cbCalled
-
serverSession
protected 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:
getSession
in interfaceSessionHolder<ServerSession>
-
getServerSession
public ServerSession getServerSession()
- Specified by:
getServerSession
in interfaceServerSessionHolder
- Returns:
- The underlying
ServerSession
used
-
setSession
public void setSession(ServerSession session)
- Specified by:
setSession
in interfaceSessionAware
- Parameters:
session
- TheServerSession
in which this shell will be executed.
-
getExecutorService
public CloseableExecutorService getExecutorService()
- Specified by:
getExecutorService
in interfaceExecutorServiceCarrier
- Returns:
- The
CloseableExecutorService
to use
-
getInputStream
public java.io.InputStream getInputStream()
-
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.
-
getOutputStream
public java.io.OutputStream getOutputStream()
-
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
-
getErrorStream
public java.io.OutputStream getErrorStream()
-
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
-
getExitCallback
public ExitCallback getExitCallback()
-
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
-
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: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
-
onExit
protected void onExit(int exitValue)
-
onExit
protected void onExit(int exitValue, java.lang.String exitMessage)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-