Package io.netty.resolver.dns
Class DnsQueryContext
- java.lang.Object
-
- io.netty.resolver.dns.DnsQueryContext
-
- Direct Known Subclasses:
DatagramDnsQueryContext
,TcpDnsQueryContext
abstract class DnsQueryContext extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DnsQueryContext.AddressedEnvelopeAdapter
-
Field Summary
Fields Modifier and Type Field Description private DnsRecord[]
additionals
private Channel
channel
private int
id
private static long
ID_REUSE_ON_TIMEOUT_DELAY_MILLIS
private static InternalLogger
logger
private java.net.InetSocketAddress
nameServerAddr
private DnsRecord
optResource
private Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>
promise
private DnsQueryContextManager
queryContextManager
private long
queryTimeoutMillis
private DnsQuestion
question
private boolean
recursionDesired
private boolean
retryWithTcpOnTimeout
private Bootstrap
socketBootstrap
private static TcpDnsQueryEncoder
TCP_ENCODER
private Future<?>
timeoutFuture
-
Constructor Summary
Constructors Constructor Description DnsQueryContext(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQueryContextManager queryContextManager, int maxPayLoadSize, boolean recursionDesired, long queryTimeoutMillis, DnsQuestion question, DnsRecord[] additionals, Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> promise, Bootstrap socketBootstrap, boolean retryWithTcpOnTimeout)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) boolean
finishFailure(java.lang.String message, java.lang.Throwable cause, boolean timeout)
Notifies the originalPromise
that the query completes because of an failure.private void
finishOriginal(java.lang.Object originalResult, Future<?> future)
(package private) void
finishSuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope, boolean truncated)
Notifies the originalPromise
that the response for the query was received.private static boolean
hasOptRecord(DnsRecord[] additionals)
(package private) boolean
isDone()
Returnstrue
if the query was completed already.protected abstract DnsQuery
newQuery(int id, java.net.InetSocketAddress nameServerAddr)
Creates and returns a newDnsQuery
.private void
onQueryWriteCompletion(long queryTimeoutMillis, ChannelFuture writeFuture)
protected abstract java.lang.String
protocol()
Returns the protocol that is used for the query.(package private) DnsQuestion
question()
Returns theDnsQuestion
that will be written as part of theDnsQuery
.private void
removeFromContextManager(java.net.InetSocketAddress nameServerAddr)
private boolean
retryWithTcp(java.lang.Object originalResult)
Retry the original query with TCP if possible.private ChannelFuture
sendQuery(DnsQuery query, boolean flush)
private boolean
trySuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)
(package private) ChannelFuture
writeQuery(boolean flush)
Write the query and return theChannelFuture
that is completed once the write completes.private void
writeQuery(DnsQuery query, boolean flush, ChannelPromise promise)
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
ID_REUSE_ON_TIMEOUT_DELAY_MILLIS
private static final long ID_REUSE_ON_TIMEOUT_DELAY_MILLIS
-
TCP_ENCODER
private static final TcpDnsQueryEncoder TCP_ENCODER
-
channel
private final Channel channel
-
nameServerAddr
private final java.net.InetSocketAddress nameServerAddr
-
queryContextManager
private final DnsQueryContextManager queryContextManager
-
promise
private final Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> promise
-
question
private final DnsQuestion question
-
additionals
private final DnsRecord[] additionals
-
optResource
private final DnsRecord optResource
-
recursionDesired
private final boolean recursionDesired
-
socketBootstrap
private final Bootstrap socketBootstrap
-
retryWithTcpOnTimeout
private final boolean retryWithTcpOnTimeout
-
queryTimeoutMillis
private final long queryTimeoutMillis
-
timeoutFuture
private volatile Future<?> timeoutFuture
-
id
private int id
-
-
Constructor Detail
-
DnsQueryContext
DnsQueryContext(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQueryContextManager queryContextManager, int maxPayLoadSize, boolean recursionDesired, long queryTimeoutMillis, DnsQuestion question, DnsRecord[] additionals, Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> promise, Bootstrap socketBootstrap, boolean retryWithTcpOnTimeout)
-
-
Method Detail
-
hasOptRecord
private static boolean hasOptRecord(DnsRecord[] additionals)
-
isDone
final boolean isDone()
Returnstrue
if the query was completed already.- Returns:
true
if done.
-
question
final DnsQuestion question()
Returns theDnsQuestion
that will be written as part of theDnsQuery
.- Returns:
- the question.
-
newQuery
protected abstract DnsQuery newQuery(int id, java.net.InetSocketAddress nameServerAddr)
Creates and returns a newDnsQuery
.- Parameters:
id
- the transaction id to use.nameServerAddr
- the nameserver to which the query will be send.- Returns:
- the new query.
-
protocol
protected abstract java.lang.String protocol()
Returns the protocol that is used for the query.- Returns:
- the protocol.
-
writeQuery
final ChannelFuture writeQuery(boolean flush)
Write the query and return theChannelFuture
that is completed once the write completes.- Parameters:
flush
-true
ifChannel.flush()
should be called as well.- Returns:
- the
ChannelFuture
that is notified once once the write completes.
-
removeFromContextManager
private void removeFromContextManager(java.net.InetSocketAddress nameServerAddr)
-
sendQuery
private ChannelFuture sendQuery(DnsQuery query, boolean flush)
-
writeQuery
private void writeQuery(DnsQuery query, boolean flush, ChannelPromise promise)
-
onQueryWriteCompletion
private void onQueryWriteCompletion(long queryTimeoutMillis, ChannelFuture writeFuture)
-
finishSuccess
void finishSuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope, boolean truncated)
Notifies the originalPromise
that the response for the query was received. This method takes ownership of passedAddressedEnvelope
.
-
trySuccess
private boolean trySuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)
-
finishFailure
final boolean finishFailure(java.lang.String message, java.lang.Throwable cause, boolean timeout)
Notifies the originalPromise
that the query completes because of an failure.
-
retryWithTcp
private boolean retryWithTcp(java.lang.Object originalResult)
Retry the original query with TCP if possible.- Parameters:
originalResult
- the result of the originalDnsQueryContext
.- Returns:
true
if retry via TCP is supported and so the ownership oforiginalResult
was transferred,false
otherwise.
-
finishOriginal
private void finishOriginal(java.lang.Object originalResult, Future<?> future)
-
-