org.apache.tools.ant.util

Class WorkerAnt

public class WorkerAnt extends Thread

A worker ant executes a single task in a background thread. After the run, any exception thrown is turned into a buildexception, which can be rethrown, the finished attribute is set, then notifyAll() is called, so that anyone waiting on the same notify object gets woken up.

This class is effectively a superset of TaskRunnable

Since: Ant 1.8

Field Summary
static StringERROR_NO_TASK
Error message if invoked with no task
Constructor Summary
WorkerAnt(Task task, Object notify)
Create the worker.
WorkerAnt(Task task)
Create the worker, using the worker as the notification point.
Method Summary
BuildExceptiongetBuildException()
Get any build exception.
ThrowablegetException()
Get whatever was thrown, which may or may not be a buildException.
TaskgetTask()
Get the task
booleanisFinished()
Query the task/thread for being finished.
voidrethrowAnyBuildException()
Raise an exception if one was caught
voidrun()
Run the task, which is skipped if null.
voidwaitUntilFinished(long timeout)
Block on the notify object and so wait until the thread is finished.

Field Detail

ERROR_NO_TASK

public static final String ERROR_NO_TASK
Error message if invoked with no task

Constructor Detail

WorkerAnt

public WorkerAnt(Task task, Object notify)
Create the worker.

This does not start the thread, merely configures it.

Parameters: task the task notify what to notify

WorkerAnt

public WorkerAnt(Task task)
Create the worker, using the worker as the notification point.

This does not start the thread, merely configures it.

Parameters: task the task

Method Detail

getBuildException

public BuildException getBuildException()
Get any build exception. This would seem to be oversynchronised, but know that Java pre-1.5 can reorder volatile access. The synchronized attribute is to force an ordering.

Returns: the exception or null

getException

public Throwable getException()
Get whatever was thrown, which may or may not be a buildException. Assertion: getException() instanceof BuildException <=> getBuildException()==getException()

Returns: the exception.

getTask

public Task getTask()
Get the task

Returns: the task

isFinished

public boolean isFinished()
Query the task/thread for being finished. This would seem to be oversynchronised, but know that Java pre-1.5 can reorder volatile access. The synchronized attribute is to force an ordering.

Returns: true if the task is finished.

rethrowAnyBuildException

public void rethrowAnyBuildException()
Raise an exception if one was caught

Throws: BuildException if one has been picked up

run

public void run()
Run the task, which is skipped if null. When invoked again, the task is re-run.

waitUntilFinished

public void waitUntilFinished(long timeout)
Block on the notify object and so wait until the thread is finished.

Parameters: timeout timeout in milliseconds

Throws: InterruptedException if the execution was interrupted