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

public Class IsReachable

extends ProjectComponent
implements Condition
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.condition.Condition
Imports
java.io.IOException, java.net.InetAddress, .MalformedURLException, .URL, .UnknownHostException, org.apache.tools.ant.BuildException, .Project, .ProjectComponent

Test for a host being reachable using ICMP "ping" packets & echo operations. Ping packets are very reliable for assessing reachability in a LAN or WAN, but they do not get through any well-configured firewall. Echo (port 7) may.

This condition turns unknown host exceptions into false conditions. This is because on a laptop, DNS is one of the first services lost when the network goes; you are implicitly offline.

If a URL is supplied instead of a host, the hostname is extracted and used in the test--all other parts of the URL are discarded.

The test may not work through firewalls; that is, something may be reachable using a protocol such as HTTP, while the lower level ICMP packets get dropped on the floor. Similarly, a host may be detected as reachable with ICMP, but not reachable on other ports (i.e. port 80), because of firewalls.

Since
Ant 1.7

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_TIMEOUT

The default timeout.

public static final String
ERROR_BAD_TIMEOUT

Error when invalid timeout value is defined

public static final String
ERROR_BAD_URL

Error message when an invalid url is used.

public static final String
ERROR_BOTH_TARGETS

Error message when url and host are specified.

public static final String
ERROR_NO_HOST_IN_URL

Error message when no hostname in url.

public static final String
ERROR_NO_HOSTNAME

Error when no hostname is defined

public static final String
ERROR_ON_NETWORK

Network error message is seen.

private String
public static final String
METHOD_NAME

The method name to look for in InetAddress

public static final String
MSG_NO_REACHABLE_TEST

Error message when no reachably test avail.

private static final int
private int
private String
private static final String
WARN_UNKNOWN_HOST

Unknown host message is seen.

Inherited from org.apache.tools.ant.ProjectComponent:
descriptionlocationproject

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the condition is true.
eval
()

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Evaluate the condition.
private boolean

Returns:

true if it is isNullOrEmpty
isNullOrEmpty
(final String
param to check
string
)

emptyness test

public void
setHost(final String
the host to ping.
host
)

Set the host to ping.

public void
setTimeout(final int
the timeout in seconds.
timeout
)

Set the timeout for the reachability test in seconds.

public void
setUrl(final String
a URL object.
url
)

Set the URL from which to extract the hostname.

Inherited from org.apache.tools.ant.ProjectComponent:
clonegetDescriptiongetLocationgetProjectloglogsetDescriptionsetLocationsetProject

Field Detail

DEFAULT_TIMEOUTback to summary
public static final int DEFAULT_TIMEOUT

The default timeout.

ERROR_BAD_TIMEOUTback to summary
public static final String ERROR_BAD_TIMEOUT

Error when invalid timeout value is defined

ERROR_BAD_URLback to summary
public static final String ERROR_BAD_URL

Error message when an invalid url is used.

ERROR_BOTH_TARGETSback to summary
public static final String ERROR_BOTH_TARGETS

Error message when url and host are specified.

ERROR_NO_HOST_IN_URLback to summary
public static final String ERROR_NO_HOST_IN_URL

Error message when no hostname in url.

ERROR_NO_HOSTNAMEback to summary
public static final String ERROR_NO_HOSTNAME

Error when no hostname is defined

ERROR_ON_NETWORKback to summary
public static final String ERROR_ON_NETWORK

Network error message is seen.

hostback to summary
private String host
METHOD_NAMEback to summary
public static final String METHOD_NAME

Deprecated

Since 1.10.6

The method name to look for in InetAddress

Annotations
@Deprecated
MSG_NO_REACHABLE_TESTback to summary
public static final String MSG_NO_REACHABLE_TEST

Error message when no reachably test avail.

SECONDback to summary
private static final int SECOND
timeoutback to summary
private int timeout
urlback to summary
private String url
WARN_UNKNOWN_HOSTback to summary
private static final String WARN_UNKNOWN_HOST

Unknown host message is seen.

Constructor Detail

IsReachableback to summary
public IsReachable()

Method Detail

evalback to summary
public boolean eval() throws BuildException

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Evaluate the condition.

Returns:boolean

true if the condition is true.

Annotations
@Override
Exceptions
BuildException:
if an error occurs
isNullOrEmptyback to summary
private boolean isNullOrEmpty(final String string)

emptyness test

Parameters
string:String

param to check

Returns:boolean

true if it is isNullOrEmpty

setHostback to summary
public void setHost(final String host)

Set the host to ping.

Parameters
host:String

the host to ping.

setTimeoutback to summary
public void setTimeout(final int timeout)

Set the timeout for the reachability test in seconds.

Parameters
timeout:int

the timeout in seconds.

setUrlback to summary
public void setUrl(final String url)

Set the URL from which to extract the hostname.

Parameters
url:String

a URL object.