Interface DnsServiceDiscovererBuilder

All Known Implementing Classes:
DefaultDnsServiceDiscovererBuilder, DelegatingDnsServiceDiscovererBuilder

public interface DnsServiceDiscovererBuilder
Builder for DNS ServiceDiscoverer which will attempt to resolve A, AAAA, CNAME, and SRV type queries.
  • Method Details

    • consolidateCacheSize

      default DnsServiceDiscovererBuilder consolidateCacheSize(int 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, or 0 if no consolidation should be performed.
      Returns:
      this.
    • ttl

      DnsServiceDiscovererBuilder ttl(int minSeconds, int maxSeconds)
      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 than 0.
      maxSeconds - The maximum about of time the result will be considered valid (in seconds), must be greater than or equal to minSeconds.
      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 than 0.
      maxSeconds - The maximum about of time the result will be considered valid (in seconds), must be greater than or equal to minSeconds.
      minCacheSeconds - The minimum about of time the result will be cached locally (in seconds), must be greater than or equal to 0, and less than or equal to minSeconds.
      maxCacheSeconds - The maximum about of time the result will be cached locally (in seconds), must be greater than or equal to minCacheSeconds, and less than or equal to maxSeconds.
      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 than 0.
      maxSeconds - The maximum about of time the result will be considered valid (in seconds), must be greater than or equal to minSeconds.
      minCacheSeconds - The minimum about of time the result will be cached locally (in seconds), must be greater than or equal to 0, and less than or equal to minSeconds.
      maxCacheSeconds - The maximum about of time the result will be cached locally (in seconds), must be greater than or equal to minCacheSeconds, and less than or equal to maxSeconds.
      negativeCacheSeconds - The amount of time an unsuccessful (failed) result will be cached locally (in seconds), must be greater than or equal to 0. If other overloads are used, the default value will recognize the standard Java system property networkaddress.cache.negative.ttl, like InetAddress does.
      Returns:
      this.
      See Also:
    • ttlJitter

      DnsServiceDiscovererBuilder ttlJitter(Duration 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

      default DnsServiceDiscovererBuilder localAddress(@Nullable SocketAddress localAddress)
      Set the local SocketAddress to bind to.
      Parameters:
      localAddress - the local SocketAddress to bind to or null 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 the DnsServerAddressStreamProvider which determines which DNS server should be used per query.
      Parameters:
      dnsServerAddressStreamProvider - the DnsServerAddressStreamProvider which determines which DNS server should be used per query.
      Returns:
      this.
    • optResourceEnabled

      DnsServiceDiscovererBuilder 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. 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

      DnsServiceDiscovererBuilder maxUdpPayloadSize(int 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

      DnsServiceDiscovererBuilder ndots(int ndots)
      Set the number of dots which must appear in a name before an initial absolute query is made.
      Parameters:
      ndots - the ndots value.
      Returns:
      this.
    • queryTimeout

      DnsServiceDiscovererBuilder queryTimeout(Duration queryTimeout)
      Sets the timeout of each DNS query performed by this service discoverer.
      Parameters:
      queryTimeout - the query timeout value
      Returns:
      this.
    • dnsResolverAddressTypes

      DnsServiceDiscovererBuilder dnsResolverAddressTypes(@Nullable DnsResolverAddressTypes dnsResolverAddressTypes)
      Sets the list of the protocol families of the address resolved.
      Parameters:
      dnsResolverAddressTypes - the address types or null to use the default value, based on "java.net" system properties: java.net.preferIPv4Stack and java.net.preferIPv6Stack.
      Returns:
      this.
    • ioExecutor

      DnsServiceDiscovererBuilder ioExecutor(IoExecutor ioExecutor)
      Sets the IoExecutor.
      Parameters:
      ioExecutor - IoExecutor to use.
      Returns:
      this.
    • observer

      Sets a DnsServiceDiscovererObserver that provides visibility into DNS ServiceDiscoverer built by this builder.
      Parameters:
      observer - a DnsServiceDiscovererObserver that provides visibility into DNS ServiceDiscoverer built by this builder
      Returns:
      this.
    • missingRecordStatus

      Sets which ServiceDiscovererEvent.Status to use in ServiceDiscovererEvent.status() when a record for a previously seen address is missing in the response.
      Parameters:
      status - a ServiceDiscovererEvent.Status for missing records.
      Returns:
      this.
    • buildSrvDiscoverer

      Build a new ServiceDiscoverer which queries SRV Resource Records corresponding to serviceName. For each SRV answer capture the Port and resolve the Target.
      Returns:
      a new ServiceDiscoverer which queries SRV Resource Records corresponding to serviceName. For each SRV answer capture the Port and resolve the Target.
    • buildARecordDiscoverer

      Build a new ServiceDiscoverer which targets host addresses (e.g. A or AAAA records) and uses a fixed port derived from the HostAndPort.
      Returns:
      a new ServiceDiscoverer which targets host addresses (e.g. A or AAAA records) and uses a fixed port derived from the HostAndPort.