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
-
-
Field Summary
Fields Modifier and Type Field Description private DnsRecord[]additionalsprivate Channelchannelprivate Future<? extends Channel>channelReadyFutureprivate intidprivate static longID_REUSE_ON_TIMEOUT_DELAY_MILLISprivate static InternalLoggerloggerprivate java.net.InetSocketAddressnameServerAddrprivate DnsRecordoptResourceprivate Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>promiseprivate DnsQueryContextManagerqueryContextManagerprivate DnsQuestionquestionprivate booleanrecursionDesiredprivate Future<?>timeoutFuture
-
Constructor Summary
Constructors Constructor Description DnsQueryContext(Channel channel, Future<? extends Channel> channelReadyFuture, java.net.InetSocketAddress nameServerAddr, DnsQueryContextManager queryContextManager, int maxPayLoadSize, boolean recursionDesired, DnsQuestion question, DnsRecord[] additionals, Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> promise)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidfailQuery(DnsQuery query, java.lang.Throwable cause, ChannelPromise writePromise)(package private) booleanfinishFailure(java.lang.String message, java.lang.Throwable cause, boolean timeout)Notifies the originalPromisethat the query completes because of an failure.(package private) voidfinishSuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)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 ChannelFuturesendQuery(java.net.InetSocketAddress nameServerAddr, DnsQuery query, long queryTimeoutMillis, boolean flush)private booleantrySuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)(package private) ChannelFuturewriteQuery(long queryTimeoutMillis, boolean flush)Write the query and return theChannelFuturethat is completed once the write completes.private voidwriteQuery(java.net.InetSocketAddress nameServerAddr, DnsQuery query, long queryTimeoutMillis, 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
-
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
-
timeoutFuture
private volatile Future<?> timeoutFuture
-
id
private int id
-
-
Constructor Detail
-
DnsQueryContext
DnsQueryContext(Channel channel, Future<? extends Channel> channelReadyFuture, java.net.InetSocketAddress nameServerAddr, DnsQueryContextManager queryContextManager, int maxPayLoadSize, boolean recursionDesired, DnsQuestion question, DnsRecord[] additionals, Promise<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> promise)
-
-
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(long queryTimeoutMillis, boolean flush)
Write the query and return theChannelFuturethat is completed once the write completes.- Parameters:
queryTimeoutMillis- the timeout after which the query is considered timeout and the originalPromisewill be failed.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(java.net.InetSocketAddress nameServerAddr, DnsQuery query, long queryTimeoutMillis, boolean flush)
-
failQuery
private void failQuery(DnsQuery query, java.lang.Throwable cause, ChannelPromise writePromise)
-
writeQuery
private void writeQuery(java.net.InetSocketAddress nameServerAddr, DnsQuery query, long queryTimeoutMillis, boolean flush, ChannelPromise promise)
-
onQueryWriteCompletion
private void onQueryWriteCompletion(long queryTimeoutMillis, ChannelFuture writeFuture)
-
finishSuccess
void finishSuccess(AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress> envelope)
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.
-
-