Class ProcessUtil.Runner

java.lang.Object
org.apache.uima.pear.util.ProcessUtil.Runner
All Implemented Interfaces:
Runnable
Enclosing class:
ProcessUtil

public static class ProcessUtil.Runner extends Object implements Runnable
The ProcessUtil.Runner class allows collecting, printing and distributing console output (stdout and stderr) of the specified Process without blocking the caller. It allows adding standard stream listeners to receive messages printed to the console by selected process.
  • Constructor Details Link icon

    • Runner Link icon

      public Runner(Process aProcess)
      Constructor that takes a given Process object and assigns default process name.
      Parameters:
      aProcess - The given Process object.
    • Runner Link icon

      public Runner(Process aProcess, String procName)
      Constructor that takes a given Process object and a given process name.
      Parameters:
      aProcess - The given Process object.
      procName - The given process name.
    • Runner Link icon

      public Runner(Process aProcess, String procName, boolean printToConsole)
      Constructor that takes a given Process object, a given process name, and a given boolean flag that enables/disables console printing. If the given process name is null, the default process name is assigned.
      Parameters:
      aProcess - The given Process object.
      procName - The given process name.
      printToConsole - boolean flag that enables/disables console printing.
  • Method Details Link icon

    • addStreamListener Link icon

      public void addStreamListener(ProcessUtil.StdStreamListener listener)
      Adds a given object, implementing the StdStreamListener interface to the list of standard stream listeners. Sends to the new listener previously printed standard error and standard output messages.
      Parameters:
      listener - The given new standard stream listener.
    • getExitCode Link icon

      public int getExitCode()
      Returns:
      Process exit code after the process finishes, otherwise Integer.MAX_VALUE.
    • getErrOutput Link icon

      public String getErrOutput()
      Returns:
      Standard error messages collected during the process execution.
    • getProcess Link icon

      public Process getProcess()
    • getStdOutput Link icon

      public String getStdOutput()
      Returns:
      Standard output messages collected during the process execution.
    • removeListener Link icon

      public void removeListener(ProcessUtil.StdStreamListener listener)
      Removes a given StdStreamListener object from the list of standard stream listeners.
      Parameters:
      listener - The given StdStreamListener object to be removed from the list.
    • run Link icon

      public void run()
      Implements the Runnable.run() method, collecting and printing standard output or standard error messages during the process execution.
      Specified by:
      run in interface Runnable
    • waitFor Link icon

      public int waitFor()
      Allows the caller to wait for the completion of the process.
      Returns:
      Process exit code.
    • waitFor Link icon

      public int waitFor(long timeout)
      Allows the caller to wait for the completion of the process, but no longer than a given timeout value.
      Parameters:
      timeout - The given timeout value (ms).
      Returns:
      Process exit code or Integer.MAX_VALUE, if the process has not finished yet.