Package com.unboundid.ldap.sdk
Class CachingNameResolver
java.lang.Object
com.unboundid.ldap.sdk.NameResolver
com.unboundid.ldap.sdk.CachingNameResolver
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class CachingNameResolver
extends NameResolver
This class provides an implementation of a
NameResolver that will
cache lookups to potentially improve performance and provide a degree of
resiliency against name service outages.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of this caching name resolver that will use a default timeout.CachingNameResolver(int timeoutMillis) Creates a new instance of this caching name resolver that will use the specified timeout. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all information from the name resolver cache.getAllByName(String host) Retrieves an array ofInetAddressobjects that encapsulate all known IP addresses associated with the provided host name.getAllByNameInternal(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.intRetrieves the length of time, in milliseconds, that cache records should be considered valid.voidtoString(StringBuilder buffer) Appends a string representation of this name resolver to the provided buffer.Methods inherited from class com.unboundid.ldap.sdk.NameResolver
setJVMSuccessfulLookupCacheTTLSeconds, setJVMUnsuccessfulLookupCacheTTLSeconds, toString
-
Constructor Details
-
CachingNameResolver
public CachingNameResolver()Creates a new instance of this caching name resolver that will use a default timeout. -
CachingNameResolver
Creates a new instance of this caching name resolver that will use the specified timeout.- Parameters:
timeoutMillis- The length of time, in milliseconds, that cache records should be considered valid. It must be greater than zero. If a record has been in the cache for less than this period of time, then the cached record will be used instead of making a name service call. If a record has been in the cache for longer than this period of time, then the cached record will only be used if it is not possible to get an updated version of the record from the name service.
-
-
Method Details
-
getTimeoutMillis
Retrieves the length of time, in milliseconds, that cache records should be considered valid. If a record has been in the cache for less than this period fo time, then the cached record will be used instead of making a name service call. If a record has been in the cache for longer than this period of time, then the cached record will only be used if it is not possible to get an updated version of the record from the name service.- Returns:
- The length of time, in milliseconds, that cache records should be considered valid.
-
getByName
@NotNull public InetAddress getByName(@Nullable String host) throws UnknownHostException, SecurityException Retrieves anInetAddressthat encapsulates an IP address associated with the provided host name.- Overrides:
getByNamein classNameResolver- 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.- Overrides:
getAllByNamein classNameResolver- 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.
-
getAllByNameInternal
@NotNull public InetAddress[] getAllByNameInternal(@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.- Overrides:
getHostNamein classNameResolver- 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.- Overrides:
getCanonicalHostNamein classNameResolver- 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.- Overrides:
getLocalHostin classNameResolver- 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.- Overrides:
getLoopbackAddressin classNameResolver- Returns:
- The loopback address for the system.
-
clearCache
Clears all information from the name resolver cache. -
toString
Appends a string representation of this name resolver to the provided buffer.- Specified by:
toStringin classNameResolver- Parameters:
buffer- A buffer to which the string representation should be appended.
-