Class DnsNameResolverBuilder
- java.lang.Object
-
- io.netty.resolver.dns.DnsNameResolverBuilder
-
public final class DnsNameResolverBuilder extends java.lang.Object
ADnsNameResolver
builder.
-
-
Constructor Summary
Constructors Constructor Description DnsNameResolverBuilder()
Creates a new builder.DnsNameResolverBuilder(EventLoop eventLoop)
Creates a new builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DnsNameResolverBuilder
authoritativeDnsServerCache(AuthoritativeDnsServerCache authoritativeDnsServerCache)
Sets the cache for authoritative NS serversDnsNameResolverBuilder
authoritativeDnsServerCache(DnsCache authoritativeDnsServerCache)
Deprecated.DnsNameResolver
build()
Returns a newDnsNameResolver
instance.protected ChannelFactory<? extends DatagramChannel>
channelFactory()
Deprecated.DnsNameResolverBuilder
channelFactory(ChannelFactory<? extends DatagramChannel> datagramChannelFactory)
Deprecated.DnsNameResolverBuilder
channelType(java.lang.Class<? extends DatagramChannel> channelType)
Deprecated.DnsNameResolverBuilder
cnameCache(DnsCnameCache cnameCache)
Sets the cache forCNAME
mappings.DnsNameResolverBuilder
completeOncePreferredResolved(boolean completeOncePreferredResolved)
Iftrue
SimpleNameResolver.resolveAll(String)
will notify the returnedFuture
as soon as all queries for the preferred address-type are complete.static ResolvedAddressTypes
computeResolvedAddressTypes(InternetProtocolFamily... internetProtocolFamilies)
Deprecated.DnsNameResolverBuilder
consolidateCacheSize(int maxNumConsolidation)
Set the maximum size of the cache that is used to consolidate lookups for different hostnames when in-flight.DnsNameResolverBuilder
copy()
Creates a copy of thisDnsNameResolverBuilder
DnsNameResolverBuilder
datagramChannelFactory(ChannelFactory<? extends DatagramChannel> datagramChannelFactory)
Sets theChannelFactory
that will create aDatagramChannel
.DnsNameResolverBuilder
datagramChannelStrategy(DnsNameResolverChannelStrategy datagramChannelStrategy)
Set the strategy that is used to determine how aDatagramChannel
is used by the resolver for sending queries over UDP protocol.DnsNameResolverBuilder
datagramChannelType(java.lang.Class<? extends DatagramChannel> channelType)
Sets theChannelFactory
as aReflectiveChannelFactory
of this type.DnsNameResolverBuilder
decodeIdn(boolean decodeIdn)
Set if domain / host names should be decoded to unicode when received.DnsNameResolverBuilder
dnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory lifecycleObserverFactory)
Set the factory used to generate objects which can observe individual DNS queries.DnsNameResolverBuilder
eventLoop(EventLoop eventLoop)
Sets theEventLoop
which will perform the communication with the DNS servers.DnsNameResolverBuilder
hostsFileEntriesResolver(HostsFileEntriesResolver hostsFileEntriesResolver)
DnsNameResolverBuilder
localAddress(java.net.SocketAddress localAddress)
Configure the address that will be used to bind too.DnsNameResolverBuilder
maxPayloadSize(int maxPayloadSize)
Sets the capacity of the datagram packet buffer (in bytes).DnsNameResolverBuilder
maxQueriesPerResolve(int maxQueriesPerResolve)
Sets the maximum allowed number of DNS queries to send when resolving a host name.protected DnsServerAddressStreamProvider
nameServerProvider()
DnsNameResolverBuilder
nameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider)
Set theDnsServerAddressStreamProvider
which is used to determine which DNS server is used to resolve each hostname.DnsNameResolverBuilder
ndots(int ndots)
Set the number of dots which must appear in a name before an initial absolute query is made.DnsNameResolverBuilder
negativeTtl(int negativeTtl)
Sets the TTL of the cache for the failed DNS queries (in seconds).DnsNameResolverBuilder
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.protected DnsServerAddressStream
queryServerAddressStream()
DnsNameResolverBuilder
queryServerAddressStream(DnsServerAddressStream queryServerAddressStream)
Set theDnsServerAddressStream
which provides the server address for DNS queries.DnsNameResolverBuilder
queryTimeoutMillis(long queryTimeoutMillis)
Sets the timeout of each DNS query performed by this resolver (in milliseconds).DnsNameResolverBuilder
recursionDesired(boolean recursionDesired)
Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.DnsNameResolverBuilder
resolveCache(DnsCache resolveCache)
Sets the cache for resolution results.DnsNameResolverBuilder
resolvedAddressTypes(ResolvedAddressTypes resolvedAddressTypes)
Sets the list of the protocol families of the address resolved.DnsNameResolverBuilder
searchDomains(java.lang.Iterable<java.lang.String> searchDomains)
Set the list of search domains of the resolver.DnsNameResolverBuilder
socketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory)
DnsNameResolverBuilder
socketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory, boolean retryOnTimeout)
DnsNameResolverBuilder
socketChannelType(java.lang.Class<? extends SocketChannel> channelType)
DnsNameResolverBuilder
socketChannelType(java.lang.Class<? extends SocketChannel> channelType, boolean retryOnTimeout)
static ResolvedAddressTypes
toResolvedAddressTypes(SocketProtocolFamily... socketProtocolFamilies)
Compute aResolvedAddressTypes
from someSocketProtocolFamily
s.DnsNameResolverBuilder
traceEnabled(boolean traceEnabled)
Deprecated.Prefer to configure aLoggingDnsQueryLifeCycleObserverFactory
instead.DnsNameResolverBuilder
ttl(int minTtl, int maxTtl)
Sets the minimum and maximum TTL of the cached DNS resource records (in seconds).
-
-
-
Method Detail
-
eventLoop
public DnsNameResolverBuilder eventLoop(EventLoop eventLoop)
Sets theEventLoop
which will perform the communication with the DNS servers.- Parameters:
eventLoop
- theEventLoop
- Returns:
this
-
channelFactory
@Deprecated protected ChannelFactory<? extends DatagramChannel> channelFactory()
Deprecated.
-
channelFactory
@Deprecated public DnsNameResolverBuilder channelFactory(ChannelFactory<? extends DatagramChannel> datagramChannelFactory)
Deprecated.Sets theChannelFactory
that will create aDatagramChannel
.If TCP fallback should be supported as well it is required to call the
or {@link #socketChannelType(Class)}
method.- Parameters:
datagramChannelFactory
- theChannelFactory
- Returns:
this
-
datagramChannelFactory
public DnsNameResolverBuilder datagramChannelFactory(ChannelFactory<? extends DatagramChannel> datagramChannelFactory)
Sets theChannelFactory
that will create aDatagramChannel
.If TCP fallback should be supported as well it is required to call the
or {@link #socketChannelType(Class)}
method.- Parameters:
datagramChannelFactory
- theChannelFactory
- Returns:
this
-
channelType
@Deprecated public DnsNameResolverBuilder channelType(java.lang.Class<? extends DatagramChannel> channelType)
Deprecated.Sets theChannelFactory
as aReflectiveChannelFactory
of this type. Use as an alternative tochannelFactory(ChannelFactory)
.If TCP fallback should be supported as well it is required to call the
or {@link #socketChannelType(Class)}
method.- Parameters:
channelType
- the type- Returns:
this
-
datagramChannelType
public DnsNameResolverBuilder datagramChannelType(java.lang.Class<? extends DatagramChannel> channelType)
Sets theChannelFactory
as aReflectiveChannelFactory
of this type. Use as an alternative todatagramChannelFactory(ChannelFactory)
.If TCP fallback should be supported as well it is required to call the
or {@link #socketChannelType(Class)}
method.- Parameters:
channelType
- the type- Returns:
this
-
socketChannelFactory
public DnsNameResolverBuilder socketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory)
Sets theChannelFactory
that will create aSocketChannel
for TCP fallback if needed.TCP fallback is not enabled by default and must be enabled by providing a non-null
ChannelFactory
for this method.- Parameters:
channelFactory
- theChannelFactory
ornull
if TCP fallback should not be supported. By default, TCP fallback is not enabled.- Returns:
this
-
socketChannelType
public DnsNameResolverBuilder socketChannelType(java.lang.Class<? extends SocketChannel> channelType)
Sets theChannelFactory
as aReflectiveChannelFactory
of this type for TCP fallback if needed. Use as an alternative tosocketChannelFactory(ChannelFactory)
.TCP fallback is not enabled by default and must be enabled by providing a non-null
channelType
for this method.- Parameters:
channelType
- the type ornull
if TCP fallback should not be supported. By default, TCP fallback is not enabled.- Returns:
this
-
socketChannelFactory
public DnsNameResolverBuilder socketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory, boolean retryOnTimeout)
Sets theChannelFactory
that will create aSocketChannel
for TCP fallback if needed.TCP fallback is not enabled by default and must be enabled by providing a non-null
ChannelFactory
for this method.- Parameters:
channelFactory
- theChannelFactory
ornull
if TCP fallback should not be supported. By default, TCP fallback is not enabled.retryOnTimeout
- iftrue
theDnsNameResolver
will also fallback to TCP if a timeout was detected, iffalse
it will only try to use TCP if the response was marked as truncated.- Returns:
this
-
socketChannelType
public DnsNameResolverBuilder socketChannelType(java.lang.Class<? extends SocketChannel> channelType, boolean retryOnTimeout)
Sets theChannelFactory
as aReflectiveChannelFactory
of this type for TCP fallback if needed. Use as an alternative tosocketChannelFactory(ChannelFactory)
.TCP fallback is not enabled by default and must be enabled by providing a non-null
channelType
for this method.- Parameters:
channelType
- the type ornull
if TCP fallback should not be supported. By default, TCP fallback is not enabled.retryOnTimeout
- iftrue
theDnsNameResolver
will also fallback to TCP if a timeout was detected, iffalse
it will only try to use TCP if the response was marked as truncated.- Returns:
this
-
resolveCache
public DnsNameResolverBuilder resolveCache(DnsCache resolveCache)
Sets the cache for resolution results.- Parameters:
resolveCache
- the DNS resolution results cache- Returns:
this
-
cnameCache
public DnsNameResolverBuilder cnameCache(DnsCnameCache cnameCache)
Sets the cache forCNAME
mappings.- Parameters:
cnameCache
- the cache used to cacheCNAME
mappings for a domain.- Returns:
this
-
dnsQueryLifecycleObserverFactory
public DnsNameResolverBuilder dnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory lifecycleObserverFactory)
Set the factory used to generate objects which can observe individual DNS queries.- Parameters:
lifecycleObserverFactory
- the factory used to generate objects which can observe individual DNS queries.- Returns:
this
-
authoritativeDnsServerCache
@Deprecated public DnsNameResolverBuilder authoritativeDnsServerCache(DnsCache authoritativeDnsServerCache)
Deprecated.Sets the cache for authoritative NS servers- Parameters:
authoritativeDnsServerCache
- the authoritative NS servers cache- Returns:
this
-
authoritativeDnsServerCache
public DnsNameResolverBuilder authoritativeDnsServerCache(AuthoritativeDnsServerCache authoritativeDnsServerCache)
Sets the cache for authoritative NS servers- Parameters:
authoritativeDnsServerCache
- the authoritative NS servers cache- Returns:
this
-
localAddress
public DnsNameResolverBuilder localAddress(java.net.SocketAddress localAddress)
Configure the address that will be used to bind too. Ifnull
the default will be used.- Parameters:
localAddress
- the bind address- Returns:
this
-
ttl
public DnsNameResolverBuilder ttl(int minTtl, int maxTtl)
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 is0
andInteger.MAX_VALUE
, which practically tells this resolver to respect the TTL from the DNS server.- Parameters:
minTtl
- the minimum TTLmaxTtl
- the maximum TTL- Returns:
this
-
negativeTtl
public DnsNameResolverBuilder negativeTtl(int negativeTtl)
Sets the TTL of the cache for the failed DNS queries (in seconds).- Parameters:
negativeTtl
- the TTL for failed cached queries- Returns:
this
-
queryTimeoutMillis
public DnsNameResolverBuilder queryTimeoutMillis(long queryTimeoutMillis)
Sets the timeout of each DNS query performed by this resolver (in milliseconds).0
disables the timeout. If not set or a negative number is set, the default timeout is used.- Parameters:
queryTimeoutMillis
- the query timeout- Returns:
this
-
computeResolvedAddressTypes
@Deprecated public static ResolvedAddressTypes computeResolvedAddressTypes(InternetProtocolFamily... internetProtocolFamilies)
Deprecated.Compute aResolvedAddressTypes
from someInternetProtocolFamily
s. An empty input will return the default value, based on "java.net" System properties. Valid inputs are (), (IPv4), (IPv6), (Ipv4, IPv6) and (IPv6, IPv4).- Parameters:
internetProtocolFamilies
- a valid sequence ofInternetProtocolFamily
s- Returns:
- a
ResolvedAddressTypes
-
toResolvedAddressTypes
public static ResolvedAddressTypes toResolvedAddressTypes(SocketProtocolFamily... socketProtocolFamilies)
Compute aResolvedAddressTypes
from someSocketProtocolFamily
s. An empty input will return the default value, based on "java.net" System properties. Valid inputs are (), (IPv4), (IPv6), (Ipv4, IPv6) and (IPv6, IPv4).- Parameters:
socketProtocolFamilies
- a valid sequence ofSocketProtocolFamily
s- Returns:
- a
ResolvedAddressTypes
-
resolvedAddressTypes
public DnsNameResolverBuilder resolvedAddressTypes(ResolvedAddressTypes resolvedAddressTypes)
Sets the list of the protocol families of the address resolved. You can usecomputeResolvedAddressTypes(InternetProtocolFamily...)
to get aResolvedAddressTypes
out of someInternetProtocolFamily
s.- Parameters:
resolvedAddressTypes
- the address types- Returns:
this
-
completeOncePreferredResolved
public DnsNameResolverBuilder completeOncePreferredResolved(boolean completeOncePreferredResolved)
Iftrue
SimpleNameResolver.resolveAll(String)
will notify the returnedFuture
as soon as all queries for the preferred address-type are complete.- Parameters:
completeOncePreferredResolved
-true
to enable,false
to disable.- Returns:
this
-
recursionDesired
public DnsNameResolverBuilder recursionDesired(boolean recursionDesired)
Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.- Parameters:
recursionDesired
- true if recursion is desired- Returns:
this
-
maxQueriesPerResolve
public DnsNameResolverBuilder maxQueriesPerResolve(int maxQueriesPerResolve)
Sets the maximum allowed number of DNS queries to send when resolving a host name.- Parameters:
maxQueriesPerResolve
- the max number of queries- Returns:
this
-
traceEnabled
@Deprecated public DnsNameResolverBuilder traceEnabled(boolean traceEnabled)
Deprecated.Prefer to configure aLoggingDnsQueryLifeCycleObserverFactory
instead.Sets if this resolver should generate the detailed trace information in an exception message so that it is easier to understand the cause of resolution failure.- Parameters:
traceEnabled
- true if trace is enabled- Returns:
this
-
maxPayloadSize
public DnsNameResolverBuilder maxPayloadSize(int maxPayloadSize)
Sets the capacity of the datagram packet buffer (in bytes). The default value is4096
bytes.- Parameters:
maxPayloadSize
- the capacity of the datagram packet buffer- Returns:
this
-
optResourceEnabled
public DnsNameResolverBuilder 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
-
hostsFileEntriesResolver
public DnsNameResolverBuilder hostsFileEntriesResolver(HostsFileEntriesResolver hostsFileEntriesResolver)
- Parameters:
hostsFileEntriesResolver
- theHostsFileEntriesResolver
used to first check if the hostname is locally aliased.- Returns:
this
-
nameServerProvider
protected DnsServerAddressStreamProvider nameServerProvider()
-
nameServerProvider
public DnsNameResolverBuilder nameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider)
Set theDnsServerAddressStreamProvider
which is used to determine which DNS server is used to resolve each hostname.- Returns:
this
.
-
queryServerAddressStream
protected DnsServerAddressStream queryServerAddressStream()
-
queryServerAddressStream
public DnsNameResolverBuilder queryServerAddressStream(DnsServerAddressStream queryServerAddressStream)
Set theDnsServerAddressStream
which provides the server address for DNS queries.- Returns:
this
.
-
searchDomains
public DnsNameResolverBuilder searchDomains(java.lang.Iterable<java.lang.String> searchDomains)
Set the list of search domains of the resolver.- Parameters:
searchDomains
- the search domains- Returns:
this
-
ndots
public DnsNameResolverBuilder ndots(int ndots)
Set the number of dots which must appear in a name before an initial absolute query is made. The default value is1
.- Parameters:
ndots
- the ndots value- Returns:
this
-
decodeIdn
public DnsNameResolverBuilder decodeIdn(boolean decodeIdn)
Set if domain / host names should be decoded to unicode when received. See rfc3492.- Parameters:
decodeIdn
- if should get decoded- Returns:
this
-
consolidateCacheSize
public DnsNameResolverBuilder consolidateCacheSize(int maxNumConsolidation)
Set the maximum size of the cache that is used to consolidate lookups for different hostnames when in-flight. 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:
maxNumConsolidation
- the maximum lookups to consolidate (different hostnames), or0
if no consolidation should be performed.- Returns:
this
-
datagramChannelStrategy
public DnsNameResolverBuilder datagramChannelStrategy(DnsNameResolverChannelStrategy datagramChannelStrategy)
Set the strategy that is used to determine how aDatagramChannel
is used by the resolver for sending queries over UDP protocol.- Parameters:
datagramChannelStrategy
- theDnsNameResolverChannelStrategy
to use when doing queries over UDP protocol.- Returns:
this
-
build
public DnsNameResolver build()
Returns a newDnsNameResolver
instance.- Returns:
- a
DnsNameResolver
-
copy
public DnsNameResolverBuilder copy()
Creates a copy of thisDnsNameResolverBuilder
- Returns:
DnsNameResolverBuilder
-
-