Class DefaultDnsCache

java.lang.Object
io.netty.resolver.dns.DefaultDnsCache
All Implemented Interfaces:
DnsCache

public class DefaultDnsCache extends java.lang.Object implements DnsCache
Default implementation of DnsCache, backed by a ConcurrentMap. If any additional DnsRecord is used, no caching takes place.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
    private static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
     
    private final int
     
    private final int
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.
    DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl)
    Create a cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static java.lang.String
    appendDot(java.lang.String hostname)
     
    cache(java.lang.String hostname, DnsRecord[] additionals, java.lang.Throwable cause, EventLoop loop)
    Cache the resolution failure for a given hostname.
    cache(java.lang.String hostname, DnsRecord[] additionals, java.net.InetAddress address, long originalTtl, EventLoop loop)
    Create a new DnsCacheEntry and cache a resolved address for a given hostname.
    void
    Clears all the resolved addresses cached by this resolver.
    boolean
    clear(java.lang.String hostname)
    Clears the resolved addresses of the specified host name from the cache of this resolver.
    private static java.lang.Throwable
    copyThrowable(java.lang.Throwable error)
     
    private static boolean
    emptyAdditionals(DnsRecord[] additionals)
     
    java.util.List<? extends DnsCacheEntry>
    get(java.lang.String hostname, DnsRecord[] additionals)
    Return the cached entries for the given hostname.
    int
    Returns the maximum TTL of the cached DNS resource records (in seconds).
    int
    Returns the minimum TTL of the cached DNS resource records (in seconds).
    int
    Returns the TTL of the cache for the failed DNS queries (in seconds).
    java.lang.String
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • DefaultDnsCache

      public DefaultDnsCache()
      Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.
    • DefaultDnsCache

      public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl)
      Create a cache.
      Parameters:
      minTtl - the minimum TTL
      maxTtl - the maximum TTL
      negativeTtl - the TTL for failed queries
  • Method Details

    • minTtl

      public int minTtl()
      Returns the minimum TTL of the cached DNS resource records (in seconds).
      See Also:
    • maxTtl

      public int maxTtl()
      Returns the maximum TTL of the cached DNS resource records (in seconds).
      See Also:
    • negativeTtl

      public int negativeTtl()
      Returns the TTL of the cache for the failed DNS queries (in seconds). The default value is 0, which disables the cache for negative results.
    • clear

      public void clear()
      Description copied from interface: DnsCache
      Clears all the resolved addresses cached by this resolver.
      Specified by:
      clear in interface DnsCache
      See Also:
    • clear

      public boolean clear(java.lang.String hostname)
      Description copied from interface: DnsCache
      Clears the resolved addresses of the specified host name from the cache of this resolver.
      Specified by:
      clear in interface DnsCache
      Returns:
      true if and only if there was an entry for the specified host name in the cache and it has been removed by this method
    • emptyAdditionals

      private static boolean emptyAdditionals(DnsRecord[] additionals)
    • get

      public java.util.List<? extends DnsCacheEntry> get(java.lang.String hostname, DnsRecord[] additionals)
      Description copied from interface: DnsCache
      Return the cached entries for the given hostname.
      Specified by:
      get in interface DnsCache
      Parameters:
      hostname - the hostname
      additionals - the additional records
      Returns:
      the cached entries
    • cache

      public DnsCacheEntry cache(java.lang.String hostname, DnsRecord[] additionals, java.net.InetAddress address, long originalTtl, EventLoop loop)
      Description copied from interface: DnsCache
      Create a new DnsCacheEntry and cache a resolved address for a given hostname.
      Specified by:
      cache in interface DnsCache
      Parameters:
      hostname - the hostname
      additionals - the additional records
      address - the resolved address
      originalTtl - the TTL as returned by the DNS server
      loop - the EventLoop used to register the TTL timeout
      Returns:
      The DnsCacheEntry corresponding to this cache entry.
    • cache

      public DnsCacheEntry cache(java.lang.String hostname, DnsRecord[] additionals, java.lang.Throwable cause, EventLoop loop)
      Description copied from interface: DnsCache
      Cache the resolution failure for a given hostname. Be aware this won't be called with timeout / cancel / transport exceptions.
      Specified by:
      cache in interface DnsCache
      Parameters:
      hostname - the hostname
      additionals - the additional records
      cause - the resolution failure
      loop - the EventLoop used to register the TTL timeout
      Returns:
      The DnsCacheEntry corresponding to this cache entry, or null if this cache doesn't support caching failed responses.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • appendDot

      private static java.lang.String appendDot(java.lang.String hostname)
    • copyThrowable

      private static java.lang.Throwable copyThrowable(java.lang.Throwable error)