public class CommandTask extends Object
CommandTask sends a command to a target subsystem and handles the responses.
Methods are provided to check if the command processing is complete, to wait for its completion, and to retrieve the result.| Modifier | Constructor and Description |
|---|---|
protected |
CommandTask(CommandSender sender,
CommandHandle handle,
Duration timeout,
String destination,
String command,
Object[] args)
Creates a
CommandTask with an explicit list of raw (not converted to strings) arguments. |
protected |
CommandTask(String destination,
String command,
CommandSender sender,
CommandHandle handle,
Duration timeout)
Creates a
CommandTask. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel()
Cancels this command task.
|
Object |
get()
Waits if necessary for the command execution to complete, and then returns its result.
|
Object[] |
getArguments()
Returns the command arguments.
|
String |
getCommand()
Returns the command as a string in
method arguments format. |
Object |
getProperty(String key)
Returns the value of the specified user-supplied property.
|
Object |
getResult()
Waits if necessary for the command execution to complete, and then returns its result or exception.
|
boolean |
isCancelled()
Returns
true if this command task was canceled before it completed normally. |
boolean |
isDone()
Returns true if this command task has completed.
|
Object |
putProperty(String key,
Object value)
Attaches a user-supplied property to this task.
|
Object |
removeProperty(String key)
Removes a previously attached user-supplied property.
|
protected void |
send()
Triggers sending the command to the target subsystem.
|
protected CommandTask(CommandSender sender, CommandHandle handle, Duration timeout, String destination, String command, Object[] args)
CommandTask with an explicit list of raw (not converted to strings) arguments.sender - CommandSender that created this task.handle - Object to be notified of responses to the command.timeout - Timeout. Zero means the command will never time out. Negative
timeout means its absolute value will be used and the custom timeout
suggested by the target subsystem through an ACK will be ignored.destination - Command destination, in "subsystem/component0/.../componentN" format.
If null, the command is assumed to contain destination in "destination/method" format.command - Command name.args - Command arguments.protected CommandTask(String destination, String command, CommandSender sender, CommandHandle handle, Duration timeout)
CommandTask.destination - Command destination in subsystem/path format.command - Command in "method arguments" format.sender - CommandSender that created this task.handle - Object to be notified of responses to the command.timeout - Timeout. Zero means the command will never time out. Negative
timeout means its absolute value will be used and the custom timeout
suggested by the target subsystem through an ACK will be ignored.protected void send()
public Object get() throws IllegalStateException, InterruptedException, org.lsst.ccs.messaging.CommandRejectedException, CancellationException, TimeoutException, ExecutionException
IllegalStateException - If the command cannot be sent.InterruptedException - If the current thread was interrupted while waiting.org.lsst.ccs.messaging.CommandRejectedException - If the command was rejected by the target subsystem.CancellationException - If the command was canceled.TimeoutException - If the command timed out.ExecutionException - If an exception was thrown by the target subsystem while executing the command,
or the result of the execution is an instance of Throwable.public Object getResult() throws InterruptedException
get() method, this method does not throw command-related exceptions. Instead,
the outcome of this command task is reported through the return value.get() method.InterruptedException - If the current thread was interrupted while waiting.public boolean cancel()
CommandHandle methods will not be called, and the get() method will throw CancellationException.
The target subsystem will not be notified of cancellation.False if the command task could not be canceled, typically because it has already completed normally; true otherwise.public boolean isCancelled()
true if this command task was canceled before it completed normally.public boolean isDone()
True if this task completed.public String getCommand()
method arguments format.public Object[] getArguments()
public Object putProperty(String key, Object value)
key - Property name.value - Property value.key, or null if there was no mapping for key.public Object removeProperty(String key)
key - Property name.key, or null if there was no mapping for key.Copyright © 2023 LSST. All rights reserved.