Interface DnsServiceDiscovererBuilder
- All Known Implementing Classes:
DefaultDnsServiceDiscovererBuilder
,DelegatingDnsServiceDiscovererBuilder
ServiceDiscoverer
which will attempt to
resolve A
, AAAA
, CNAME
, and SRV
type queries.-
Method Summary
Modifier and TypeMethodDescriptionBuild a newServiceDiscoverer
which targets host addresses (e.g.default DnsServiceDiscovererBuilder
consolidateCacheSize
(int consolidateCacheSize) Set the maximum size of the cache that is used to consolidate concurrent lookups for different hostnames.dnsResolverAddressTypes
(DnsResolverAddressTypes dnsResolverAddressTypes) Sets the list of the protocol families of the address resolved.dnsServerAddressStreamProvider
(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) Set theDnsServerAddressStreamProvider
which determines which DNS server should be used per query.ioExecutor
(IoExecutor ioExecutor) Sets theIoExecutor
.default DnsServiceDiscovererBuilder
localAddress
(SocketAddress localAddress) Set the localSocketAddress
to bind to.maxUdpPayloadSize
(int maxUdpPayloadSize) Set the maximum size of the receiving UDP datagram (in bytes).Sets whichServiceDiscovererEvent.Status
to use inServiceDiscovererEvent.status()
when a record for a previously seen address is missing in the response.ndots
(int ndots) Set the number of dots which must appear in a name before an initial absolute query is made.observer
(DnsServiceDiscovererObserver observer) Sets aDnsServiceDiscovererObserver
that provides visibility into DNSServiceDiscoverer
built by this builder.optResourceEnabled
(boolean optResourceEnabled) Enable the automatic inclusion of a 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 each DNS query performed by this service discoverer as part of a resolution request.default DnsServiceDiscovererBuilder
resolutionTimeout
(Duration resolutionTimeout) Sets the total timeout of each DNS resolution performed by this service discoverer.ttl
(int minSeconds, int maxSeconds) Controls min/max TTL values that will influence polling intervals.ttl
(int minSeconds, int maxSeconds, int minCacheSeconds, int maxCacheSeconds) Controls min/max TTL values that will affect polling intervals and local caching.default DnsServiceDiscovererBuilder
ttl
(int minSeconds, int maxSeconds, int minCacheSeconds, int maxCacheSeconds, int negativeCacheSeconds) Controls min/max TTL values that will affect polling intervals, local caching, and caching negative results.The jitter to apply for scheduling the next query after TTL to help spread out subsequent DNS queries.
-
Method Details
-
consolidateCacheSize
Set the maximum size of the cache that is used to consolidate concurrent lookups for different hostnames.This means if multiple lookups are done for the same hostname and still in-flight, only one actual query will be made and the result will be cascaded to the others.
- Parameters:
consolidateCacheSize
- The maximum number of different hostnames for consolidation of concurrent lookups, or0
if no consolidation should be performed.- Returns:
this
.
-
ttl
Controls min/max TTL values that will influence polling intervals.The created
ServiceDiscoverer
polls DNS server based on TTL value of the resolved records. Min/max values help to make sure polling stays within reasonable boundaries. Too frequent DNS queries may generate too much load for the DNS server, too rare DNS queries may lead to incorrect state if the remote servers changed IPs before original TTL expired.With this overload, there will be no local caching for resolved records.
- Parameters:
minSeconds
- The minimum about of time the result will be considered valid (in seconds), must be greater than0
.maxSeconds
- The maximum about of time the result will be considered valid (in seconds), must be greater than or equal tominSeconds
.- Returns:
this
.- See Also:
-
ttl
DnsServiceDiscovererBuilder ttl(int minSeconds, int maxSeconds, int minCacheSeconds, int maxCacheSeconds) Controls min/max TTL values that will affect polling intervals and local caching.The created
ServiceDiscoverer
polls DNS server based on TTL value of the resolved records. Min/max values help to make sure polling stays within reasonable boundaries. Too frequent DNS queries may generate too much load for the DNS server, too rare DNS queries may lead to incorrect state if the remote servers changed IPs before original TTL expired.The second min/max pair controls for how long the resolved records should be cached locally. Cache is helpful in scenarios when multiple concurrent resolutions are possible for the same address: either an application runs multiple client instances for the same hostname or clients perform DNS resolutions per new connection instead of background polling.
- Parameters:
minSeconds
- The minimum about of time the result will be considered valid (in seconds), must be greater than0
.maxSeconds
- The maximum about of time the result will be considered valid (in seconds), must be greater than or equal tominSeconds
.minCacheSeconds
- The minimum about of time the result will be cached locally (in seconds), must be greater than or equal to0
, and less than or equal tominSeconds
.maxCacheSeconds
- The maximum about of time the result will be cached locally (in seconds), must be greater than or equal tominCacheSeconds
, and less than or equal tomaxSeconds
.- Returns:
this
.- See Also:
-
ttl
default DnsServiceDiscovererBuilder ttl(int minSeconds, int maxSeconds, int minCacheSeconds, int maxCacheSeconds, int negativeCacheSeconds) Controls min/max TTL values that will affect polling intervals, local caching, and caching negative results.The created
ServiceDiscoverer
polls DNS server based on TTL value of the resolved records. Min/max values help to make sure polling stays within reasonable boundaries. Too frequent DNS queries may generate too much load for the DNS server, too rare DNS queries may lead to incorrect state if the remote servers changed IPs before original TTL expired.The second min/max pair controls for how long the resolved records should be cached locally. Cache is helpful in scenarios when multiple concurrent resolutions are possible for the same address: either an application runs multiple client instances for the same hostname or clients perform DNS resolutions per new connection instead of background polling.
- Parameters:
minSeconds
- The minimum about of time the result will be considered valid (in seconds), must be greater than0
.maxSeconds
- The maximum about of time the result will be considered valid (in seconds), must be greater than or equal tominSeconds
.minCacheSeconds
- The minimum about of time the result will be cached locally (in seconds), must be greater than or equal to0
, and less than or equal tominSeconds
.maxCacheSeconds
- The maximum about of time the result will be cached locally (in seconds), must be greater than or equal tominCacheSeconds
, and less than or equal tomaxSeconds
.negativeCacheSeconds
- The amount of time an unsuccessful (failed) result will be cached locally (in seconds), must be greater than or equal to0
. If other overloads are used, the default value will recognize the standard Java system propertynetworkaddress.cache.negative.ttl
, likeInetAddress
does.- Returns:
this
.- See Also:
-
ttlJitter
The jitter to apply for scheduling the next query after TTL to help spread out subsequent DNS queries.The jitter value will be added on top of the TTL value returned from the DNS server to avoid hitting the cache.
- Parameters:
ttlJitter
- The jitter to apply to schedule the next query after TTL.- Returns:
this
.
-
localAddress
Set the localSocketAddress
to bind to.- Parameters:
localAddress
- the localSocketAddress
to bind to ornull
to skip binding. When specified, all DNS queries will be sent from the specified address. When skipped, OS will automatically bind before sending frames but address won't be available in logs.- Returns:
this
.
-
dnsServerAddressStreamProvider
DnsServiceDiscovererBuilder dnsServerAddressStreamProvider(@Nullable DnsServerAddressStreamProvider dnsServerAddressStreamProvider) Set theDnsServerAddressStreamProvider
which determines which DNS server should be used per query.- Parameters:
dnsServerAddressStreamProvider
- theDnsServerAddressStreamProvider
which determines which DNS server should be used per query.- Returns:
this
.
-
optResourceEnabled
Enable the automatic inclusion of a optional records that tries to give the remote DNS server a hint about how much data the resolver can read per response. Some DNSServer may not support this and so fail to answer queries. If you find problems you may want to disable this.- Parameters:
optResourceEnabled
- if optional records inclusion is enabled.- Returns:
this
.
-
maxUdpPayloadSize
Set the maximum size of the receiving UDP datagram (in bytes).If the DNS response exceeds this amount the request will be automatically retried via TCP.
- Parameters:
maxUdpPayloadSize
- the maximum size of the receiving UDP datagram (in bytes)- Returns:
this
.
-
ndots
Set the number of dots which must appear in a name before an initial absolute query is made.If not set, the default value is read from
ndots
option of/etc/resolv.conf
).- Parameters:
ndots
- the ndots value.- Returns:
this
.
-
queryTimeout
Sets the timeout of each DNS query performed by this service discoverer as part of a resolution request.Zero (
0
) disables the timeout. If not set, the default value is read fromtimeout
option of/etc/resolv.conf
). Similar to linux systems, this value may be silently capped.- Parameters:
queryTimeout
- the query timeout value- Returns:
this
- See Also:
-
resolutionTimeout
Sets the total timeout of each DNS resolution performed by this service discoverer.Each resolution may execute one or more DNS queries, like following multiple CNAME(s) or trying different search domains. This is the total timeout for all intermediate queries involved in a single resolution request. Note, that SRV resolutions may generate independent resolutions for
A/AAAA
records. In this case, this timeout will be applied to anSRV
resolution and eachA/AAAA
resolution independently.Zero (
0
) disables the timeout. If not set, it defaults toquery timeout
value multiplied by2
.- Parameters:
resolutionTimeout
- the query timeout value- Returns:
this
- See Also:
-
dnsResolverAddressTypes
DnsServiceDiscovererBuilder dnsResolverAddressTypes(@Nullable DnsResolverAddressTypes dnsResolverAddressTypes) Sets the list of the protocol families of the address resolved.- Parameters:
dnsResolverAddressTypes
- the address types ornull
to use the default value, based on "java.net" system properties:java.net.preferIPv4Stack
andjava.net.preferIPv6Stack
.- Returns:
this
.
-
ioExecutor
Sets theIoExecutor
.- Parameters:
ioExecutor
-IoExecutor
to use.- Returns:
this
.
-
observer
Sets aDnsServiceDiscovererObserver
that provides visibility into DNSServiceDiscoverer
built by this builder.- Parameters:
observer
- aDnsServiceDiscovererObserver
that provides visibility into DNSServiceDiscoverer
built by this builder- Returns:
this
.
-
missingRecordStatus
Sets whichServiceDiscovererEvent.Status
to use inServiceDiscovererEvent.status()
when a record for a previously seen address is missing in the response.- Parameters:
status
- aServiceDiscovererEvent.Status
for missing records.- Returns:
this
.
-
buildSrvDiscoverer
ServiceDiscoverer<String,InetSocketAddress, buildSrvDiscoverer()ServiceDiscovererEvent<InetSocketAddress>> Build a newServiceDiscoverer
which queries SRV Resource Records corresponding toserviceName
. For each SRV answer capture the Port and resolve the Target.- Returns:
- a new
ServiceDiscoverer
which queries SRV Resource Records corresponding toserviceName
. For each SRV answer capture the Port and resolve the Target.
-
buildARecordDiscoverer
ServiceDiscoverer<HostAndPort,InetSocketAddress, buildARecordDiscoverer()ServiceDiscovererEvent<InetSocketAddress>> Build a newServiceDiscoverer
which targets host addresses (e.g. A or AAAA records) and uses a fixed port derived from theHostAndPort
.- Returns:
- a new
ServiceDiscoverer
which targets host addresses (e.g. A or AAAA records) and uses a fixed port derived from theHostAndPort
.
-