Class OrProcess

All Implemented Interfaces:
SystemProcess

public class OrProcess extends CompositeProcess
Represents a single system process containing alternative SystemProcess implementations for controlling it. Children are expected to throw UnsupportedOperationException for certain operations.

For any operation we try each children until it doesn't throw UnsupportedOperationException. If all of them throw it, we throw it as well.

If it has only one child it acts the same as invoking the same method directly on the child.

  • Constructor Details

  • Method Details

    • isAlive

      public boolean isAlive() throws IOException, InterruptedException
      Description copied from interface: SystemProcess
      Tests whether this process is alive.

      This operation may take some time to finish.

      Returns:
      true if this process is alive, false if it is finished or not found.
      Throws:
      IOException - on IO error.
      InterruptedException - if interrupted.
    • waitFor

      public void waitFor() throws InterruptedException
      Description copied from interface: SystemProcess
      Causes the current thread to wait, if necessary, until this process has terminated.

      This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.

      Throws:
      InterruptedException - if interrupted.
    • destroy

      public void destroy(boolean forceful) throws IOException, InterruptedException
      Description copied from class: AbstractProcess
      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.

      Specified by:
      destroy in class AbstractProcess
      Parameters:
      forceful - true if the process must be destroyed forcefully (like kill -KILL), false if it must be destroyed gracefully (like kill -TERM).
      Throws:
      IOException - on IO error.
      InterruptedException - if interrupted.