Class AbstractProcessOutput

java.lang.Object
com.github.fracpete.processoutput4j.output.AbstractProcessOutput
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CollectingProcessOutput, ConsoleOutputProcessOutput, StreamingProcessOutput

public abstract class AbstractProcessOutput extends Object implements Serializable
Ancestor for classes that give access to the output generated by a process.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      for serialization.
      See Also:
    • m_Command

      protected String[] m_Command
      the command.
    • m_Environment

      protected String[] m_Environment
      the environment variables.
    • m_ExitCode

      protected int m_ExitCode
      the exit code.
    • m_Process

      protected transient Process m_Process
      the process.
    • m_TimeOut

      protected int m_TimeOut
      the timeout for the process in seconds (ignored if invalid input: '<' 1).
    • m_TimedOut

      protected boolean m_TimedOut
      whether the process has timed out.
    • m_ReaderStdErr

      protected transient AbstractProcessReader m_ReaderStdErr
      for monitoring stderr.
    • m_ReaderStdOut

      protected transient AbstractProcessReader m_ReaderStdOut
      for monitoring stdout.
    • m_RunnableTimeout

      protected transient AbstractProcessRunnable m_RunnableTimeout
      for monitoring timeouts.
  • Constructor Details

    • AbstractProcessOutput

      public AbstractProcessOutput()
      Starts the monitoring process.
  • Method Details

    • initialize

      protected void initialize()
      For initializing the members.
    • setTimeOut

      public void setTimeOut(int value)
      Sets the timeout for the process in seconds.
      Parameters:
      value - the timeout (less than 1 for no timeout)
    • getTimeOut

      public int getTimeOut()
      Returns the timeout for the process in seconds.
      Returns:
      the timeout (less than 1 for no timeout)
    • monitor

      public void monitor(ProcessBuilder builder) throws Exception
      Performs the actual process monitoring.
      Parameters:
      builder - the process builder to monitor
      Throws:
      Exception - if writing to stdin fails
    • monitor

      public void monitor(String input, ProcessBuilder builder) throws Exception
      Performs the actual process monitoring.
      Parameters:
      builder - the process builder to monitor
      Throws:
      Exception - if writing to stdin fails
    • monitor

      public void monitor(String cmd, String[] env, Process process) throws Exception
      Performs the actual process monitoring.
      Parameters:
      cmd - the command that was used
      env - the environment
      process - the process to monitor
      Throws:
      Exception - if writing to stdin fails
    • monitor

      public void monitor(String cmd, String[] env, String input, Process process) throws Exception
      Performs the actual process monitoring.
      Parameters:
      cmd - the command that was used
      env - the environment
      input - the input to be written to the process via stdin, ignored if null
      process - the process to monitor
      Throws:
      Exception - if writing to stdin fails
    • monitor

      public void monitor(String[] cmd, String[] env, String input, Process process) throws Exception
      Performs the actual process monitoring.
      Parameters:
      cmd - the command that was used
      env - the environment
      input - the input to be written to the process via stdin, ignored if null
      process - the process to monitor
      Throws:
      Exception - if writing to stdin fails
    • configureStdErr

      protected abstract AbstractProcessReader configureStdErr()
      Configures the reader for stderr.
      Returns:
      the configured reader
    • configureStdOut

      protected abstract AbstractProcessReader configureStdOut()
      Configures the reader for stdout.
      Returns:
      the configured reader
    • configureTimeOutMonitor

      protected AbstractProcessRunnable configureTimeOutMonitor()
      Configures the runnable for watching for time outs.
      Returns:
      the configured runnable
    • getCommand

      public String[] getCommand()
      Returns the command that was used for the process.
      Returns:
      the command
    • getEnvironment

      public String[] getEnvironment()
      Returns the environment.
      Returns:
      the environment, null if process inherited current one
    • hasSucceeded

      public boolean hasSucceeded()
      Returns whether the process has succeeded.
      Returns:
      true if succeeded, i.e., exit code = 0 and not timedout
      See Also:
    • getExitCode

      public int getExitCode()
      Returns the exit code.
      Returns:
      the exit code
    • hasTimedOut

      public boolean hasTimedOut()
      Returns whether the process timed out and got terminated.
      Returns:
      true if timedout
      See Also:
    • getProcess

      public Process getProcess()
      Returns the process.
      Returns:
      the process, null if not available
    • flush

      public void flush()
      Flushes the readers.
    • destroy

      public void destroy()
      Destroys the process if possible.
    • toString

      public String toString()
      Returns a short description string.
      Overrides:
      toString in class Object
      Returns:
      the description