Package org.apache.tools.ant.taskdefs
Class ExecuteWatchdog
- java.lang.Object
- 
- org.apache.tools.ant.taskdefs.ExecuteWatchdog
 
- 
- All Implemented Interfaces:
- TimeoutObserver
 
 public class ExecuteWatchdog extends java.lang.Object implements TimeoutObserver Destroys a process running for too long. For example:ExecuteWatchdog watchdog = new ExecuteWatchdog(30000); Execute exec = new Execute(myloghandler, watchdog); exec.setCommandLine(mycmdline); int exitvalue = exec.execute(); if (Execute.isFailure(exitvalue) && watchdog.killedProcess()) { // it was killed on purpose by the watchdog }
- 
- 
Constructor SummaryConstructors Constructor Description ExecuteWatchdog(int timeout)Deprecated.since 1.5.x.ExecuteWatchdog(long timeout)Creates a new watchdog with a given timeout.
 - 
Method SummaryModifier and Type Method Description voidcheckException()This method will rethrow the exception that was possibly caught during the run of the process.protected voidcleanUp()reset the monitor flag and the process.booleanisWatching()Indicates whether or not the watchdog is still monitoring the process.booleankilledProcess()Indicates whether the last process run was killed on timeout or not.voidstart(java.lang.Process process)Watches the given process and terminates it, if it runs for too long.voidstop()Stops the watcher.voidtimeoutOccured(Watchdog w)Called after watchdog has finished.
 
- 
- 
- 
Constructor Detail- 
ExecuteWatchdogpublic ExecuteWatchdog(long timeout) Creates a new watchdog with a given timeout.- Parameters:
- timeout- the timeout for the process in milliseconds. It must be greater than 0.
 
 - 
ExecuteWatchdog@Deprecated public ExecuteWatchdog(int timeout) Deprecated.since 1.5.x. Use constructor with a long type instead. (1.4.x compatibility)- Parameters:
- timeout- the timeout value to use in milliseconds.
- See Also:
- ExecuteWatchdog(long)
 
 
- 
 - 
Method Detail- 
startpublic void start(java.lang.Process process) Watches the given process and terminates it, if it runs for too long. All information from the previous run are reset.- Parameters:
- process- the process to monitor. It cannot be- null
- Throws:
- java.lang.IllegalStateException- if a process is still being monitored.
 
 - 
stoppublic void stop() Stops the watcher. It will notify all threads possibly waiting on this object.
 - 
timeoutOccuredpublic void timeoutOccured(Watchdog w) Called after watchdog has finished. This can be called in the watchdog thread- Specified by:
- timeoutOccuredin interface- TimeoutObserver
- Parameters:
- w- the watchdog
 
 - 
cleanUpprotected void cleanUp() reset the monitor flag and the process.
 - 
checkExceptionpublic void checkException() throws BuildExceptionThis method will rethrow the exception that was possibly caught during the run of the process. It will only remains valid once the process has been terminated either by 'error', timeout or manual intervention. Information will be discarded once a new process is ran.- Throws:
- BuildException- a wrapped exception over the one that was silently swallowed and stored during the process run.
 
 - 
isWatchingpublic boolean isWatching() Indicates whether or not the watchdog is still monitoring the process.- Returns:
- trueif the process is still running, otherwise- false.
 
 - 
killedProcesspublic boolean killedProcess() Indicates whether the last process run was killed on timeout or not.- Returns:
- trueif the process was killed otherwise- false.
 
 
- 
 
-