Class CachedDnsResolver

  • All Implemented Interfaces:, java.lang.AutoCloseable, org.apache.http.conn.DnsResolver

    public class CachedDnsResolver
    extends java.lang.Object
    implements org.apache.http.conn.DnsResolver,
    CachedDnsResolver caches the dns entries for hosts, which matches the specified host pattern. In the meantime, there is a asynchronous task running to refresh the cached entries periodically. The reason to have this customized DnsResolver: 1. If the DNS lookup is slow,, Object) will be blocked by the slow DNS lookup, which will cause a lot of requests being blocked since the slow DNS lookup will grab the per-connection-pool lock until it is done; 2. Here we choose to use a asynchronous task to refresh the cached entries is that the synchronous refresh with TTL will still cause latency spike because of #1;
    • Constructor Summary

      Constructor Description
      CachedDnsResolver​(java.lang.String cachedHostPattern, long refreshIntervalInMs, DnsLookupStats stats)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      protected java.util.Optional<[]> getEntryFromDnsCache​(java.lang.String host)[] resolve​(java.lang.String host)  
      protected[] systemGetAllByName​(java.lang.String host)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CachedDnsResolver

        public CachedDnsResolver​(java.lang.String cachedHostPattern,
                                 long refreshIntervalInMs,
                                 DnsLookupStats stats)
    • Method Detail

      • resolve

        public[] resolve​(java.lang.String host)
        Specified by:
        resolve in interface org.apache.http.conn.DnsResolver
      • getEntryFromDnsCache

        protected java.util.Optional<[]> getEntryFromDnsCache​(java.lang.String host)
      • systemGetAllByName

        protected[] systemGetAllByName​(java.lang.String host)
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface