Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class ExecuteWatchdog

extends Object
implements TimeoutObserver
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.util.TimeoutObserver
Imports
org.apache.tools.ant.BuildException, org.apache.tools.ant.util.TimeoutObserver, .Watchdog

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
}
Since
Ant 1.2
See Also
Execute, org.apache.tools.ant.util.Watchdog

Field Summary

Modifier and TypeField and Description
private Exception
caught

exception that might be thrown during the process execution

private volatile boolean
killedProcess

say whether or not the process was killed due to running overtime

private Process
process

the process to execute and watch for duration

private volatile boolean
watch

say whether or not the watchdog is currently monitoring a process

private Watchdog
watchdog

will tell us whether timeout has occurred

Constructor Summary

AccessConstructor and Description
public
ExecuteWatchdog(long
the timeout for the process in milliseconds. It must be greater than 0.
timeout
)

Creates a new watchdog with a given timeout.

public
ExecuteWatchdog(int
the timeout value to use in milliseconds.
timeout
)

Deprecated since 1.5.x. Use constructor with a long type instead. (1.4.x compatibility)

Method Summary

Modifier and TypeMethod and Description
public synchronized void
checkException()

This method will rethrow the exception that was possibly caught during the run of the process.

protected synchronized void
cleanUp()

reset the monitor flag and the process.

public boolean

Returns:

true if the process is still running, otherwise false.
isWatching
()

Indicates whether or not the watchdog is still monitoring the process.

public boolean

Returns:

true if the process was killed otherwise false.
killedProcess
()

Indicates whether the last process run was killed on timeout or not.

public synchronized void
start(Process
the process to monitor. It cannot be null
process
)

Watches the given process and terminates it, if it runs for too long.

public synchronized void
stop()

Stops the watcher.

public synchronized void
timeoutOccured(Watchdog
the watchdog
w
)

Implements org.apache.tools.ant.util.TimeoutObserver.timeoutOccured.

Called after watchdog has finished.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

caughtback to summary
private Exception caught

exception that might be thrown during the process execution

killedProcessback to summary
private volatile boolean killedProcess

say whether or not the process was killed due to running overtime

processback to summary
private Process process

the process to execute and watch for duration

watchback to summary
private volatile boolean watch

say whether or not the watchdog is currently monitoring a process

watchdogback to summary
private Watchdog watchdog

will tell us whether timeout has occurred

Constructor Detail

ExecuteWatchdogback to summary
public ExecuteWatchdog(long timeout)

Creates a new watchdog with a given timeout.

Parameters
timeout:long

the timeout for the process in milliseconds. It must be greater than 0.

ExecuteWatchdogback to summary
public ExecuteWatchdog(int timeout)

Deprecated

since 1.5.x. Use constructor with a long type instead. (1.4.x compatibility)

Parameters
timeout:int

the timeout value to use in milliseconds.

Annotations
@Deprecated
See Also
ExecuteWatchdog(long)

Method Detail

checkExceptionback to summary
public synchronized 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.

Exceptions
BuildException:
a wrapped exception over the one that was silently swallowed and stored during the process run.
cleanUpback to summary
protected synchronized void cleanUp()

reset the monitor flag and the process.

isWatchingback to summary
public boolean isWatching()

Indicates whether or not the watchdog is still monitoring the process.

Returns:boolean

true if the process is still running, otherwise false.

killedProcessback to summary
public boolean killedProcess()

Indicates whether the last process run was killed on timeout or not.

Returns:boolean

true if the process was killed otherwise false.

startback to summary
public synchronized 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.

Parameters
process:Process

the process to monitor. It cannot be null

Exceptions
IllegalStateException:
if a process is still being monitored.
stopback to summary
public synchronized void stop()

Stops the watcher. It will notify all threads possibly waiting on this object.

timeoutOccuredback to summary
public synchronized void timeoutOccured(Watchdog w)

Implements org.apache.tools.ant.util.TimeoutObserver.timeoutOccured.

Called after watchdog has finished. This can be called in the watchdog thread

Parameters
w:Watchdog

the watchdog

Annotations
@Override