|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.common.network.HostAddressService
public class HostAddressService
Implements a service for performing operations on Internet addresses, such as testing liveness. This class is designed to make calls to ping hosts as robust and as simple as possible, at the cost of a little more up-front configuration in some cases, for example to set timeouts.
This class is thread-safe through the use of synchronized methods to access the method table and enabled names list. The timeout is volatile, which obviates the need for synchronization.
| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT
Default Java ping method using InetAddress.isReachable(). |
static java.lang.String |
PING
Ping method using operating system ping command. |
| Constructor Summary | |
|---|---|
HostAddressService(boolean autoEnable)
Creates a new service. |
|
| Method Summary | |
|---|---|
PingNotification |
_isReachableByMethod(java.lang.String name,
HostAddress host)
|
void |
addMethod(java.lang.String name,
java.lang.String methodClass,
boolean enable)
Adds a ping method to the service. |
static boolean |
addressesAreEqual(java.lang.String host1,
java.lang.String host2)
This method returns true if the host addresses are equal to each other, otherwise false. |
static boolean |
addressesAreInSameSubnet(java.lang.String host1,
java.lang.String host2,
short prefix)
Given a pair of addresses and a single network prefix, determines if hosts are on the same subnet. |
void |
enableMethod(java.lang.String name)
Enables a ping method. |
java.util.List<java.lang.String> |
getAvailableMethodNames()
Returns names of available ping methods, whether enabled or not. |
static HostAddress |
getByName(java.lang.String host)
Returns a host address instance. |
static java.lang.String |
getCanonicalAddress(java.lang.String host)
This method returns the host address, in string format, or UNKNOWN if there's a problem resolving the address. |
java.util.List<java.lang.String> |
getEnabledMethodNames()
Returns names of available ping methods. |
static short |
getLocalNetworkPrefix(java.lang.String hostName)
This method returns a prefix for a given internet address. |
java.lang.String |
getMethodName(java.lang.String name)
Returns a ping method by name or null if no such method exists. |
int |
getTimeout()
Returns current timeout in milliseconds. |
PingResponse |
isReachable(HostAddress host)
Returns true if the host is reachable by an available ping method. |
PingResponse |
isReachableByMethod(java.lang.String name,
HostAddress host)
Returns true if the host is reachable by an available ping method. |
static byte[] |
netMaskFromPrefixLength(short prefix)
|
void |
setTimeout(int timeoutMillis)
Sets the timeout for ping methods. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static java.lang.String DEFAULT
public static java.lang.String PING
| Constructor Detail |
|---|
public HostAddressService(boolean autoEnable)
throws HostException
autoEnable - If true, enable ping methods automatically.
HostException - Thrown if there is a problem enabling a method| Method Detail |
|---|
public void setTimeout(int timeoutMillis)
timeoutMillis - Timeout in millisecondspublic int getTimeout()
public void addMethod(java.lang.String name,
java.lang.String methodClass,
boolean enable)
throws HostException
name - Logical name of the methodmethodClass - Method class nameenable - If true, enable the method for use
HostException - Thrown if there is a problem enabling a method.
public void enableMethod(java.lang.String name)
throws HostException
name - of method to enable
HostException - Thrown if method name does not existpublic java.util.List<java.lang.String> getAvailableMethodNames()
public java.util.List<java.lang.String> getEnabledMethodNames()
public java.lang.String getMethodName(java.lang.String name)
public static HostAddress getByName(java.lang.String host)
throws java.net.UnknownHostException
java.net.UnknownHostExceptionpublic static java.lang.String getCanonicalAddress(java.lang.String host)
host -
public static boolean addressesAreInSameSubnet(java.lang.String host1,
java.lang.String host2,
short prefix)
throws java.lang.Exception
java.lang.Exception
public static boolean addressesAreEqual(java.lang.String host1,
java.lang.String host2)
host1 - host2 -
public PingResponse isReachable(HostAddress host)
throws HostException
host - Name of host for which we want to test reachability
HostException - Thrown if a ping method fails
public PingResponse isReachableByMethod(java.lang.String name,
HostAddress host)
throws HostException
name - Name of ping method to usehost - Name of host for which we want to test reachability
HostException - Thrown if a ping method fails
public PingNotification _isReachableByMethod(java.lang.String name,
HostAddress host)
throws HostException
HostException
public static short getLocalNetworkPrefix(java.lang.String hostName)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] netMaskFromPrefixLength(short prefix)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||