Class Shell.Job

java.lang.Object
com.topjohnwu.superuser.Shell.Job
Enclosing class:
Shell

public abstract static class Shell.Job extends Object
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 Details

    • Job

      public Job()
  • Method Details

    • to

      @NonNull public abstract Shell.Job to(@Nullable List<String> stdout)
      Store output of STDOUT to a specific list.
      Parameters:
      stdout - the list to store STDOUT. Pass null to omit all outputs.
      Returns:
      this Job object for chaining of calls.
    • to

      @NonNull public abstract Shell.Job to(@Nullable List<String> stdout, @Nullable List<String> stderr)
      Store output of STDOUT and STDERR to specific lists.
      Parameters:
      stdout - the list to store STDOUT. Pass null to omit STDOUT.
      stderr - the list to store STDERR. Pass null to omit STDERR.
      Returns:
      this Job object for chaining of calls.
    • add

      @NonNull public abstract Shell.Job add(@NonNull String... cmds)
      Add a new operation running commands.
      Parameters:
      cmds - the commands to run.
      Returns:
      this Job object for chaining of calls.
    • add

      @NonNull public abstract Shell.Job add(@NonNull InputStream in)
      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 call exit 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

      @NonNull public abstract Shell.Result 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

      public final void submit(@Nullable Shell.ResultCallback cb)
      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

      public abstract void submit(@Nullable Executor executor, @Nullable Shell.ResultCallback cb)
      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. Pass null to run the callback on the same thread executing the job.
      cb - the callback to receive the result of the job.
    • enqueue

      @NonNull public abstract Future<Shell.Result> enqueue()
      Submit the job to an internal queue to run in the background.
      Returns:
      a Future to get the result of the job later.