Package com.unboundid.ldap.sdk
Class NameResolver
java.lang.Object
com.unboundid.ldap.sdk.NameResolver
- Direct Known Subclasses:
CachingNameResolver,DefaultNameResolver
@Extensible
@ThreadSafety(level=INTERFACE_THREADSAFE)
public abstract class NameResolver
extends Object
This class defines an API that the LDAP SDK can use to resolve host names to
IP addresses, and vice versa. The default implementations of the name
resolution methods simply delegates to the corresponding methods provided in
the
InetAddress class. Subclasses may override these methods to
provide support for caching, improved instrumentation, or other
functionality. Any such methods that are not overridden will get the
JVM-default behavior.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance of this default name resolver. -
Method Summary
Modifier and TypeMethodDescriptiongetAllByName(String host) Retrieves an array ofInetAddressobjects that encapsulate all known IP addresses associated with the provided host name.Retrieves anInetAddressthat encapsulates an IP address associated with the provided host name.getCanonicalHostName(InetAddress inetAddress) Retrieves the canonical host name for the providedInetAddressobject.getHostName(InetAddress inetAddress) Retrieves the host name for the providedInetAddressobject.Retrieves the address of the local host.Retrieves the loopback address for the system.static voidsetJVMSuccessfulLookupCacheTTLSeconds(int seconds) Sets the length of time in seconds for which the JVM should cache the results of successful name service lookups.static voidsetJVMUnsuccessfulLookupCacheTTLSeconds(int seconds) Sets the length of time in seconds for which the JVM should cache the results of unsuccessful name service lookups (that is, lookups in which no mapping is found).final StringtoString()Retrieves a string representation of this name resolver.abstract voidtoString(StringBuilder buffer) Appends a string representation of this name resolver to the provided buffer.
-
Constructor Details
-
NameResolver
protected NameResolver()Creates a new instance of this default name resolver.
-
-
Method Details
-
getByName
@NotNull public InetAddress getByName(@Nullable String host) throws UnknownHostException, SecurityException Retrieves anInetAddressthat encapsulates an IP address associated with the provided host name.- Parameters:
host- The host name for which to retrieve a correspondingInetAddressobject. It can be a resolvable name or a textual representation of an IP address. If the provided name is the textual representation of an IPv6 address, then it can use either the form described in RFC 2373 or RFC 2732, or it can be an IPv6 scoped address. If it isnull, then the returned address should represent an address of the loopback interface.- Returns:
- An
InetAddressthat encapsulates an IP address associated with the provided host name. - Throws:
UnknownHostException- If the provided name cannot be resolved to its corresponding IP addresses.SecurityException- If a security manager prevents the name resolution attempt.
-
getAllByName
@NotNull public InetAddress[] getAllByName(@Nullable String host) throws UnknownHostException, SecurityException Retrieves an array ofInetAddressobjects that encapsulate all known IP addresses associated with the provided host name.- Parameters:
host- The host name for which to retrieve the correspondingInetAddressobjects. It can be a resolvable name or a textual representation of an IP address. If the provided name is the textual representation of an IPv6 address, then it can use either the form described in RFC 2373 or RFC 2732, or it can be an IPv6 scoped address. If it isnull, then the returned address should represent an address of the loopback interface.- Returns:
- An array of
InetAddressobjects that encapsulate all known IP addresses associated with the provided host name. - Throws:
UnknownHostException- If the provided name cannot be resolved to its corresponding IP addresses.SecurityException- If a security manager prevents the name resolution attempt.
-
getHostName
Retrieves the host name for the providedInetAddressobject.- Parameters:
inetAddress- The address for which to retrieve the host name. It must not benull.- Returns:
- The host name for the provided
InetAddressobject, or a textual representation of the IP address if the name cannot be determined.
-
getCanonicalHostName
Retrieves the canonical host name for the providedInetAddressobject.- Parameters:
inetAddress- The address for which to retrieve the canonical host name. It must not benull.- Returns:
- The canonical host name for the provided
InetAddressobject, or a textual representation of the IP address if the name cannot be determined.
-
getLocalHost
Retrieves the address of the local host. This should be the name of the host obtained from the system, converted to anInetAddress.- Returns:
- The address of the local host.
- Throws:
UnknownHostException- If the local host name cannot be resolved.SecurityException- If a security manager prevents the name resolution attempt.
-
getLoopbackAddress
Retrieves the loopback address for the system. This should be either the IPv4 loopback address of 127.0.0.1, or the IPv6 loopback address of ::1.- Returns:
- The loopback address for the system.
-
setJVMSuccessfulLookupCacheTTLSeconds
Sets the length of time in seconds for which the JVM should cache the results of successful name service lookups.
Note that this timeout only applies to lookups performed by the JVM itself and may not apply to all name resolver implementations. Some implementations may provide their own caching or their own lookup mechanisms that do not use this setting.- Parameters:
seconds- The length of time in seconds for which the JVM should cache the results of successful name service lookups. A value that is less than zero indicates that values should be cached forever.
-
setJVMUnsuccessfulLookupCacheTTLSeconds
Sets the length of time in seconds for which the JVM should cache the results of unsuccessful name service lookups (that is, lookups in which no mapping is found).
Note that this timeout only applies to lookups performed by the JVM itself and may not apply to all name resolver implementations. Some implementations may provide their own caching or their own lookup mechanisms that do not use this setting.- Parameters:
seconds- The length of time in seconds for which the JVM should cache the results of unsuccessful name service lookups. A value that is less than zero indicates that values should be cached forever.
-
toString
Retrieves a string representation of this name resolver. -
toString
Appends a string representation of this name resolver to the provided buffer.- Parameters:
buffer- A buffer to which the string representation should be appended.
-