public class DnsNameResolver extends InetNameResolver
InetNameResolver
.限定符和类型 | 字段和说明 |
---|---|
static AttributeKey<java.lang.Boolean> |
DNS_PIPELINE_ATTRIBUTE
An attribute used to mark all channels created by the
DnsNameResolver . |
构造器和说明 |
---|
DnsNameResolver(EventLoop eventLoop,
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsCache resolveCache,
AuthoritativeDnsServerCache authoritativeDnsServerCache,
DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory,
long queryTimeoutMillis,
ResolvedAddressTypes resolvedAddressTypes,
boolean recursionDesired,
int maxQueriesPerResolve,
boolean traceEnabled,
int maxPayloadSize,
boolean optResourceEnabled,
HostsFileEntriesResolver hostsFileEntriesResolver,
DnsServerAddressStreamProvider dnsServerAddressStreamProvider,
java.lang.String[] searchDomains,
int ndots,
boolean decodeIdn)
已过时。
|
DnsNameResolver(EventLoop eventLoop,
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsCache resolveCache,
DnsCache authoritativeDnsServerCache,
DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory,
long queryTimeoutMillis,
ResolvedAddressTypes resolvedAddressTypes,
boolean recursionDesired,
int maxQueriesPerResolve,
boolean traceEnabled,
int maxPayloadSize,
boolean optResourceEnabled,
HostsFileEntriesResolver hostsFileEntriesResolver,
DnsServerAddressStreamProvider dnsServerAddressStreamProvider,
java.lang.String[] searchDomains,
int ndots,
boolean decodeIdn)
已过时。
|
限定符和类型 | 方法和说明 |
---|---|
AuthoritativeDnsServerCache |
authoritativeDnsServerCache()
Returns the cache used for authoritative DNS servers for a domain.
|
void |
close()
Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource
records from the cache.
|
DnsCnameCache |
cnameCache()
Returns the
DnsCnameCache . |
protected void |
doResolve(java.lang.String inetHost,
DnsRecord[] additionals,
Promise<java.net.InetAddress> promise,
DnsCache resolveCache)
Hook designed for extensibility so one can pass a different cache on each resolution attempt
instead of using the global one.
|
protected void |
doResolve(java.lang.String inetHost,
Promise<java.net.InetAddress> promise)
Invoked by
SimpleNameResolver.resolve(String) to perform the actual name resolution. |
protected void |
doResolveAll(java.lang.String inetHost,
DnsRecord[] additionals,
Promise<java.util.List<java.net.InetAddress>> promise,
DnsCache resolveCache)
Hook designed for extensibility so one can pass a different cache on each resolution attempt
instead of using the global one.
|
protected void |
doResolveAll(java.lang.String inetHost,
Promise<java.util.List<java.net.InetAddress>> promise)
Invoked by
SimpleNameResolver.resolveAll(String) to perform the actual name resolution. |
protected EventLoop |
executor()
Returns the
EventExecutor which is used to notify the listeners of the Future returned
by SimpleNameResolver.resolve(String) . |
HostsFileEntriesResolver |
hostsFileEntriesResolver()
Returns the component that tries to resolve hostnames against the hosts file prior to asking to
remotes DNS servers.
|
boolean |
isOptResourceEnabled()
Returns 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 is enabled.
|
boolean |
isRecursionDesired()
Returns
true if and only if this resolver sends a DNS query with the RD (recursion desired) flag set. |
static boolean |
isTimeoutError(java.lang.Throwable cause)
Returns
true if the Throwable was caused by an timeout. |
static boolean |
isTransportOrTimeoutError(java.lang.Throwable cause)
Returns
true if the Throwable was caused by an timeout or transport error. |
int |
maxPayloadSize()
Returns the capacity of the datagram packet buffer (in bytes).
|
int |
maxQueriesPerResolve()
Returns the maximum allowed number of DNS queries to send when resolving a host name.
|
protected DnsServerAddressStream |
newRedirectDnsServerStream(java.lang.String hostname,
java.util.List<java.net.InetSocketAddress> nameservers)
Creates a new
DnsServerAddressStream to following a redirected DNS query. |
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(DnsQuestion question)
Sends a DNS query with the specified question.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(DnsQuestion question,
java.lang.Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(DnsQuestion question,
Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(java.net.InetSocketAddress nameServerAddr,
DnsQuestion question)
Sends a DNS query with the specified question using the specified name server list.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(java.net.InetSocketAddress nameServerAddr,
DnsQuestion question,
java.lang.Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records using the specified name server list.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(java.net.InetSocketAddress nameServerAddr,
DnsQuestion question,
java.lang.Iterable<DnsRecord> additionals,
Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question with additional records using the specified name server list.
|
Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> |
query(java.net.InetSocketAddress nameServerAddr,
DnsQuestion question,
Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question using the specified name server list.
|
DnsServerAddressStream |
queryDnsServerAddressStream()
Returns the dns server address stream used for DNS queries (not resolve).
|
long |
queryTimeoutMillis()
Returns the timeout of each DNS query performed by this resolver (in milliseconds).
|
Future<java.net.InetAddress> |
resolve(java.lang.String inetHost,
java.lang.Iterable<DnsRecord> additionals)
Resolves the specified name into an address.
|
Future<java.net.InetAddress> |
resolve(java.lang.String inetHost,
java.lang.Iterable<DnsRecord> additionals,
Promise<java.net.InetAddress> promise)
Resolves the specified name into an address.
|
Future<java.util.List<DnsRecord>> |
resolveAll(DnsQuestion question)
Resolves the
DnsRecord s that are matched by the specified DnsQuestion . |
Future<java.util.List<DnsRecord>> |
resolveAll(DnsQuestion question,
java.lang.Iterable<DnsRecord> additionals)
Resolves the
DnsRecord s that are matched by the specified DnsQuestion . |
Future<java.util.List<DnsRecord>> |
resolveAll(DnsQuestion question,
java.lang.Iterable<DnsRecord> additionals,
Promise<java.util.List<DnsRecord>> promise)
Resolves the
DnsRecord s that are matched by the specified DnsQuestion . |
Future<java.util.List<java.net.InetAddress>> |
resolveAll(java.lang.String inetHost,
java.lang.Iterable<DnsRecord> additionals)
Resolves the specified host name and port into a list of address.
|
Future<java.util.List<java.net.InetAddress>> |
resolveAll(java.lang.String inetHost,
java.lang.Iterable<DnsRecord> additionals,
Promise<java.util.List<java.net.InetAddress>> promise)
Resolves the specified host name and port into a list of address.
|
DnsCache |
resolveCache()
Returns the resolution cache.
|
ResolvedAddressTypes |
resolvedAddressTypes()
Returns the
ResolvedAddressTypes resolved by SimpleNameResolver.resolve(String) . |
asAddressResolver
resolve, resolve, resolveAll, resolveAll
public static final AttributeKey<java.lang.Boolean> DNS_PIPELINE_ATTRIBUTE
DnsNameResolver
.@Deprecated public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, DnsCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)
DnsNameResolverBuilder
.eventLoop
- the EventLoop
which will perform the communication with the DNS serverschannelFactory
- the ChannelFactory
that will create a DatagramChannel
resolveCache
- the DNS resolved entries cacheauthoritativeDnsServerCache
- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory
- used to generate new instances of DnsQueryLifecycleObserver
which
can be used to track metrics for DNS servers.queryTimeoutMillis
- timeout of each DNS query in millis. 0
disables the timeout. If not set or a
negative number is set, the default timeout is used.resolvedAddressTypes
- the preferred address typesrecursionDesired
- if recursion desired flag must be setmaxQueriesPerResolve
- the maximum allowed number of DNS queries for a given name resolutiontraceEnabled
- if trace is enabledmaxPayloadSize
- the capacity of the datagram packet bufferoptResourceEnabled
- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver
- the HostsFileEntriesResolver
used to check for local aliasesdnsServerAddressStreamProvider
- The DnsServerAddressStreamProvider
used to determine the name
servers for each hostname lookup.searchDomains
- the list of search domain
(can be null, if so, will try to default to the underlying platform ones)ndots
- the ndots valuedecodeIdn
- true
if domain / host names should be decoded to unicode when received.
See rfc3492.@Deprecated public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)
DnsNameResolverBuilder
.eventLoop
- the EventLoop
which will perform the communication with the DNS serverschannelFactory
- the ChannelFactory
that will create a DatagramChannel
resolveCache
- the DNS resolved entries cacheauthoritativeDnsServerCache
- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory
- used to generate new instances of DnsQueryLifecycleObserver
which
can be used to track metrics for DNS servers.queryTimeoutMillis
- timeout of each DNS query in millis. 0
disables the timeout. If not set or a
negative number is set, the default timeout is used.resolvedAddressTypes
- the preferred address typesrecursionDesired
- if recursion desired flag must be setmaxQueriesPerResolve
- the maximum allowed number of DNS queries for a given name resolutiontraceEnabled
- if trace is enabledmaxPayloadSize
- the capacity of the datagram packet bufferoptResourceEnabled
- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver
- the HostsFileEntriesResolver
used to check for local aliasesdnsServerAddressStreamProvider
- The DnsServerAddressStreamProvider
used to determine the name
servers for each hostname lookup.searchDomains
- the list of search domain
(can be null, if so, will try to default to the underlying platform ones)ndots
- the ndots valuedecodeIdn
- true
if domain / host names should be decoded to unicode when received.
See rfc3492.protected DnsServerAddressStream newRedirectDnsServerStream(java.lang.String hostname, java.util.List<java.net.InetSocketAddress> nameservers)
DnsServerAddressStream
to following a redirected DNS query. By overriding this
it provides the opportunity to sort the name servers before following a redirected DNS query.hostname
- the hostname.nameservers
- The addresses of the DNS servers which are used in the event of a redirect. This may
contain resolved and unresolved addresses so the used DnsServerAddressStream
must
allow unresolved addresses if you want to include these as well.DnsServerAddressStream
which will be used to follow the DNS redirect or null
if
none should be followed.public DnsCache resolveCache()
public DnsCnameCache cnameCache()
DnsCnameCache
.public AuthoritativeDnsServerCache authoritativeDnsServerCache()
public long queryTimeoutMillis()
public DnsServerAddressStream queryDnsServerAddressStream()
public ResolvedAddressTypes resolvedAddressTypes()
ResolvedAddressTypes
resolved by SimpleNameResolver.resolve(String)
.
The default value depends on the value of the system property "java.net.preferIPv6Addresses"
.public boolean isRecursionDesired()
true
if and only if this resolver sends a DNS query with the RD (recursion desired) flag set.
The default value is true
.public int maxQueriesPerResolve()
8
.public int maxPayloadSize()
4096
bytes.public boolean isOptResourceEnabled()
public HostsFileEntriesResolver hostsFileEntriesResolver()
public void close()
close
在接口中 NameResolver<java.net.InetAddress>
close
在接口中 java.io.Closeable
close
在接口中 java.lang.AutoCloseable
close
在类中 SimpleNameResolver<java.net.InetAddress>
protected EventLoop executor()
SimpleNameResolver
EventExecutor
which is used to notify the listeners of the Future
returned
by SimpleNameResolver.resolve(String)
.executor
在类中 SimpleNameResolver<java.net.InetAddress>
public final Future<java.net.InetAddress> resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)
inetHost
- the name to resolveadditionals
- additional records (OPT
)public final Future<java.net.InetAddress> resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.net.InetAddress> promise)
inetHost
- the name to resolveadditionals
- additional records (OPT
)promise
- the Promise
which will be fulfilled when the name resolution is finishedpublic final Future<java.util.List<java.net.InetAddress>> resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)
inetHost
- the name to resolveadditionals
- additional records (OPT
)public final Future<java.util.List<java.net.InetAddress>> resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<java.net.InetAddress>> promise)
inetHost
- the name to resolveadditionals
- additional records (OPT
)promise
- the Promise
which will be fulfilled when the name resolution is finishedprotected void doResolve(java.lang.String inetHost, Promise<java.net.InetAddress> promise) throws java.lang.Exception
SimpleNameResolver
SimpleNameResolver.resolve(String)
to perform the actual name resolution.doResolve
在类中 SimpleNameResolver<java.net.InetAddress>
java.lang.Exception
public final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question)
DnsRecord
s that are matched by the specified DnsQuestion
. Unlike
query(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers.
If the specified DnsQuestion
is A
or AAAA
, this method looks up the configured
HostsFileEntries
before sending a query to the name servers. If a match is found in the
HostsFileEntries
, a synthetic A
or AAAA
record will be returned.question
- the questionDnsRecord
s as the result of the resolutionpublic final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
DnsRecord
s that are matched by the specified DnsQuestion
. Unlike
query(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers.
If the specified DnsQuestion
is A
or AAAA
, this method looks up the configured
HostsFileEntries
before sending a query to the name servers. If a match is found in the
HostsFileEntries
, a synthetic A
or AAAA
record will be returned.question
- the questionadditionals
- additional records (OPT
)DnsRecord
s as the result of the resolutionpublic final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<DnsRecord>> promise)
DnsRecord
s that are matched by the specified DnsQuestion
. Unlike
query(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers.
If the specified DnsQuestion
is A
or AAAA
, this method looks up the configured
HostsFileEntries
before sending a query to the name servers. If a match is found in the
HostsFileEntries
, a synthetic A
or AAAA
record will be returned.protected void doResolve(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) throws java.lang.Exception
java.lang.Exception
protected void doResolveAll(java.lang.String inetHost, Promise<java.util.List<java.net.InetAddress>> promise) throws java.lang.Exception
SimpleNameResolver
SimpleNameResolver.resolveAll(String)
to perform the actual name resolution.doResolveAll
在类中 SimpleNameResolver<java.net.InetAddress>
java.lang.Exception
protected void doResolveAll(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache) throws java.lang.Exception
java.lang.Exception
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
public static boolean isTransportOrTimeoutError(java.lang.Throwable cause)
true
if the Throwable
was caused by an timeout or transport error.
These methods can be used on the Future.cause()
that is returned by the various methods exposed by this
DnsNameResolver
.public static boolean isTimeoutError(java.lang.Throwable cause)
true
if the Throwable
was caused by an timeout.
These methods can be used on the Future.cause()
that is returned by the various methods exposed by this
DnsNameResolver
.