Package com.topjohnwu.superuser
Class Shell.Job
java.lang.Object
com.topjohnwu.superuser.Shell.Job
- Enclosing class:
- Shell
Represents a shell Job that could later be executed or submitted to background threads.
All operations added in add(String...)
and add(InputStream)
will be
executed in the order of addition.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Shell.Job
add
(InputStream in) Add a new operation serving an InputStream to STDIN.abstract Shell.Job
Add a new operation running commands.abstract Future<Shell.Result>
enqueue()
Submit the job to an internal queue to run in the background.abstract Shell.Result
exec()
Execute the job immediately and returns the result.final void
submit()
Submit the job to an internal queue to run in the background.final void
Submit the job to an internal queue to run in the background.abstract void
submit
(Executor executor, Shell.ResultCallback cb) Submit the job to an internal queue to run in the background.abstract Shell.Job
Store output of STDOUT to a specific list.abstract Shell.Job
Store output of STDOUT and STDERR to specific lists.
-
Constructor Details
-
Job
public Job()
-
-
Method Details
-
to
Store output of STDOUT to a specific list.- Parameters:
stdout
- the list to store STDOUT. Passnull
to omit all outputs.- Returns:
- this Job object for chaining of calls.
-
to
Store output of STDOUT and STDERR to specific lists.- Parameters:
stdout
- the list to store STDOUT. Passnull
to omit STDOUT.stderr
- the list to store STDERR. Passnull
to omit STDERR.- Returns:
- this Job object for chaining of calls.
-
add
Add a new operation running commands.- Parameters:
cmds
- the commands to run.- Returns:
- this Job object for chaining of calls.
-
add
Add a new operation serving an InputStream to STDIN.This is NOT executing the script like
sh script.sh
. This is similar to sourcing the script (. script.sh
) as the raw content of the script is directly fed into STDIN. If you callexit
in the script, the shell will be killed and this shell instance will no longer be alive!- Parameters:
in
- the InputStream to serve to STDIN. The stream will be closed after consumption.- Returns:
- this Job object for chaining of calls.
-
exec
Execute the job immediately and returns the result.- Returns:
- the result of the job.
-
submit
public final void submit()Submit the job to an internal queue to run in the background. The result will be omitted. -
submit
Submit the job to an internal queue to run in the background. The result will be returned with a callback running on the main thread.- Parameters:
cb
- the callback to receive the result of the job.
-
submit
Submit the job to an internal queue to run in the background. The result will be returned with a callback executed by the provided executor.- Parameters:
executor
- the executor used to handle the result callback event. Passnull
to run the callback on the same thread executing the job.cb
- the callback to receive the result of the job.
-
enqueue
Submit the job to an internal queue to run in the background.- Returns:
- a
Future
to get the result of the job later.
-