Class ProcessHandler<T>

java.lang.Object
com.github.kokorin.jaffree.process.ProcessHandler<T>
Type Parameters:
T - process execution result

public class ProcessHandler<T> extends Object
ProcessHandler executes program.

To read stdout and stderr configure StdReaders

See Also:
  • Constructor Details

    • ProcessHandler

      public ProcessHandler(Path executable, String contextName)
      Parameters:
      executable - path to executable
      contextName - logging context
  • Method Details

    • setStdOutReader

      public ProcessHandler<T> setStdOutReader(StdReader<T> stdOutReader)
      Sets stdout reader.
      Parameters:
      stdOutReader - stdout reader
      Returns:
      this
    • setStdErrReader

      public ProcessHandler<T> setStdErrReader(StdReader<T> stdErrReader)
      Sets stderr reader.
      Parameters:
      stdErrReader - stdout reader
      Returns:
      this
    • setHelpers

      public ProcessHandler<T> setHelpers(List<ProcessHelper> helpers)
      Set extra ProcessHelpers that must be executed in parallel with process.
      Parameters:
      helpers - helpers list
      Returns:
      this
    • setStopper

      public ProcessHandler<T> setStopper(Stopper stopper)
      Sets Stopper which can be used to interrupt program execution.
      Parameters:
      stopper - stopper
      Returns:
      this
    • setArguments

      public ProcessHandler<T> setArguments(List<String> arguments)
      Sets arguments list to pass to a program.
      Parameters:
      arguments - arguments list
      Returns:
      this
    • setExecutorTimeoutMillis

      public void setExecutorTimeoutMillis(int executorTimeoutMillis)
      Overrides the default Executor timeout.

      A value of 0 is interpreted as "wait indefinitely".

      Parameters:
      executorTimeoutMillis - the new Executor timeout in milliseconds
    • execute

      public T execute()
      Executes a program.

      Returns program result from stdout or stderr readers.

      Returns:
      program result
    • interactWithProcess

      protected T interactWithProcess(Process process)
      Interacts with Process: reads stderr and stdout.
      Parameters:
      process - process
      Returns:
      program result
    • startExecution

      protected Executor startExecution(Process process, AtomicReference<T> resultReference)
      Starts execution of stdout and stderr readers as well as ProcessHelpers.

      Returns Executor

      Parameters:
      process - process
      resultReference - reference to set result
      Returns:
      executor
    • joinArguments

      protected static String joinArguments(List<String> arguments)