DnsQueryContextManager Class — netty Architecture
Architecture documentation for the DnsQueryContextManager class in DnsQueryContextManager.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f72b2e69_7611_a48e_cf72_c0d4a5edb9ba["DnsQueryContextManager"] 22ab3849_09e5_5cdc_61a4_76e82e98c465["DnsQueryContextManager.java"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|defined in| 22ab3849_09e5_5cdc_61a4_76e82e98c465 298d5f6c_7a77_a8b8_05a0_617c07a1e10a["add()"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|method| 298d5f6c_7a77_a8b8_05a0_617c07a1e10a e2241eec_58df_0c71_9259_a141d39aa092["DnsQueryContext()"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|method| e2241eec_58df_0c71_9259_a141d39aa092 dd9d6404_ba90_4c2f_3ac6_b5298eb04ced["DnsQueryContextMap()"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|method| dd9d6404_ba90_4c2f_3ac6_b5298eb04ced 040d6352_a4de_7307_6029_d87ea86c8766["Inet6Address()"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|method| 040d6352_a4de_7307_6029_d87ea86c8766 f37cb291_df28_62fb_15d2_92d996efdff6["Inet4Address()"] f72b2e69_7611_a48e_cf72_c0d4a5edb9ba -->|method| f37cb291_df28_62fb_15d2_92d996efdff6
Relationship Graph
Source Code
resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContextManager.java lines 31–190
final class DnsQueryContextManager {
/**
* A map whose key is the DNS server address and value is the map of the DNS query ID and its corresponding
* {@link DnsQueryContext}.
*/
private final Map<InetSocketAddress, DnsQueryContextMap> map =
new HashMap<InetSocketAddress, DnsQueryContextMap>();
/**
* Add {@link DnsQueryContext} to the context manager and return the ID that should be used for the query.
* This method will return {@code -1} if an ID could not be generated and the context was not stored.
*
* @param nameServerAddr The {@link InetSocketAddress} of the nameserver to query.
* @param qCtx The {@link {@link DnsQueryContext} to store.
* @return the ID that should be used or {@code -1} if none could be generated.
*/
int add(InetSocketAddress nameServerAddr, DnsQueryContext qCtx) {
assert !nameServerAddr.isUnresolved();
final DnsQueryContextMap contexts = getOrCreateContextMap(nameServerAddr);
return contexts.add(qCtx);
}
/**
* Return the {@link DnsQueryContext} for the given {@link InetSocketAddress} and id or {@code null} if
* none could be found.
*
* @param nameServerAddr The {@link InetSocketAddress} of the nameserver.
* @param id The id that identifies the {@link DnsQueryContext} and was used for the query.
* @return The context or {@code null} if none could be found.
*/
DnsQueryContext get(InetSocketAddress nameServerAddr, int id) {
assert !nameServerAddr.isUnresolved();
final DnsQueryContextMap contexts = getContextMap(nameServerAddr);
if (contexts == null) {
return null;
}
return contexts.get(id);
}
/**
* Remove the {@link DnsQueryContext} for the given {@link InetSocketAddress} and id or {@code null} if
* none could be found.
*
* @param nameServerAddr The {@link InetSocketAddress} of the nameserver.
* @param id The id that identifies the {@link DnsQueryContext} and was used for the query.
* @return The context or {@code null} if none could be removed.
*/
DnsQueryContext remove(InetSocketAddress nameServerAddr, int id) {
assert !nameServerAddr.isUnresolved();
final DnsQueryContextMap contexts = getContextMap(nameServerAddr);
if (contexts == null) {
return null;
}
return contexts.remove(id);
}
private DnsQueryContextMap getContextMap(InetSocketAddress nameServerAddr) {
synchronized (map) {
return map.get(nameServerAddr);
}
}
private DnsQueryContextMap getOrCreateContextMap(InetSocketAddress nameServerAddr) {
synchronized (map) {
final DnsQueryContextMap contexts = map.get(nameServerAddr);
if (contexts != null) {
return contexts;
}
final DnsQueryContextMap newContexts = new DnsQueryContextMap();
final InetAddress a = nameServerAddr.getAddress();
final int port = nameServerAddr.getPort();
DnsQueryContextMap old = map.put(nameServerAddr, newContexts);
// Assert that we didn't replace an existing mapping.
assert old == null : "DnsQueryContextMap already exists for " + nameServerAddr;
InetSocketAddress extraAddress = null;
if (a instanceof Inet4Address) {
// Also add the mapping for the IPv4-compatible IPv6 address.
final Inet4Address a4 = (Inet4Address) a;
Source
Frequently Asked Questions
What is the DnsQueryContextManager class?
DnsQueryContextManager is a class in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContextManager.java.
Where is DnsQueryContextManager defined?
DnsQueryContextManager is defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContextManager.java at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free