Class DnsResolverGroupBuilder
AddressResolverGroup
which builds AddressResolver
s that update DNS caches
automatically. Standard DnsNameResolver
will only expire a cache entry after TTL,
meaning DNS queries after TTL will always take time to resolve. A refreshing AddressResolver
on the other hand updates the DNS cache automatically when TTL elapses,
meaning DNS queries after TTL will retrieve a refreshed result right away. If refreshing fails,
the AddressResolver
will retry with autoRefreshBackoff(Backoff)
.-
Method Summary
Modifier and TypeMethodDescriptionautoRefreshBackoff
(Backoff refreshBackoff) Sets theBackoff
which is used when theDnsNameResolver
fails to update the cache.autoRefreshTimeout
(Duration timeout) Sets the timeout after which a refreshingDnsRecord
should expire.autoRefreshTimeout
(ToLongFunction<? super String> timeoutFunction) Sets theToLongFunction
which determines how long theDnsRecord
s for a hostname should be refreshed after the first cache.autoRefreshTimeoutMillis
(long timeoutMillis) Sets the timeout in milliseconds after which a refreshingDnsRecord
should expire.Sets the Caffeine specification string of the cache that stores the domain names and their resolved addresses.decodeIdn
(boolean decodeIdn) Sets if the domain and host names should be decoded to unicode when received.Deprecated.dnsQueryLifecycleObserverFactory
(DnsQueryLifecycleObserverFactory observerFactory) Sets theDnsQueryLifecycleObserverFactory
that is used to generate objects which can observe individual DNS queries.dnsServerAddressStreamProvider
(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) Deprecated.enableAutoRefresh
(boolean autoRefresh) Sets whether to enable auto refresh for expiredDnsRecord
s.enableDnsQueryMetrics
(boolean enable) Enables the defaultDnsQueryLifecycleObserverFactory
that collects DNS query metrics throughMeterRegistry
.hostsFileEntriesResolver
(HostsFileEntriesResolver hostsFileEntriesResolver) Sets theHostsFileEntriesResolver
which is used to first check if the hostname is locally aliased.maxPayloadSize
(int maxPayloadSize) Sets the capacity of the datagram packet buffer in bytes.maxQueriesPerResolve
(int maxQueriesPerResolve) Sets the base value of maximum allowed number of DNS queries to send when resolving a host name.meterRegistry
(MeterRegistry meterRegistry) SetsMeterRegistry
to collect the DNS query metrics.ndots
(int ndots) Sets the number of dots which must appear in a name before an initial absolute query is made.negativeTtl
(int negativeTtl) Sets the TTL of the cache for the failed DNS queries in seconds.optResourceEnabled
(boolean optResourceEnabled) Enables the automatic inclusion of an optional records that tries to give the remote DNS server a hint about how much data the resolver can read per response.queryTimeout
(Duration queryTimeout) Sets the timeout of the DNS query performed by this resolver.queryTimeoutForEachAttempt
(Duration queryTimeoutForEachAttempt) Sets the timeout of each DNS query performed by this endpoint group.queryTimeoutMillis
(long queryTimeoutMillis) Sets the timeout of the DNS query performed by this resolver in milliseconds.queryTimeoutMillisForEachAttempt
(long queryTimeoutMillisForEachAttempt) Sets the timeout of each DNS query performed by this endpoint group in milliseconds.recursionDesired
(boolean recursionDesired) Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.refreshBackoff
(Backoff refreshBackoff) Deprecated.resolvedAddressTypes
(ResolvedAddressTypes resolvedAddressTypes) SetsResolvedAddressTypes
which is the list of the protocol families of the address resolved.searchDomains
(Iterable<String> searchDomains) Sets the list of search domains of the resolver.searchDomains
(String... searchDomains) Sets the search domains of the resolver.serverAddresses
(Iterable<InetSocketAddress> serverAddresses) Sets the DNS server addresses to send queries to.serverAddresses
(InetSocketAddress... serverAddresses) Sets the DNS server addresses to send queries to.serverAddressStreamProvider
(DnsServerAddressStreamProvider serverAddressStreamProvider) Sets theDnsServerAddressStreamProvider
which is used to determine which DNS server is used to resolve each hostname.traceEnabled
(boolean traceEnabled) Sets if this resolver should generate detailed trace information in exception messages so that it is easier to understand the cause of resolution failure.ttl
(int minTtl, int maxTtl) Sets the minimum and maximum TTL of the cached DNS resource records in seconds.Methods inherited from class com.linecorp.armeria.client.AbstractDnsResolverBuilder
buildConfigurator, cacheSpec, hostsFileEntriesResolver, maxTtl, maybeCreateDnsCache, meterRegistry, minTtl, ndots, negativeTtl, queryTimeoutMillis, searchDomains, serverAddressStreamProvider
-
Method Details
-
refreshBackoff
Deprecated.UseautoRefreshBackoff(Backoff)
instead.SetsBackoff
which is used when theDnsNameResolver
fails to update the cache. -
resolvedAddressTypes
SetsResolvedAddressTypes
which is the list of the protocol families of the address resolved. -
enableAutoRefresh
-
autoRefreshBackoff
Sets theBackoff
which is used when theDnsNameResolver
fails to update the cache. -
autoRefreshTimeout
@UnstableApi public DnsResolverGroupBuilder autoRefreshTimeout(ToLongFunction<? super String> timeoutFunction) Sets theToLongFunction
which determines how long theDnsRecord
s for a hostname should be refreshed after the first cache. TheToLongFunction
should return the refresh timeout in milliseconds. If a non-positive number is returned, theDnsRecord
s are removed immediately without refresh.Note that the timeout function is called whenever the cached
DnsRecord
s expire.For example:
AtomicInteger refreshCounter = new AtomicInteger(MAX_NUM_REFRESH); dnsResolverGroupBuilder.autoRefreshTimeout(hostname -> { if (hostname.endsWith("busy.domain.com")) { return Duration.ofDays(7).toMillis(); // Automatically refresh the cached domain for 7 days. } if (hostname.endsWith("sporadic.domain.dom")) { return 0; // Don't need to refresh a sporadically used domain. } if (hostname.endsWith("counting.domain.dom")) { // Allow refreshing up to MAX_NUM_REFRESH times. if (refreshCounter.getAndDecrease() > 0) { return Long.MAX_VALUE; } else { refreshCounter.set(MAX_NUM_REFRESH); return 0; } } ... }); -
autoRefreshTimeout
Sets the timeout after which a refreshingDnsRecord
should expire. If this option is unspecified andenableAutoRefresh(boolean)
is set totrue
, a cachedDnsRecord
is automatically refreshed until theClientFactory
is closed.Duration.ZERO
disables the timeout. -
autoRefreshTimeoutMillis
Sets the timeout in milliseconds after which a refreshingDnsRecord
should expire. If this option is unspecified andenableAutoRefresh(boolean)
is set totrue
, a cachedDnsRecord
is automatically refreshed until theClientFactory
is closed.0
disables the timeout. -
traceEnabled
Description copied from class:AbstractDnsResolverBuilder
Sets if this resolver should generate detailed trace information in exception messages so that it is easier to understand the cause of resolution failure. This flag is enabled by default.- Overrides:
traceEnabled
in classAbstractDnsResolverBuilder
-
queryTimeout
Description copied from class:AbstractDnsResolverBuilder
Sets the timeout of the DNS query performed by this resolver.0
disables the timeout. If unspecified, 5000 ms will be used.- Overrides:
queryTimeout
in classAbstractDnsResolverBuilder
-
queryTimeoutMillis
Description copied from class:AbstractDnsResolverBuilder
Sets the timeout of the DNS query performed by this resolver in milliseconds.0
disables the timeout. If unspecified, 5000 ms will be used.- Overrides:
queryTimeoutMillis
in classAbstractDnsResolverBuilder
-
queryTimeoutForEachAttempt
Description copied from class:AbstractDnsResolverBuilder
Sets the timeout of each DNS query performed by this endpoint group. This option is useful if you want to set a timeout for each search domain resolution. If unspecified, the value ofAbstractDnsResolverBuilder.queryTimeout(Duration)
is used.- Overrides:
queryTimeoutForEachAttempt
in classAbstractDnsResolverBuilder
-
queryTimeoutMillisForEachAttempt
public DnsResolverGroupBuilder queryTimeoutMillisForEachAttempt(long queryTimeoutMillisForEachAttempt) Description copied from class:AbstractDnsResolverBuilder
Sets the timeout of each DNS query performed by this endpoint group in milliseconds. This option is useful if you want to set a timeout for each search domain resolution. If unspecified, the value ofAbstractDnsResolverBuilder.queryTimeoutMillis(long)
is used.- Overrides:
queryTimeoutMillisForEachAttempt
in classAbstractDnsResolverBuilder
-
recursionDesired
Description copied from class:AbstractDnsResolverBuilder
Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set. This flag is enabled by default.- Overrides:
recursionDesired
in classAbstractDnsResolverBuilder
-
maxQueriesPerResolve
Description copied from class:AbstractDnsResolverBuilder
Sets the base value of maximum allowed number of DNS queries to send when resolving a host name. The actual maximum allowed number of queries will be multiplied by theDnsServerAddressStream.size()
. For example, ifmaxQueriesPerResolve
is 5 andDnsServerAddressStream.size()
is 2, DNS queries can be executed up to 10 times. TheDnsServerAddressStream
is provided byDnsServerAddressStreamProvider
. -
serverAddresses
Description copied from class:AbstractDnsResolverBuilder
Sets the DNS server addresses to send queries to. Operating system default is used by default.- Overrides:
serverAddresses
in classAbstractDnsResolverBuilder
-
serverAddresses
Description copied from class:AbstractDnsResolverBuilder
Sets the DNS server addresses to send queries to. Operating system default is used by default.- Overrides:
serverAddresses
in classAbstractDnsResolverBuilder
-
serverAddressStreamProvider
public DnsResolverGroupBuilder serverAddressStreamProvider(DnsServerAddressStreamProvider serverAddressStreamProvider) Description copied from class:AbstractDnsResolverBuilder
Sets theDnsServerAddressStreamProvider
which is used to determine which DNS server is used to resolve each hostname.- Overrides:
serverAddressStreamProvider
in classAbstractDnsResolverBuilder
-
dnsServerAddressStreamProvider
@Deprecated public DnsResolverGroupBuilder dnsServerAddressStreamProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) Deprecated.Description copied from class:AbstractDnsResolverBuilder
Sets theDnsServerAddressStreamProvider
which is used to determine which DNS server is used to resolve each hostname.- Overrides:
dnsServerAddressStreamProvider
in classAbstractDnsResolverBuilder
-
maxPayloadSize
Description copied from class:AbstractDnsResolverBuilder
Sets the capacity of the datagram packet buffer in bytes.- Overrides:
maxPayloadSize
in classAbstractDnsResolverBuilder
-
optResourceEnabled
Description copied from class:AbstractDnsResolverBuilder
Enables the automatic inclusion of an optional records that tries to give the remote DNS server a hint about how much data the resolver can read per response. Some DNS Server may not support this and so fail to answer queries.- Overrides:
optResourceEnabled
in classAbstractDnsResolverBuilder
-
hostsFileEntriesResolver
public DnsResolverGroupBuilder hostsFileEntriesResolver(HostsFileEntriesResolver hostsFileEntriesResolver) Description copied from class:AbstractDnsResolverBuilder
Sets theHostsFileEntriesResolver
which is used to first check if the hostname is locally aliased.- Overrides:
hostsFileEntriesResolver
in classAbstractDnsResolverBuilder
-
dnsQueryLifecycleObserverFactory
public DnsResolverGroupBuilder dnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory observerFactory) Description copied from class:AbstractDnsResolverBuilder
Sets theDnsQueryLifecycleObserverFactory
that is used to generate objects which can observe individual DNS queries.- Overrides:
dnsQueryLifecycleObserverFactory
in classAbstractDnsResolverBuilder
-
disableDnsQueryMetrics
Deprecated.Description copied from class:AbstractDnsResolverBuilder
Disables the defaultDnsQueryLifecycleObserverFactory
that collects DNS query metrics throughMeterRegistry
.- Overrides:
disableDnsQueryMetrics
in classAbstractDnsResolverBuilder
-
searchDomains
Description copied from class:AbstractDnsResolverBuilder
Sets the search domains of the resolver.- Overrides:
searchDomains
in classAbstractDnsResolverBuilder
-
searchDomains
Description copied from class:AbstractDnsResolverBuilder
Sets the list of search domains of the resolver.- Overrides:
searchDomains
in classAbstractDnsResolverBuilder
-
ndots
Description copied from class:AbstractDnsResolverBuilder
Sets the number of dots which must appear in a name before an initial absolute query is made.- Overrides:
ndots
in classAbstractDnsResolverBuilder
-
decodeIdn
Description copied from class:AbstractDnsResolverBuilder
Sets if the domain and host names should be decoded to unicode when received. See rfc3492. This flag is enabled by default.- Overrides:
decodeIdn
in classAbstractDnsResolverBuilder
-
meterRegistry
Description copied from class:AbstractDnsResolverBuilder
SetsMeterRegistry
to collect the DNS query metrics.- Overrides:
meterRegistry
in classAbstractDnsResolverBuilder
-
cacheSpec
Description copied from class:AbstractDnsResolverBuilder
Sets the Caffeine specification string of the cache that stores the domain names and their resolved addresses. If not set,Flags.dnsCacheSpec()
is used by default.Note that
AbstractDnsResolverBuilder.cacheSpec(String)
andAbstractDnsResolverBuilder.dnsCache(DnsCache)
are mutually exclusive.- Overrides:
cacheSpec
in classAbstractDnsResolverBuilder
-
ttl
Description copied from class:AbstractDnsResolverBuilder
Sets the minimum and maximum TTL of the cached DNS resource records in seconds. If the TTL of the DNS resource record returned by the DNS server is less than the minimum TTL or greater than the maximum TTL, this resolver will ignore the TTL from the DNS server and use the minimum TTL or the maximum TTL instead respectively. The default value is1
andInteger.MAX_VALUE
, which practically tells this resolver to respect the TTL from the DNS server.Note that
AbstractDnsResolverBuilder.ttl(int, int)
andAbstractDnsResolverBuilder.dnsCache(DnsCache)
are mutually exclusive.- Overrides:
ttl
in classAbstractDnsResolverBuilder
-
negativeTtl
Description copied from class:AbstractDnsResolverBuilder
Sets the TTL of the cache for the failed DNS queries in seconds. The default value is0
which means that the DNS resolver does not cache when DNS queries are failed.Note that
AbstractDnsResolverBuilder.negativeTtl(int)
andAbstractDnsResolverBuilder.dnsCache(DnsCache)
are mutually exclusive.- Overrides:
negativeTtl
in classAbstractDnsResolverBuilder
-
dnsCache
Description copied from class:AbstractDnsResolverBuilder
Sets theDnsCache
that caches the resolvedDnsRecord
s and the cause of a failure if negative cache is activated. This option is useful if you want to share aDnsCache
with multiple DNS resolvers. If unspecified, the defaultDnsCache
is used.Note that if
AbstractDnsResolverBuilder.cacheSpec(String)
,AbstractDnsResolverBuilder.ttl(int, int)
, orAbstractDnsResolverBuilder.negativeTtl(int)
is set, the DNS resolver will create its ownDnsCache
using the properties. Therefore,AbstractDnsResolverBuilder.cacheSpec(String)
,AbstractDnsResolverBuilder.ttl(int, int)
, andAbstractDnsResolverBuilder.negativeTtl(int)
are mutually exclusive withAbstractDnsResolverBuilder.dnsCache(DnsCache)
.- Overrides:
dnsCache
in classAbstractDnsResolverBuilder
-
enableDnsQueryMetrics
Description copied from class:AbstractDnsResolverBuilder
Enables the defaultDnsQueryLifecycleObserverFactory
that collects DNS query metrics throughMeterRegistry
. This option is enabled by default.- Overrides:
enableDnsQueryMetrics
in classAbstractDnsResolverBuilder
-
autoRefreshBackoff(Backoff)
instead.