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)
AdvancedHostResolver
remapHosts
in interface AdvancedHostResolver
hostRemappings
- Map of <original hostname, remapped hostname>
public void remapHost(String originalHost, String remappedHost)
AdvancedHostResolver
remapHost
in interface AdvancedHostResolver
originalHost
- 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)
AdvancedHostResolver
removeHostRemapping
in interface AdvancedHostResolver
originalHost
- currently-remapped hostnamepublic void clearHostRemappings()
AdvancedHostResolver
clearHostRemappings
in interface AdvancedHostResolver
public Map<String,String> getHostRemappings()
AdvancedHostResolver
getHostRemappings
in interface AdvancedHostResolver
<original hostname, remapped hostname>
public Collection<String> getOriginalHostnames(String remappedHost)
AdvancedHostResolver
getOriginalHostnames
in interface AdvancedHostResolver
remappedHost
- remapped hostnamepublic void clearDNSCache()
AdvancedHostResolver
clearDNSCache
in interface AdvancedHostResolver
public void setPositiveDNSCacheTimeout(int timeout, TimeUnit timeUnit)
AdvancedHostResolver
setPositiveDNSCacheTimeout
in interface AdvancedHostResolver
timeout
- maximum lookup timetimeUnit
- units of the timeout valuepublic void setNegativeDNSCacheTimeout(int timeout, TimeUnit timeUnit)
AdvancedHostResolver
setNegativeDNSCacheTimeout
in interface AdvancedHostResolver
timeout
- maximum lookup timetimeUnit
- units of the timeout valuepublic Collection<InetAddress> resolve(String host)
HostResolver
resolve
in interface HostResolver
host
- host to resolveCopyright © 2017. All rights reserved.