Class DefaultExecuteResultHandler

  • All Implemented Interfaces:
    ExecuteResultHandler

    public class DefaultExecuteResultHandler
    extends java.lang.Object
    implements ExecuteResultHandler
    A default implementation of 'ExecuteResultHandler' used for asynchronous process handling.
    Version:
    $Id: DefaultExecuteResultHandler.java 1636057 2014-11-01 21:14:00Z ggregory $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ExecuteException exception
      Any offending exception
      private int exitValue
      The exit value of the finished process
      private boolean hasResult
      Keep track if the process is still running
      private static int SLEEP_TIME_MS
      the interval polling the result
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ExecuteException getException()
      Get the exception causing the process execution to fail.
      int getExitValue()
      Get the exitValue of the process.
      boolean hasResult()
      Has the process exited and a result is available, i.e.
      void onProcessComplete​(int exitValue)
      The asynchronous execution completed.
      void onProcessFailed​(ExecuteException e)
      The asynchronous execution failed.
      void waitFor()
      Causes the current thread to wait, if necessary, until the process has terminated.
      void waitFor​(long timeout)
      Causes the current thread to wait, if necessary, until the process has terminated.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SLEEP_TIME_MS

        private static final int SLEEP_TIME_MS
        the interval polling the result
        See Also:
        Constant Field Values
      • hasResult

        private volatile boolean hasResult
        Keep track if the process is still running
      • exitValue

        private volatile int exitValue
        The exit value of the finished process
      • exception

        private volatile ExecuteException exception
        Any offending exception
    • Constructor Detail

      • DefaultExecuteResultHandler

        public DefaultExecuteResultHandler()
        Constructor.
    • Method Detail

      • getException

        public ExecuteException getException()
        Get the exception causing the process execution to fail.
        Returns:
        Returns the exception.
        Throws:
        java.lang.IllegalStateException - if the process has not exited yet
      • getExitValue

        public int getExitValue()
        Get the exitValue of the process.
        Returns:
        Returns the exitValue.
        Throws:
        java.lang.IllegalStateException - if the process has not exited yet
      • hasResult

        public boolean hasResult()
        Has the process exited and a result is available, i.e. exitCode or exception?
        Returns:
        true if a result of the execution is available
      • waitFor

        public void waitFor()
                     throws java.lang.InterruptedException
        Causes the current thread to wait, if necessary, until the 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:
        java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.
      • waitFor

        public void waitFor​(long timeout)
                     throws java.lang.InterruptedException
        Causes the current thread to wait, if necessary, until the 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.
        Parameters:
        timeout - the maximum time to wait in milliseconds
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.