Package io.netty.resolver.dns
Class DnsNameResolverBuilder
- java.lang.Object
-
- io.netty.resolver.dns.DnsNameResolverBuilder
-
public final class DnsNameResolverBuilder extends java.lang.ObjectADnsNameResolverbuilder.
-
-
Field Summary
-
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 DnsNameResolverBuilderauthoritativeDnsServerCache(AuthoritativeDnsServerCache authoritativeDnsServerCache)Sets the cache for authoritative NS serversDnsNameResolverBuilderauthoritativeDnsServerCache(DnsCache authoritativeDnsServerCache)Deprecated.DnsNameResolverbuild()Returns a newDnsNameResolverinstance.protected ChannelFactory<? extends DatagramChannel>channelFactory()DnsNameResolverBuilderchannelFactory(ChannelFactory<? extends DatagramChannel> channelFactory)Sets theChannelFactorythat will create aDatagramChannel.DnsNameResolverBuilderchannelType(java.lang.Class<? extends DatagramChannel> channelType)Sets theChannelFactoryas aReflectiveChannelFactoryof this type.DnsNameResolverBuildercnameCache(DnsCnameCache cnameCache)Sets the cache forCNAMEmappings.DnsNameResolverBuildercompleteOncePreferredResolved(boolean completeOncePreferredResolved)IftrueSimpleNameResolver.resolveAll(String)will notify the returnedFutureas soon as all queries for the preferred address-type are complete.static ResolvedAddressTypescomputeResolvedAddressTypes(InternetProtocolFamily... internetProtocolFamilies)Compute aResolvedAddressTypesfrom someInternetProtocolFamilys.DnsNameResolverBuildercopy()Creates a copy of thisDnsNameResolverBuilderDnsNameResolverBuilderdecodeIdn(boolean decodeIdn)Set if domain / host names should be decoded to unicode when received.DnsNameResolverBuilderdnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory lifecycleObserverFactory)Set the factory used to generate objects which can observe individual DNS queries.DnsNameResolverBuildereventLoop(EventLoop eventLoop)Sets theEventLoopwhich will perform the communication with the DNS servers.DnsNameResolverBuilderhostsFileEntriesResolver(HostsFileEntriesResolver hostsFileEntriesResolver)DnsNameResolverBuildermaxPayloadSize(int maxPayloadSize)Sets the capacity of the datagram packet buffer (in bytes).DnsNameResolverBuildermaxQueriesPerResolve(int maxQueriesPerResolve)Sets the maximum allowed number of DNS queries to send when resolving a host name.protected DnsServerAddressStreamProvidernameServerProvider()DnsNameResolverBuildernameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider)Set theDnsServerAddressStreamProviderwhich is used to determine which DNS server is used to resolve each hostname.DnsNameResolverBuilderndots(int ndots)Set the number of dots which must appear in a name before an initial absolute query is made.DnsNameResolverBuildernegativeTtl(int negativeTtl)Sets the TTL of the cache for the failed DNS queries (in seconds).private AuthoritativeDnsServerCachenewAuthoritativeDnsServerCache()private DnsCachenewCache()private DnsCnameCachenewCnameCache()DnsNameResolverBuilderoptResourceEnabled(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.DnsNameResolverBuilderqueryTimeoutMillis(long queryTimeoutMillis)Sets the timeout of each DNS query performed by this resolver (in milliseconds).DnsNameResolverBuilderrecursionDesired(boolean recursionDesired)Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.DnsNameResolverBuilderresolveCache(DnsCache resolveCache)Sets the cache for resolution results.DnsNameResolverBuilderresolvedAddressTypes(ResolvedAddressTypes resolvedAddressTypes)Sets the list of the protocol families of the address resolved.DnsNameResolverBuildersearchDomains(java.lang.Iterable<java.lang.String> searchDomains)Set the list of search domains of the resolver.DnsNameResolverBuildersocketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory)DnsNameResolverBuildersocketChannelType(java.lang.Class<? extends SocketChannel> channelType)DnsNameResolverBuildertraceEnabled(boolean traceEnabled)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.DnsNameResolverBuilderttl(int minTtl, int maxTtl)Sets the minimum and maximum TTL of the cached DNS resource records (in seconds).
-
-
-
Field Detail
-
eventLoop
private EventLoop eventLoop
-
channelFactory
private ChannelFactory<? extends DatagramChannel> channelFactory
-
socketChannelFactory
private ChannelFactory<? extends SocketChannel> socketChannelFactory
-
resolveCache
private DnsCache resolveCache
-
cnameCache
private DnsCnameCache cnameCache
-
authoritativeDnsServerCache
private AuthoritativeDnsServerCache authoritativeDnsServerCache
-
minTtl
private java.lang.Integer minTtl
-
maxTtl
private java.lang.Integer maxTtl
-
negativeTtl
private java.lang.Integer negativeTtl
-
queryTimeoutMillis
private long queryTimeoutMillis
-
resolvedAddressTypes
private ResolvedAddressTypes resolvedAddressTypes
-
completeOncePreferredResolved
private boolean completeOncePreferredResolved
-
recursionDesired
private boolean recursionDesired
-
maxQueriesPerResolve
private int maxQueriesPerResolve
-
traceEnabled
private boolean traceEnabled
-
maxPayloadSize
private int maxPayloadSize
-
optResourceEnabled
private boolean optResourceEnabled
-
hostsFileEntriesResolver
private HostsFileEntriesResolver hostsFileEntriesResolver
-
dnsServerAddressStreamProvider
private DnsServerAddressStreamProvider dnsServerAddressStreamProvider
-
dnsQueryLifecycleObserverFactory
private DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory
-
searchDomains
private java.lang.String[] searchDomains
-
ndots
private int ndots
-
decodeIdn
private boolean decodeIdn
-
-
Method Detail
-
eventLoop
public DnsNameResolverBuilder eventLoop(EventLoop eventLoop)
Sets theEventLoopwhich will perform the communication with the DNS servers.- Parameters:
eventLoop- theEventLoop- Returns:
this
-
channelFactory
protected ChannelFactory<? extends DatagramChannel> channelFactory()
-
channelFactory
public DnsNameResolverBuilder channelFactory(ChannelFactory<? extends DatagramChannel> channelFactory)
Sets theChannelFactorythat will create aDatagramChannel.- Parameters:
channelFactory- theChannelFactory- Returns:
this
-
channelType
public DnsNameResolverBuilder channelType(java.lang.Class<? extends DatagramChannel> channelType)
Sets theChannelFactoryas aReflectiveChannelFactoryof this type. Use as an alternative tochannelFactory(ChannelFactory).- Parameters:
channelType- the type- Returns:
this
-
socketChannelFactory
public DnsNameResolverBuilder socketChannelFactory(ChannelFactory<? extends SocketChannel> channelFactory)
- Parameters:
channelFactory- theChannelFactoryornullif TCP fallback should not be supported.- Returns:
this
-
socketChannelType
public DnsNameResolverBuilder socketChannelType(java.lang.Class<? extends SocketChannel> channelType)
Sets theChannelFactoryas aReflectiveChannelFactoryof this type for TCP fallback if needed. Use as an alternative tosocketChannelFactory(ChannelFactory).- Parameters:
channelType- the type ornullif TCP fallback should not be supported.- 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 forCNAMEmappings.- Parameters:
cnameCache- the cache used to cacheCNAMEmappings 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
-
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 is0andInteger.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).- Parameters:
queryTimeoutMillis- the query timeout- Returns:
this
-
computeResolvedAddressTypes
public static ResolvedAddressTypes computeResolvedAddressTypes(InternetProtocolFamily... internetProtocolFamilies)
Compute aResolvedAddressTypesfrom someInternetProtocolFamilys. 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 ofInternetProtocolFamilys- 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 aResolvedAddressTypesout of someInternetProtocolFamilys.- Parameters:
resolvedAddressTypes- the address types- Returns:
this
-
completeOncePreferredResolved
public DnsNameResolverBuilder completeOncePreferredResolved(boolean completeOncePreferredResolved)
IftrueSimpleNameResolver.resolveAll(String)will notify the returnedFutureas soon as all queries for the preferred address-type are complete.- Parameters:
completeOncePreferredResolved-trueto enable,falseto 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
public DnsNameResolverBuilder traceEnabled(boolean traceEnabled)
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 is4096bytes.- 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- theHostsFileEntriesResolverused to first check if the hostname is locally aliased.- Returns:
this
-
nameServerProvider
protected DnsServerAddressStreamProvider nameServerProvider()
-
nameServerProvider
public DnsNameResolverBuilder nameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider)
Set theDnsServerAddressStreamProviderwhich is used to determine which DNS server is used to resolve each hostname.- 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
-
newCache
private DnsCache newCache()
-
newAuthoritativeDnsServerCache
private AuthoritativeDnsServerCache newAuthoritativeDnsServerCache()
-
newCnameCache
private DnsCnameCache newCnameCache()
-
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
-
build
public DnsNameResolver build()
Returns a newDnsNameResolverinstance.- Returns:
- a
DnsNameResolver
-
copy
public DnsNameResolverBuilder copy()
Creates a copy of thisDnsNameResolverBuilder- Returns:
DnsNameResolverBuilder
-
-