@Plugin(name="Command Service Plugin", id="command-service", description="Command service utility.") public final class CommandService extends ConsolePlugin implements ConsoleService
Sample Usage. The following code sketch creates a sender, sets a custom timeout, and sends a command.
CommandService service = CommandService.getService();
CommandSender sender = service.getSender();
sender.setTimeout(Duration.ofSeconds(3));
sender.send("worker", "component/command --noconfig [A,B] C");
All sendXXX(...) methods return immediately, without waiting for the command to be processed
by the messaging service or the target subsystem. Synchronous command execution can be achieved by calling
get() or getResult() on the CommandTask returned by these methods:
CommandService service = CommandService.getService();
CommandTask task = service.sendEncoded("worker", "component/command", "[A, B]", "C", "--noconfig");
try {
Object result = getResult();
....
} catch (InterruptedException x) {
....
}
| Constructor and Description |
|---|
CommandService() |
| Modifier and Type | Method and Description |
|---|---|
CommandTask |
execute(CommandHandle handle,
Duration timeout,
String command,
Object... args)
Deprecated.
Use
sendRaw(...), sendEncoded(...), or send(...) instead. |
CommandTask |
execute(CommandHandle handle,
String command,
Object... args)
Deprecated.
Use
sendRaw(...), sendEncoded(...), or send(...) instead. |
CommandTask |
execute(Duration timeout,
String command,
Object... args)
Deprecated.
Use
sendRaw(...), sendEncoded(...), or send(...) instead. |
CommandTask |
execute(String command,
Object... args)
Deprecated.
Use
sendRaw(...), sendEncoded(...), or send(...) instead. |
CommandSender |
getSender()
Creates a new customizable instance of
CommandSender configured for use in the graphical console environment. |
static CommandService |
getService() |
CommandTask |
send(String shellCommand)
Sends a command to a remote subsystem with default timeout and default response handling.
|
CommandTask |
send(String destination,
String command)
Sends a command to a remote subsystem with default timeout and default response handling.
|
CommandTask |
send(String destination,
String commandName,
String arguments)
Sends a command to a remote subsystem with default timeout and default response handling.
|
CommandTask |
sendEncoded(String destination,
String command,
String... args)
Sends a command to a remote subsystem with default timeout and default response handling.
|
CommandTask |
sendRaw(String destination,
String command,
Object... args)
Sends a command to a remote subsystem with default timeout and default response handling.
|
void |
watch(Consumer<Boolean> watcher,
String command,
int numberOfArguments)
Not yet implemented.
Registers a component that should be notified whenever the availability of the specified command changes.
|
getConsole, getServices, initialize, propertiesChanged, restore, save, setServicesProvider, shutdown, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitstartService, stopServicepublic static CommandService getService()
public CommandSender getSender()
CommandSender configured for use in the graphical console environment.
For any commands sent through the CommandSender created by this method,
CommandHandle methods will be called on the AWT Event Dispatching Thread.
The sender created by this method can be further customized.CommandSender.@Deprecated public CommandTask execute(CommandHandle handle, Duration timeout, String command, Object... args)
sendRaw(...), sendEncoded(...), or send(...) instead.
This method returns immediately, without waiting for the command to be processed
by the messaging service or the target subsystem. Synchronous command execution can
be done by calling get() or getResult()
on the CommandTask returned by this method.
handle - Handle for processing the command responses. May be null if no processing is required.
All callbacks are executed on the AWT Event Dispatching Thread.timeout - Timeout. Cannot be null.
Zero duration means the command will never time out.
Negative duration means its absolute value will be used and the custom timeout
suggested by the target subsystem through an ACK will be ignored.command - Command in subsystem/path format.args - Command arguments.@Deprecated public CommandTask execute(CommandHandle handle, String command, Object... args)
sendRaw(...), sendEncoded(...), or send(...) instead.
This method returns immediately, without waiting for the command to be processed
by the messaging service or the target subsystem. Synchronous command execution can
be done by calling get() or getResult()
on the CommandTask returned by this method.
handle - Handle for processing the command responses.
Cannot be null. If no processing is required, use CommandHandle.NONE.
All callbacks are executed on the AWT Event Dispatching Thread.command - Command in subsystem/path format.args - Command arguments.@Deprecated public CommandTask execute(Duration timeout, String command, Object... args)
sendRaw(...), sendEncoded(...), or send(...) instead.
This method returns immediately, without waiting for the command to be processed
by the messaging service or the target subsystem. Synchronous command execution can
be done by calling get() or getResult()
on the CommandTask returned by this method.
timeout - Timeout. Cannot be null.
Zero duration means the command will never time out.
Negative duration means its absolute value will be used and the custom timeout
suggested by the target subsystem through an ACK will be ignored.command - Command in subsystem/path format.args - Command arguments.@Deprecated public CommandTask execute(String command, Object... args)
sendRaw(...), sendEncoded(...), or send(...) instead.
This method returns immediately, without waiting for the command to be processed
by the messaging service or the target subsystem. Synchronous command execution can
be done by calling get() or getResult()
on the CommandTask returned by this method.
command - Command in subsystem/path format.args - Command arguments.public CommandTask sendRaw(String destination, String command, Object... args)
destination - Command destination, in "subsystem/component0/.../componentN" format.command - Command name.args - Command arguments as objects that should be passed directly to the command implementation.public CommandTask sendEncoded(String destination, String command, String... args)
destination - Command destination, in "subsystem/component0/.../componentN" format.command - Command name.args - Command arguments encoded as strings.public CommandTask send(String destination, String commandName, String arguments)
destination - Command destination, in "subsystem/component0/.../componentN" format.commandName - Command name.arguments - Command arguments encoded as a single string.public CommandTask send(String destination, String command)
destination - Command destination, in "subsystem/component0/.../componentN" format.command - Command with arguments, encoded as a single string.public CommandTask send(String shellCommand)
shellCommand - Command with destination and arguments, as it would be given to a command shell.public void watch(Consumer<Boolean> watcher, String command, int numberOfArguments)
watcher - Component to be notified.command - Command in subsystem/path format.numberOfArguments - Number of arguments accepted by the command.Copyright © 2023 LSST. All rights reserved.