public abstract class BaseCommand extends Object implements org.apache.sshd.server.Command
Modifier and Type | Class and Description |
---|---|
static interface |
BaseCommand.CommandRunnable
Runnable function which can throw an exception.
|
static class |
BaseCommand.Failure
Thrown from
BaseCommand.CommandRunnable.run() with client message and code. |
static interface |
BaseCommand.ProjectCommandRunnable
Runnable function which can retrieve a project name related to the task
|
static class |
BaseCommand.UnloggedFailure
Thrown from
BaseCommand.CommandRunnable.run() with client message and code. |
Modifier and Type | Field and Description |
---|---|
static String |
ENC |
protected OutputStream |
err |
protected InputStream |
in |
protected OutputStream |
out |
static int |
STATUS_NOT_ADMIN |
Constructor and Description |
---|
BaseCommand() |
Modifier and Type | Method and Description |
---|---|
void |
checkExclusivity(Object arg1,
String arg1name,
Object arg2,
String arg2name) |
void |
destroy() |
protected BaseCommand.UnloggedFailure |
die(String msg) |
protected BaseCommand.UnloggedFailure |
die(Throwable why) |
String[] |
getArguments() |
protected String |
getName() |
protected String |
getPluginName() |
protected com.google.gerrit.util.cli.CmdLineParser |
newCmdLineParser(Object options)
Construct a new parser for this command's received command line.
|
protected void |
onExit(int rc)
Terminate this command and return a result code to the remote client.
|
protected void |
parseCommandLine()
Parses the command line argument, injecting parsed values into fields.
|
protected void |
parseCommandLine(Object options)
Parses the command line argument, injecting parsed values into fields.
|
protected void |
provideStateTo(org.apache.sshd.server.Command cmd)
Pass all state into the command, then run its start method.
|
void |
setArguments(String[] argv) |
void |
setErrorStream(OutputStream err) |
void |
setExitCallback(org.apache.sshd.server.ExitCallback callback) |
void |
setInputStream(InputStream in) |
void |
setOutputStream(OutputStream out) |
protected void |
startThread(BaseCommand.CommandRunnable thunk)
Spawn a function into its own thread.
|
protected void |
startThread(Runnable thunk)
Spawn a function into its own thread.
|
protected static PrintWriter |
toPrintWriter(OutputStream o)
Wrap the supplied output stream in a UTF-8 encoded PrintWriter.
|
protected String |
usage() |
public static final String ENC
public static final int STATUS_NOT_ADMIN
protected InputStream in
protected OutputStream out
protected OutputStream err
public void setInputStream(InputStream in)
setInputStream
in interface org.apache.sshd.server.Command
public void setOutputStream(OutputStream out)
setOutputStream
in interface org.apache.sshd.server.Command
public void setErrorStream(OutputStream err)
setErrorStream
in interface org.apache.sshd.server.Command
public void setExitCallback(org.apache.sshd.server.ExitCallback callback)
setExitCallback
in interface org.apache.sshd.server.Command
protected String getPluginName()
protected String getName()
public String[] getArguments()
public void setArguments(String[] argv)
public void destroy()
destroy
in interface org.apache.sshd.server.Command
protected void provideStateTo(org.apache.sshd.server.Command cmd)
This method copies all critical state, like the input and output streams,
into the supplied command. The caller must still invoke cmd.start()
if wants to pass control to the command.
cmd
- the command that will receive the current state.protected void parseCommandLine() throws BaseCommand.UnloggedFailure
This method must be explicitly invoked to cause a parse.
BaseCommand.UnloggedFailure
- if the command line arguments were invalid.Option
,
Argument
protected void parseCommandLine(Object options) throws BaseCommand.UnloggedFailure
This method must be explicitly invoked to cause a parse.
options
- object whose fields declare Option and Argument annotations
to describe the parameters of the command. Usually this
.BaseCommand.UnloggedFailure
- if the command line arguments were invalid.Option
,
Argument
protected String usage()
protected com.google.gerrit.util.cli.CmdLineParser newCmdLineParser(Object options)
protected void startThread(Runnable thunk)
Typically this should be invoked within Command.start(Environment)
,
such as:
startThread(new Runnable() { public void run() { runImp(); } });
thunk
- the runnable to execute on the thread, performing the
command's logic.protected void startThread(BaseCommand.CommandRunnable thunk)
Typically this should be invoked within Command.start(Environment)
,
such as:
startThread(new CommandRunnable() { public void run() throws Exception { runImp(); } });
If the function throws an exception, it is translated to a simple message for the client, a non-zero exit code, and the stack trace is logged.
thunk
- the runnable to execute on the thread, performing the
command's logic.protected void onExit(int rc)
Commands should invoke this at most once. Once invoked, the command may
lose access to request based resources as any callbacks previously
registered with RequestCleanup
will fire.
rc
- exit code for the remote client.protected static PrintWriter toPrintWriter(OutputStream o)
protected BaseCommand.UnloggedFailure die(String msg)
protected BaseCommand.UnloggedFailure die(Throwable why)
public void checkExclusivity(Object arg1, String arg1name, Object arg2, String arg2name) throws BaseCommand.UnloggedFailure
BaseCommand.UnloggedFailure