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 classDnsQueryContext.AddressedEnvelopeAdapter
-
Field Summary
Fields Modifier and Type Field Description private DnsRecord[]additionalsprivate Channelchannelprivate intidprivate static longID_REUSE_ON_TIMEOUT_DELAY_MILLISprivate static InternalLoggerloggerprivate java.net.InetSocketAddressnameServerAddrprivate DnsRecordoptResourceprivate Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>promiseprivate DnsQueryContextManagerqueryContextManagerprivate longqueryTimeoutMillisprivate DnsQuestionquestionprivate booleanrecursionDesiredprivate booleanretryWithTcpOnTimeoutprivate BootstrapsocketBootstrapprivate static TcpDnsQueryEncoderTCP_ENCODERprivate 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) booleanfinishFailure(java.lang.String message, java.lang.Throwable cause, boolean timeout)Notifies the originalPromisethat the query completes because of an failure.private voidfinishOriginal(java.lang.Object originalResult, Future<?> future)(package private) voidfinishSuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope, boolean truncated)Notifies the originalPromisethat the response for the query was received.private static booleanhasOptRecord(DnsRecord[] additionals)(package private) booleanisDone()Returnstrueif the query was completed already.protected abstract DnsQuerynewQuery(int id, java.net.InetSocketAddress nameServerAddr)Creates and returns a newDnsQuery.private voidonQueryWriteCompletion(long queryTimeoutMillis, ChannelFuture writeFuture)protected abstract java.lang.Stringprotocol()Returns the protocol that is used for the query.(package private) DnsQuestionquestion()Returns theDnsQuestionthat will be written as part of theDnsQuery.private voidremoveFromContextManager(java.net.InetSocketAddress nameServerAddr)private booleanretryWithTcp(java.lang.Object originalResult)Retry the original query with TCP if possible.private ChannelFuturesendQuery(DnsQuery query, boolean flush)private booleantrySuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)(package private) ChannelFuturewriteQuery(boolean flush)Write the query and return theChannelFuturethat is completed once the write completes.private voidwriteQuery(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()
Returnstrueif the query was completed already.- Returns:
trueif done.
-
question
final DnsQuestion question()
Returns theDnsQuestionthat 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 theChannelFuturethat is completed once the write completes.- Parameters:
flush-trueifChannel.flush()should be called as well.- Returns:
- the
ChannelFuturethat 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 originalPromisethat 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 originalPromisethat 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:
trueif retry via TCP is supported and so the ownership oforiginalResultwas transferred,falseotherwise.
-
finishOriginal
private void finishOriginal(java.lang.Object originalResult, Future<?> future)
-
-