org.apache.tools.ant.taskdefs
Class ExecuteWatchdog
java.lang.Object
org.apache.tools.ant.taskdefs.ExecuteWatchdog
- TimeoutObserver
public class ExecuteWatchdog
extends java.lang.Object
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
}
void | checkException() - This method will rethrow the exception that was possibly caught during
the run of the process.
|
protected void | cleanUp() - reset the monitor flag and the process.
|
boolean | isWatching() - Indicates whether or not the watchdog is still monitoring the process.
|
boolean | killedProcess() - Indicates whether the last process run was killed on timeout or not.
|
void | start(Process process) - Watches the given process and terminates it, if it runs for too long.
|
void | stop() - Stops the watcher.
|
void | timeoutOccured(Watchdog w) - Called after watchdog has finished.
|
ExecuteWatchdog
public ExecuteWatchdog(int timeout)
Use constructor with a long type instead.
(1.4.x compatibility)
ExecuteWatchdog
public ExecuteWatchdog(long timeout)
Creates a new watchdog with a given timeout.
timeout
- the timeout for the process in milliseconds.
It must be greater than 0.
checkException
public void checkException()
throws BuildException
This 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.
BuildException
- a wrapped exception over the one that was
silently swallowed and stored during the process run.
cleanUp
protected void cleanUp()
reset the monitor flag and the process.
isWatching
public boolean isWatching()
Indicates whether or not the watchdog is still monitoring the process.
- true if the process is still running, otherwise
false.
killedProcess
public boolean killedProcess()
Indicates whether the last process run was killed on timeout or not.
- true if the process was killed otherwise
false.
start
public void start(Process process)
Watches the given process and terminates it, if it runs for too long.
All information from the previous run are reset.
process
- the process to monitor. It cannot be null
stop
public void stop()
Stops the watcher. It will notify all threads possibly waiting
on this object.
Copyright © 2000-2006 Apache Software Foundation. All Rights Reserved.