public class ChainedHostResolver extends Object implements AdvancedHostResolver
AdvancedHostResolver that applies the AdvancedHostResolver methods to multiple implementations. Methods
are applied to the resolvers in the order specified when the ChainedHostResolver is constructed. AdvancedHostResolver methods that modify the
resolver are guaranteed to complete atomically over all resolvers. For example, if one thread makes a call to
resolve(String) while another thread is remapping hosts using
remapHost(String, String), the call to resolve(String) is guaranteed to
apply the newly-remapped hosts to all resolvers managed by this ChainedHostResolver, or to no resolvers, but the call to
resolve(String) will never result in the host name remappings applied only to "some" of the chained resolvers.
For getter methods (all read-only methods except resolve(String)), the ChainedHostResolver returns results from the first chained resolver.
The atomic write methods specified by AdvancedHostResolver are:
AdvancedHostResolver.remapHost(String, String)AdvancedHostResolver.remapHosts(java.util.Map)AdvancedHostResolver.removeHostRemapping(String)AdvancedHostResolver.clearHostRemappings()AdvancedHostResolver.setNegativeDNSCacheTimeout(int, java.util.concurrent.TimeUnit)AdvancedHostResolver.setPositiveDNSCacheTimeout(int, java.util.concurrent.TimeUnit)AdvancedHostResolver.clearDNSCache()| Constructor and Description |
|---|
ChainedHostResolver(Collection<? extends AdvancedHostResolver> resolvers)
Creates a ChainedHostResolver that applies
AdvancedHostResolver methods to the specified resolvers
in the order specified by the collection's iterator. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearDNSCache()
Clears both the positive (successful DNS lookups) and negative (failed DNS lookups) cache.
|
void |
clearHostRemappings()
Removes all hostname remappings.
|
Map<String,String> |
getHostRemappings()
Returns all host remappings in effect.
|
Collection<String> |
getOriginalHostnames(String remappedHost)
Returns the original address or addresses that are remapped to the specified remappedHost.
|
Collection<? extends AdvancedHostResolver> |
getResolvers()
Returns the resolvers used by this ChainedHostResolver.
|
void |
remapHost(String originalHost,
String remappedHost)
Remaps an individual host.
|
void |
remapHosts(Map<String,String> hostRemappings)
Replaces the host remappings in the existing list of remappings (if any) with the specified remappings.
|
void |
removeHostRemapping(String originalHost)
Removes the specified host remapping.
|
Collection<InetAddress> |
resolve(String host)
Resolves a hostname to one or more IP addresses.
|
void |
setNegativeDNSCacheTimeout(int timeout,
TimeUnit timeUnit)
Sets the negative (failed DNS lookup) timeout when making DNS lookups.
|
void |
setPositiveDNSCacheTimeout(int timeout,
TimeUnit timeUnit)
Sets the positive (successful DNS lookup) timeout when making DNS lookups.
|
public ChainedHostResolver(Collection<? extends AdvancedHostResolver> resolvers)
AdvancedHostResolver methods to the specified resolvers
in the order specified by the collection's iterator.resolvers - resolvers to invoke, in the order specified by the collection's iteratorpublic Collection<? extends AdvancedHostResolver> getResolvers()
public void remapHosts(Map<String,String> hostRemappings)
AdvancedHostResolverremapHosts in interface AdvancedHostResolverhostRemappings - Map of <original hostname, remapped hostname>public void remapHost(String originalHost, String remappedHost)
AdvancedHostResolverremapHost in interface AdvancedHostResolveroriginalHost - Original host to remap. Must exactly match the requested hostname (not a domain or regular expression match).remappedHost - hostname that will replace originalHostpublic void removeHostRemapping(String originalHost)
AdvancedHostResolverremoveHostRemapping in interface AdvancedHostResolveroriginalHost - currently-remapped hostnamepublic void clearHostRemappings()
AdvancedHostResolverclearHostRemappings in interface AdvancedHostResolverpublic Map<String,String> getHostRemappings()
AdvancedHostResolvergetHostRemappings in interface AdvancedHostResolver<original hostname, remapped hostname>public Collection<String> getOriginalHostnames(String remappedHost)
AdvancedHostResolvergetOriginalHostnames in interface AdvancedHostResolverremappedHost - remapped hostnamepublic void clearDNSCache()
AdvancedHostResolverclearDNSCache in interface AdvancedHostResolverpublic void setPositiveDNSCacheTimeout(int timeout,
TimeUnit timeUnit)
AdvancedHostResolversetPositiveDNSCacheTimeout in interface AdvancedHostResolvertimeout - maximum lookup timetimeUnit - units of the timeout valuepublic void setNegativeDNSCacheTimeout(int timeout,
TimeUnit timeUnit)
AdvancedHostResolversetNegativeDNSCacheTimeout in interface AdvancedHostResolvertimeout - maximum lookup timetimeUnit - units of the timeout valuepublic Collection<InetAddress> resolve(String host)
HostResolverresolve in interface HostResolverhost - host to resolveCopyright © 2016. All rights reserved.