Class IsReachable
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 TypeFieldDescriptionstatic final int
The default timeout.static final String
Error when invalid timeout value is definedstatic final String
Error message when an invalid url is used.static final String
Error message when url and host are specified.static final String
Error message when no hostname in url.static final String
Error when no hostname is definedstatic final String
Network error message is seen.static final String
Deprecated.Since 1.10.6static final String
Error message when no reachably test avail.Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
-
Constructor Summary
-
Method Summary
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
-
Field Details
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTThe default timeout.- See Also:
-
ERROR_NO_HOSTNAME
-
ERROR_BAD_TIMEOUT
-
ERROR_ON_NETWORK
-
ERROR_BOTH_TARGETS
Error message when url and host are specified.- See Also:
-
MSG_NO_REACHABLE_TEST
Error message when no reachably test avail.- See Also:
-
ERROR_BAD_URL
-
ERROR_NO_HOST_IN_URL
-
METHOD_NAME
Deprecated.Since 1.10.6The method name to look for in InetAddress- See Also:
-
-
Constructor Details
-
IsReachable
public IsReachable()
-
-
Method Details
-
setHost
-
setUrl
Set the URL from which to extract the hostname.- Parameters:
url
- a URL object.
-
setTimeout
public void setTimeout(int timeout) Set the timeout for the reachability test in seconds.- Parameters:
timeout
- the timeout in seconds.
-
eval
Evaluate the condition.- Specified by:
eval
in interfaceCondition
- Returns:
- true if the condition is true.
- Throws:
BuildException
- if an error occurs
-