WaitFor (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs, class: WaitFor

# Class WaitFor

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.taskdefs.condition.ConditionBase
org.apache.tools.ant.taskdefs.WaitFor

All Implemented Interfaces:
  `Cloneable`

Direct Known Subclasses:
  `BlockFor`

public class WaitFor extends ConditionBase
Wait for an external event to occur. Wait for an external process to start or to complete some task. This is useful with the `parallel` task to synchronize the execution of tests with server startup. The following attributes can be specified on a waitfor task:

- maxwait - maximum length of time to wait before giving up
- maxwaitunit - The unit to be used to interpret maxwait attribute
- checkevery - amount of time to sleep between each check
- checkeveryunit - The unit to be used to interpret checkevery attribute
- timeoutproperty - name of a property to set if maxwait has been exceeded.

The maxwaitunit and checkeveryunit are allowed to have the following values: millisecond, second, minute, hour, day and week. The default is millisecond. For programmatic use/subclassing, there are two methods that may be overridden, `processSuccess` and `processTimeout`

Since:
  Ant 1.5

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `WaitFor.Unit`
  The enumeration of units: millisecond, second, minute, hour, day, week

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final long`
  `DEFAULT_CHECK_MILLIS`
  default check time
  `static final long`
  `DEFAULT_MAX_WAIT_MILLIS`
  default wait time
  `static final long`
  `ONE_DAY`
  a day in milliseconds
  `static final long`
  `ONE_HOUR`
  an hour in milliseconds
  `static final long`
  `ONE_MILLISECOND`
  a millisecond
  `static final long`
  `ONE_MINUTE`
  a minute in milliseconds
  `static final long`
  `ONE_SECOND`
  a second in milliseconds
  `static final long`
  `ONE_WEEK`
  a week in milliseconds

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WaitFor()`
  Constructor, names this task "waitfor".
  `WaitFor(String taskName)`
  Constructor that takes the name of the task in the task name.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `calculateCheckEveryMillis()`
  Get the check wait time, in milliseconds.
  `long`
  `calculateMaxWaitMillis()`
  Get the maximum wait time, in milliseconds.
  `void`
  `execute()`
  Check repeatedly for the specified conditions until they become true or the timeout expires.
  `protected void`
  `processSuccess()`
  Actions to be taken on a successful waitfor.
  `protected void`
  `processTimeout()`
  Actions to be taken on an unsuccessful wait.
  `void`
  `setCheckEvery(long time)`
  Set the time between each check
  `void`
  `setCheckEveryUnit(WaitFor.Unit unit)`
  Set the check every time unit
  `void`
  `setMaxWait(long time)`
  Set the maximum length of time to wait.
  `void`
  `setMaxWaitUnit(WaitFor.Unit unit)`
  Set the max wait time unit
  `void`
  `setTimeoutProperty(String p)`
  Name the property to set after a timeout.

  ### Methods inherited from class ConditionBase

  `add, addAnd, addAvailable, addChecksum, addContains, addEquals, addFilesMatch, addHttp, addIsFalse, addIsFileSelected, addIsReference, addIsSet, addIsTrue, addNot, addOr, addOs, addSocket, addUptodate, countConditions, getConditions, getTaskName, setTaskName`
  Modifier and Type
  Method
  Description
  `void`
  `add(Condition c)`
  Add an arbitrary condition
  `void`
  `addAnd(And a)`
  Add an <and> condition "container".
  `void`
  `addAvailable(Available a)`
  Add an <available> condition.
  `void`
  `addChecksum(Checksum c)`
  Add an <checksum> condition.
  `void`
  `addContains(Contains test)`
  Add a <contains> condition.
  `void`
  `addEquals(Equals e)`
  Add an <equals> condition.
  `void`
  `addFilesMatch(FilesMatch test)`
  Add a <filesmatch> condition.
  `void`
  `addHttp(Http h)`
  Add an <http> condition.
  `void`
  `addIsFalse(IsFalse test)`
  Add a <isfalse> condition.
  `void`
  `addIsFileSelected(IsFileSelected test)`
  Add an <isfileselected> condition.
  `void`
  `addIsReference(IsReference i)`
  Add an <isreference> condition.
  `void`
  `addIsSet(IsSet i)`
  Add an <isset> condition.
  `void`
  `addIsTrue(IsTrue test)`
  Add a <istrue> condition.
  `void`
  `addNot(Not n)`
  Add an <not> condition "container".
  `void`
  `addOr(Or o)`
  Add an <or> condition "container".
  `void`
  `addOs(Os o)`
  Add an <os> condition.
  `void`
  `addSocket(Socket s)`
  Add a <socket> condition.
  `void`
  `addUptodate(UpToDate u)`
  Add an <uptodate> condition.
  `protected int`
  `countConditions()`
  Count the conditions.
  `protected final Enumeration<Condition>`
  `getConditions()`
  Iterate through all conditions.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ONE_MILLISECOND

    public static final long ONE_MILLISECOND
    a millisecond
    See Also:
      - Constant Field Values

  - ### ONE_SECOND

    public static final long ONE_SECOND
    a second in milliseconds
    See Also:
      - Constant Field Values

  - ### ONE_MINUTE

    public static final long ONE_MINUTE
    a minute in milliseconds
    See Also:
      - Constant Field Values

  - ### ONE_HOUR

    public static final long ONE_HOUR
    an hour in milliseconds
    See Also:
      - Constant Field Values

  - ### ONE_DAY

    public static final long ONE_DAY
    a day in milliseconds
    See Also:
      - Constant Field Values

  - ### ONE_WEEK

    public static final long ONE_WEEK
    a week in milliseconds
    See Also:
      - Constant Field Values

  - ### DEFAULT_MAX_WAIT_MILLIS

    public static final long DEFAULT_MAX_WAIT_MILLIS
    default wait time
    See Also:
      - Constant Field Values

  - ### DEFAULT_CHECK_MILLIS

    public static final long DEFAULT_CHECK_MILLIS
    default check time
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### WaitFor

    public WaitFor()
    Constructor, names this task "waitfor".

  - ### WaitFor

    public WaitFor(String taskName)
    Constructor that takes the name of the task in the task name.
    Parameters:
      `taskName` - the name of the task.
    Since:
      Ant 1.8

- ## Method Details

  - ### setMaxWait

    public void setMaxWait(long time)
    Set the maximum length of time to wait.
    Parameters:
      `time` - a `long` value

  - ### setMaxWaitUnit

    public void setMaxWaitUnit(WaitFor.Unit unit)
    Set the max wait time unit
    Parameters:
      `unit` - an enumerated `Unit` value

  - ### setCheckEvery

    public void setCheckEvery(long time)
    Set the time between each check
    Parameters:
      `time` - a `long` value

  - ### setCheckEveryUnit

    public void setCheckEveryUnit(WaitFor.Unit unit)
    Set the check every time unit
    Parameters:
      `unit` - an enumerated `Unit` value

  - ### setTimeoutProperty

    public void setTimeoutProperty(String p)
    Name the property to set after a timeout.
    Parameters:
      `p` - the property name

  - ### execute

    public void execute() throws BuildException
    Check repeatedly for the specified conditions until they become true or the timeout expires.
    Throws:
      `BuildException` - on error

  - ### calculateCheckEveryMillis

    public long calculateCheckEveryMillis()
    Get the check wait time, in milliseconds.
    Returns:
      how long to wait between checks
    Since:
      Ant 1.8

  - ### calculateMaxWaitMillis

    public long calculateMaxWaitMillis()
    Get the maximum wait time, in milliseconds.
    Returns:
      how long to wait before timing out
    Since:
      Ant 1.8

  - ### processSuccess

    protected void processSuccess()
    Actions to be taken on a successful waitfor. This is an override point. The base implementation does nothing.
    Since:
      Ant1.7

  - ### processTimeout

    protected void processTimeout()
    Actions to be taken on an unsuccessful wait. This is an override point. It is where the timeout processing takes place. The base implementation sets the timeoutproperty if there was a timeout and the property was defined.
    Since:
      Ant1.7