Home / Class/ DefaultAuthoritativeDnsServerCache Class — netty Architecture

DefaultAuthoritativeDnsServerCache Class — netty Architecture

Architecture documentation for the DefaultAuthoritativeDnsServerCache class in DefaultAuthoritativeDnsServerCache.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9058d90f_2238_a379_97a2_ac280ac73508["DefaultAuthoritativeDnsServerCache"]
  e55f2ec0_4179_f2e5_06ef_0f6ca165cafc["DefaultAuthoritativeDnsServerCache.java"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|defined in| e55f2ec0_4179_f2e5_06ef_0f6ca165cafc
  af420136_7856_25c9_84bf_acdeba59e373["DefaultAuthoritativeDnsServerCache()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| af420136_7856_25c9_84bf_acdeba59e373
  fe893187_01df_0da9_eab8_f07ec48f0559["DnsServerAddressStream()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| fe893187_01df_0da9_eab8_f07ec48f0559
  5d337b0e_1923_de57_7d54_9d3eaa385aad["cache()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| 5d337b0e_1923_de57_7d54_9d3eaa385aad
  036f08ae_e8a3_0e97_76b7_09834e9f9d62["clear()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| 036f08ae_e8a3_0e97_76b7_09834e9f9d62
  cc27ecfc_c59d_cfe0_5dc9_8c1dbfda79cb["String()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| cc27ecfc_c59d_cfe0_5dc9_8c1dbfda79cb
  580f1ad4_3b6f_b16e_299d_98f699d88829["minTtl()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| 580f1ad4_3b6f_b16e_299d_98f699d88829
  7563371d_c41e_f0b9_119b_85e1cebc76f0["maxTtl()"]
  9058d90f_2238_a379_97a2_ac280ac73508 -->|method| 7563371d_c41e_f0b9_119b_85e1cebc76f0

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCache.java lines 33–134

public class DefaultAuthoritativeDnsServerCache implements AuthoritativeDnsServerCache {

    private final int minTtl;
    private final int maxTtl;
    private final Comparator<InetSocketAddress> comparator;
    private final Cache<InetSocketAddress> resolveCache = new Cache<InetSocketAddress>() {
        @Override
        protected boolean shouldReplaceAll(InetSocketAddress entry) {
            return false;
        }

        @Override
        protected boolean equals(InetSocketAddress entry, InetSocketAddress otherEntry) {
            return entry.getHostString().equalsIgnoreCase(otherEntry.getHostString());
        }

        @Override
        protected void sortEntries(String hostname, List<InetSocketAddress> entries) {
            if (comparator != null) {
                Collections.sort(entries, comparator);
            }
        }
    };

    /**
     * Create a cache that respects the TTL returned by the DNS server.
     */
    public DefaultAuthoritativeDnsServerCache() {
        this(0, Cache.MAX_SUPPORTED_TTL_SECS, null);
    }

    /**
     * Create a cache.
     *
     * @param minTtl the minimum TTL
     * @param maxTtl the maximum TTL
     * @param comparator the {@link Comparator} to order the {@link InetSocketAddress} for a hostname or {@code null}
     *                   if insertion order should be used.
     */
    public DefaultAuthoritativeDnsServerCache(int minTtl, int maxTtl, Comparator<InetSocketAddress> comparator) {
        this.minTtl = Math.min(Cache.MAX_SUPPORTED_TTL_SECS, checkPositiveOrZero(minTtl, "minTtl"));
        this.maxTtl = Math.min(Cache.MAX_SUPPORTED_TTL_SECS, checkPositive(maxTtl, "maxTtl"));
        if (minTtl > maxTtl) {
            throw new IllegalArgumentException(
                    "minTtl: " + minTtl + ", maxTtl: " + maxTtl + " (expected: 0 <= minTtl <= maxTtl)");
        }
        this.comparator = comparator;
    }

    @SuppressWarnings("unchecked")
    @Override
    public DnsServerAddressStream get(String hostname) {
        checkNotNull(hostname, "hostname");

        List<? extends InetSocketAddress> addresses = resolveCache.get(hostname);
        if (addresses == null || addresses.isEmpty()) {
            return null;
        }
        return new SequentialDnsServerAddressStream(addresses, 0);
    }

    @Override
    public void cache(String hostname, InetSocketAddress address, long originalTtl, EventLoop loop) {
        checkNotNull(hostname, "hostname");
        checkNotNull(address, "address");
        checkNotNull(loop, "loop");

        if (address.getHostString() == null) {
            // We only cache addresses that have also a host string as we will need it later when trying to replace
            // unresolved entries in the cache.
            return;
        }

        resolveCache.cache(hostname, address, Math.max(minTtl, (int) Math.min(maxTtl, originalTtl)), loop);
    }

    @Override
    public void clear() {
        resolveCache.clear();
    }

Frequently Asked Questions

What is the DefaultAuthoritativeDnsServerCache class?
DefaultAuthoritativeDnsServerCache is a class in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCache.java.
Where is DefaultAuthoritativeDnsServerCache defined?
DefaultAuthoritativeDnsServerCache is defined in resolver-dns/src/main/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCache.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free