Package org.apache.commons.exec
Class DefaultExecuteResultHandler
java.lang.Object
org.apache.commons.exec.DefaultExecuteResultHandler
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate ExecuteExceptionAny offending exceptionprivate intThe exit value of the finished processprivate booleanKeep track if the process is still runningprivate static final intthe interval polling the result -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet theexceptioncausing the process execution to fail.intGet theexitValueof the process.booleanHas the process exited and a result is available, i.e.voidonProcessComplete(int exitValue) The asynchronous execution completed.voidThe asynchronous execution failed.voidwaitFor()Causes the current thread to wait, if necessary, until the process has terminated.voidwaitFor(long timeout) Causes the current thread to wait, if necessary, until the process has terminated.
-
Field Details
-
SLEEP_TIME_MS
private static final int SLEEP_TIME_MSthe interval polling the result- See Also:
-
hasResult
private volatile boolean hasResultKeep track if the process is still running -
exitValue
private volatile int exitValueThe exit value of the finished process -
exception
Any offending exception
-
-
Constructor Details
-
DefaultExecuteResultHandler
public DefaultExecuteResultHandler()Constructor.
-
-
Method Details
-
onProcessComplete
public void onProcessComplete(int exitValue) Description copied from interface:ExecuteResultHandlerThe asynchronous execution completed.- Specified by:
onProcessCompletein interfaceExecuteResultHandler- Parameters:
exitValue- the exit value of the sub-process- See Also:
-
onProcessFailed
Description copied from interface:ExecuteResultHandlerThe asynchronous execution failed.- Specified by:
onProcessFailedin interfaceExecuteResultHandler- Parameters:
e- theExecuteExceptioncontaining the root cause- See Also:
-
getException
Get theexceptioncausing the process execution to fail.- Returns:
- Returns the exception.
- Throws:
IllegalStateException- if the process has not exited yet
-
getExitValue
public int getExitValue()Get theexitValueof the process.- Returns:
- Returns the exitValue.
- Throws:
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
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:
InterruptedException- if the current thread is interrupted by another thread while it is waiting, then the wait is ended and anInterruptedExceptionis thrown.
-
waitFor
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:
InterruptedException- if the current thread is interrupted by another thread while it is waiting, then the wait is ended and anInterruptedExceptionis thrown.
-