Class BasicProcessTracker

java.lang.Object
com.peterphi.std.system.exec.BasicProcessTracker

public class BasicProcessTracker extends Object
A basic process tracker that does not touch stdout/stderr streams
  • Field Details

    • cmd

      protected final List<String> cmd
    • process

      protected final Process process
    • combinedOutput

      protected final boolean combinedOutput
    • finished

      protected boolean finished
    • exitCode

      protected int exitCode
  • Constructor Details

    • BasicProcessTracker

      protected BasicProcessTracker(List<String> cmd, Process p, boolean combinedOutput)
  • Method Details

    • isStillReadingOutput

      protected boolean isStillReadingOutput()
      Returns true if the output of this process is still being read
      Returns:
      false if this instance is copying the stdout/stderr and they have been closed, otherwise true if we are still copying stdout/stderr. Always returns false if some external agent is handling the stdout/stderr streams.
    • discardOutput

      public void discardOutput()
      Indicates that the output of this process should be discarded
    • getProcess

      public Process getProcess()
    • kill

      public final void kill()
    • kill

      public void kill(boolean force)
    • isFinished

      public boolean isFinished()
      Determines if the application has completed yet
      Returns:
      true if the process has terminated, otherwise false
    • exitCode

      public int exitCode() throws IllegalThreadStateException
      Returns the exit code of the application, assuming it has already terminated. If the process has not yet terminated then an IllegalStateException will be thrown
      Returns:
      the exit code of the process
      Throws:
      IllegalStateException - if the process has not yet terminated
      IllegalThreadStateException
    • waitForExit

      public int waitForExit(int expected)
      Wait an indefinite amount of time for the process to exit, expecting the return code to be expected. If the output is not expected then a RuntimeException is thrown
      Parameters:
      expected - the expected return code
      Returns:
      the exit code of the process
      Throws:
      RuntimeException - if the return code was not what was expected
    • waitForExit

      public int waitForExit(Deadline deadline, int expected)
      Wait until deadline for the process to exit, expecting the return code to be expected. If the output is not expected (or if the operation times out) then a RuntimeException is thrown
      In the event of a timeout the process is not terminated
      Parameters:
      deadline -
      expected -
      Returns:
      the exit code of the process
      Throws:
      RuntimeException - if a timeout occurrs or if the return code was not what was expected
    • waitForExit

      public int waitForExit()
      Wait an indefinite amount of time for the process to exit
      Returns:
      the exit code of the process
    • waitForExit

      public int waitForExit(Deadline deadline)
      Waits for the process to exit; this method blocks until the process has completed (at which point it returns the process exit code) or until deadline has elapsed, at which point it returns Integer.MIN_VALUE
      Parameters:
      deadline -
      Returns:
      the exit code of the process
    • getStandardOutputStream

      public InputStream getStandardOutputStream()
    • getStandardErrorStream

      public InputStream getStandardErrorStream()
    • getStandardInputStream

      public OutputStream getStandardInputStream()
    • finished

      protected void finished(int exitCode)
    • unexpectedFailure

      protected void unexpectedFailure(IOException e)
    • copy

      protected Thread copy(InputStream in, Writer out)
    • discard

      protected Thread discard(InputStream in)