Class IsReachable
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.taskdefs.condition.IsReachable
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable,- Condition
 
 public class IsReachable extends ProjectComponent implements Condition 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 SummaryFields Modifier and Type Field Description static intDEFAULT_TIMEOUTThe default timeout.static java.lang.StringERROR_BAD_TIMEOUTError when invalid timeout value is definedstatic java.lang.StringERROR_BAD_URLError message when an invalid url is used.static java.lang.StringERROR_BOTH_TARGETSError message when url and host are specified.static java.lang.StringERROR_NO_HOST_IN_URLError message when no hostname in url.static java.lang.StringERROR_NO_HOSTNAMEError when no hostname is definedstatic java.lang.StringERROR_ON_NETWORKNetwork error message is seen.static java.lang.StringMETHOD_NAMEDeprecated.Since 1.10.6static java.lang.StringMSG_NO_REACHABLE_TESTError message when no reachably test avail.- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Constructor SummaryConstructors Constructor Description IsReachable()
 - 
Method SummaryModifier and Type Method Description booleaneval()Evaluate the condition.voidsetHost(java.lang.String host)Set the host to ping.voidsetTimeout(int timeout)Set the timeout for the reachability test in seconds.voidsetUrl(java.lang.String url)Set the URL from which to extract the hostname.- 
Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Field Detail- 
DEFAULT_TIMEOUTpublic static final int DEFAULT_TIMEOUT The default timeout.- See Also:
- Constant Field Values
 
 - 
ERROR_NO_HOSTNAMEpublic static final java.lang.String ERROR_NO_HOSTNAME Error when no hostname is defined- See Also:
- Constant Field Values
 
 - 
ERROR_BAD_TIMEOUTpublic static final java.lang.String ERROR_BAD_TIMEOUT Error when invalid timeout value is defined- See Also:
- Constant Field Values
 
 - 
ERROR_ON_NETWORKpublic static final java.lang.String ERROR_ON_NETWORK Network error message is seen.- See Also:
- Constant Field Values
 
 - 
ERROR_BOTH_TARGETSpublic static final java.lang.String ERROR_BOTH_TARGETS Error message when url and host are specified.- See Also:
- Constant Field Values
 
 - 
MSG_NO_REACHABLE_TESTpublic static final java.lang.String MSG_NO_REACHABLE_TEST Error message when no reachably test avail.- See Also:
- Constant Field Values
 
 - 
ERROR_BAD_URLpublic static final java.lang.String ERROR_BAD_URL Error message when an invalid url is used.- See Also:
- Constant Field Values
 
 - 
ERROR_NO_HOST_IN_URLpublic static final java.lang.String ERROR_NO_HOST_IN_URL Error message when no hostname in url.- See Also:
- Constant Field Values
 
 - 
METHOD_NAME@Deprecated public static final java.lang.String METHOD_NAME Deprecated.Since 1.10.6The method name to look for in InetAddress- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
setHostpublic void setHost(java.lang.String host) Set the host to ping.- Parameters:
- host- the host to ping.
 
 - 
setUrlpublic void setUrl(java.lang.String url) Set 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.
 
 - 
evalpublic boolean eval() throws BuildExceptionEvaluate the condition.- Specified by:
- evalin interface- Condition
- Returns:
- true if the condition is true.
- Throws:
- BuildException- if an error occurs
 
 
- 
 
-