Package org.apache.commons.exec
Class DefaultExecuteResultHandler
- java.lang.Object
-
- org.apache.commons.exec.DefaultExecuteResultHandler
-
- All Implemented Interfaces:
ExecuteResultHandler
public class DefaultExecuteResultHandler extends java.lang.Object implements ExecuteResultHandler
A default implementation of 'ExecuteResultHandler' used for asynchronous process handling.
-
-
Field Summary
Fields Modifier and Type Field Description private ExecuteExceptionexceptionAny offending exception.private intexitValueThe exit value of the finished process.private booleanhasResultKeep track if the process is still running.private static intSLEEP_TIME_MSThe interval polling the result.
-
Constructor Summary
Constructors Constructor Description DefaultExecuteResultHandler()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ExecuteExceptiongetException()Gets theexceptioncausing the process execution to fail.intgetExitValue()Gets theexitValueof the process.booleanhasResult()Tests whether the process exited and a result is available, i.e.voidonProcessComplete(int exitValue)The asynchronous execution completed.voidonProcessFailed(ExecuteException e)The asynchronous execution failed.voidwaitFor()Causes the current thread to wait, if necessary, until the process has terminated.voidwaitFor(long timeoutMillis)Deprecated.UsewaitFor(Duration).voidwaitFor(java.time.Duration timeout)Causes the current thread to wait, if necessary, until the process has terminated.
-
-
-
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.
-
-
Method Detail
-
getException
public ExecuteException getException()
Gets theexceptioncausing the process execution to fail.- Returns:
- the exception.
- Throws:
java.lang.IllegalStateException- if the process has not exited yet.
-
getExitValue
public int getExitValue()
Gets theexitValueof the process.- Returns:
- the exitValue.
- Throws:
java.lang.IllegalStateException- if the process has not exited yet.
-
hasResult
public boolean hasResult()
Tests whether the process exited and a result is available, i.e. exitCode or exception?- Returns:
- true whether a result of the execution is available.
-
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:
ExecuteResultHandler.onProcessComplete(int)
-
onProcessFailed
public void onProcessFailed(ExecuteException e)
Description copied from interface:ExecuteResultHandlerThe asynchronous execution failed.- Specified by:
onProcessFailedin interfaceExecuteResultHandler- Parameters:
e- theExecuteExceptioncontaining the root cause.- See Also:
ExecuteResultHandler.onProcessFailed(org.apache.commons.exec.ExecuteException)
-
waitFor
public void waitFor() throws java.lang.InterruptedExceptionCauses 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 anInterruptedExceptionis thrown.
-
waitFor
public void waitFor(java.time.Duration timeout) throws java.lang.InterruptedExceptionCauses 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.- Throws:
java.lang.InterruptedException- if the current thread is interrupted by another thread while it is waiting, then the wait is ended and anInterruptedExceptionis thrown.- Since:
- 1.4.0
-
waitFor
@Deprecated public void waitFor(long timeoutMillis) throws java.lang.InterruptedExceptionDeprecated.UsewaitFor(Duration).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:
timeoutMillis- 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 anInterruptedExceptionis thrown.
-
-