Class AbstractProcess

java.lang.Object
org.zeroturnaround.process.AbstractProcess
All Implemented Interfaces:
SystemProcess
Direct Known Subclasses:
CompositeProcess, JavaProcess, PollingProcess

public abstract class AbstractProcess extends Object implements SystemProcess
Base implementation of SystemProcess.
  • Field Details

    • log

      protected final org.slf4j.Logger log
  • Constructor Details

    • AbstractProcess

      public AbstractProcess()
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDescription

      protected abstract String getDescription()
      Returns:
      the description of the system process.
    • waitFor

      public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException
      Causes the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified timeout is reached.

      If the process has already terminated then this method returns immediately with the value true. If the process has not terminated and the timeout value is less than, or equal to, zero, then this method returns immediately with the value false.

      Specified by:
      waitFor in interface SystemProcess
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if the process has exited and false if the timeout is reached before the process has exited.
      Throws:
      InterruptedException - if interrupted.
    • destroyGracefully

      public AbstractProcess destroyGracefully() throws IOException, InterruptedException
      Terminates this process. The process is gracefully terminated (like kill -TERM does).

      Note: The process may not terminate at all. i.e. isAlive() may return true for a any period after destroyGracefully() is called. This method may be chained to waitFor() if needed.

      No error is thrown if the process was already terminated.

      Specified by:
      destroyGracefully in interface SystemProcess
      Returns:
      this process object.
      Throws:
      UnsupportedOperationException - if this implementation is unable to gracefully terminate the process.
      IOException - on IO error.
      InterruptedException - if interrupted.
    • destroyForcefully

      public AbstractProcess destroyForcefully() throws IOException, InterruptedException
      Kills this process. The process is forcibly terminated (like kill -KILL does).

      Note: The process may not terminate immediately. i.e. isAlive() may return true for a brief period after destroyForcefully() is called. This method may be chained to waitFor() if needed.

      No error is thrown if the process was already terminated.

      Specified by:
      destroyForcefully in interface SystemProcess
      Returns:
      this process object.
      Throws:
      UnsupportedOperationException - if this implementation is unable to gracefully terminate the process.
      IOException - on IO error.
      InterruptedException - if interrupted.
    • destroy

      public abstract void destroy(boolean forceful) throws IOException, InterruptedException
      Destroys the process either forcefully or gracefully according to the given option.

      Note: The process may not terminate at all. i.e. isAlive() may return true for a any period after destroy() is called. This method may be chained to waitFor() if needed.

      No error is thrown if the process was already terminated.

      Parameters:
      forceful - true if the process must be destroyed forcefully (like kill -KILL), false if it must be destroyed gracefully (like kill -TERM).
      Throws:
      UnsupportedOperationException - if this implementation is unable to terminate the process with this forceful value.
      IOException - on IO error.
      InterruptedException - if interrupted.