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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Shell.Jobadd(InputStream in) Add a new operation serving an InputStream to STDIN.abstract Shell.JobAdd a new operation running commands.abstract Future<Shell.Result>enqueue()Submit the job to an internal queue to run in the background.abstract Shell.Resultexec()Execute the job immediately and returns the result.final voidsubmit()Submit the job to an internal queue to run in the background.final voidSubmit the job to an internal queue to run in the background.abstract voidsubmit(Executor executor, Shell.ResultCallback cb) Submit the job to an internal queue to run in the background.abstract Shell.JobStore output of STDOUT to a specific list.abstract Shell.JobStore 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. Passnullto 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. Passnullto omit STDOUT.stderr- the list to store STDERR. Passnullto 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 callexitin 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. Passnullto 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
Futureto get the result of the job later.
-