Package com.couchbase.client.core.utils
Class NetworkAddress
- java.lang.Object
-
- com.couchbase.client.core.utils.NetworkAddress
-
public class NetworkAddress extends Object
A convenient wrapper class around network primitives in Java. How IPv6 is handled: If a hostname is passed in as input instead of a literal IP address, then the class relies onInetAddress.getAllByName(String)
to perform a lookup. By default the JVM prefers IPv4 for this lookup in dual stack environments, unless the system property "java.net.preferIPv6Addresses" is set to true on startup. In this case, IPv6 is preferred and automatically selected. Note that there is one specific case where if IPv6 is preferred in dual stack and you are running Couchbase Server pre 5.1 which does not support IPv6, then you must set the system property "com.couchbase.forceIPv4" to true so that the firstly returned IPv6 address is ignored and we are looking for an IPv4 address to be resolved as well. Obviously, in a single IPv6 stack environment working with older Couchbase Server releases won't work.- Since:
- 1.4.6
- Author:
- Michael Nitschinger
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ALLOW_REVERSE_DNS
Flag which controls the usage of reverse dnsstatic boolean
FORCE_IPV4
Flag which controls if even if ipv6 is present, IPv4 should be preferred.static String
FORCE_IPV4_PROPERTY
static String
REVERSE_DNS_PROPERTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
address()
Returns the string IP representation for this network address.static NetworkAddress
create(String input)
Creates a newNetworkAddress
from either a hostname or ip address literal.boolean
equals(Object o)
int
hashCode()
String
hostname()
Returns the hostname for this network address.static NetworkAddress
localhost()
Creates a newNetworkAddress
for loopback.String
nameAndAddress()
Prints a safe representation of the hostname (if available) and the IP address.String
nameOrAddress()
Returns the hostname if available and if not returns the address.String
toString()
-
-
-
Field Detail
-
REVERSE_DNS_PROPERTY
public static final String REVERSE_DNS_PROPERTY
- See Also:
- Constant Field Values
-
FORCE_IPV4_PROPERTY
public static final String FORCE_IPV4_PROPERTY
- See Also:
- Constant Field Values
-
ALLOW_REVERSE_DNS
public static final boolean ALLOW_REVERSE_DNS
Flag which controls the usage of reverse dns
-
FORCE_IPV4
public static final boolean FORCE_IPV4
Flag which controls if even if ipv6 is present, IPv4 should be preferred.
-
-
Method Detail
-
create
public static NetworkAddress create(String input)
Creates a newNetworkAddress
from either a hostname or ip address literal.
-
localhost
public static NetworkAddress localhost()
Creates a newNetworkAddress
for loopback.
-
hostname
public String hostname()
Returns the hostname for this network address.- Returns:
- the hostname.
-
address
public String address()
Returns the string IP representation for this network address.- Returns:
- the IP address in string representation
-
nameOrAddress
public String nameOrAddress()
Returns the hostname if available and if not returns the address.- Returns:
- hostname or address, best effort.
-
nameAndAddress
public String nameAndAddress()
Prints a safe representation of the hostname (if available) and the IP address.- Returns:
- hostname and ip as a string
-
-