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 SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe default timeout.static final StringError when invalid timeout value is definedstatic final StringError message when an invalid url is used.static final StringError message when url and host are specified.static final StringError message when no hostname in url.static final StringError when no hostname is definedstatic final StringNetwork error message is seen.static final StringDeprecated.Since 1.10.6static final StringError message when no reachably test avail.Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryMethods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
- 
Field Details- 
DEFAULT_TIMEOUTpublic static final int DEFAULT_TIMEOUTThe default timeout.- See Also:
 
- 
ERROR_NO_HOSTNAMEError when no hostname is defined- See Also:
 
- 
ERROR_BAD_TIMEOUTError when invalid timeout value is defined- See Also:
 
- 
ERROR_ON_NETWORKNetwork error message is seen.- See Also:
 
- 
ERROR_BOTH_TARGETSError message when url and host are specified.- See Also:
 
- 
MSG_NO_REACHABLE_TESTError message when no reachably test avail.- See Also:
 
- 
ERROR_BAD_URLError message when an invalid url is used.- See Also:
 
- 
ERROR_NO_HOST_IN_URLError message when no hostname in url.- See Also:
 
- 
METHOD_NAMEDeprecated.Since 1.10.6The method name to look for in InetAddress- See Also:
 
 
- 
- 
Constructor Details- 
IsReachablepublic IsReachable()
 
- 
- 
Method Details- 
setHostSet the host to ping.- Parameters:
- host- the host to ping.
 
- 
setUrlSet the URL from which to extract the hostname.- Parameters:
- url- a URL object.
 
- 
setTimeoutpublic void setTimeout(int timeout) Set the timeout for the reachability test in seconds.- Parameters:
- timeout- the timeout in seconds.
 
- 
evalEvaluate the condition.- Specified by:
- evalin interface- Condition
- Returns:
- true if the condition is true.
- Throws:
- BuildException- if an error occurs
 
 
-