Class InMemoryDnsResolver

java.lang.Object
org.apache.hc.client5.http.impl.InMemoryDnsResolver
All Implemented Interfaces:
DnsResolver

@Contract(threading=STATELESS) public class InMemoryDnsResolver extends Object implements DnsResolver
In-memory DnsResolver implementation.
Since:
4.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<String,InetAddress[]>
    In-memory collection that will hold the associations between a host name and an array of InetAddress instances.
    private static final org.slf4j.Logger
    Logger associated to this class.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Builds a DNS resolver that will resolve the host names against a collection held in-memory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String host, InetAddress... ips)
    Associates the given array of IP addresses to the given host in this DNS overrider.
    Returns the IP address for the specified host name, or null if the given host is not recognized or the associated IP address cannot be used to build an InetAddress instance.
    Gets the fully qualified domain name for given host name.

    Methods inherited from class java.lang.Object

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

    • LOG

      private static final org.slf4j.Logger LOG
      Logger associated to this class.
    • dnsMap

      private final Map<String,InetAddress[]> dnsMap
      In-memory collection that will hold the associations between a host name and an array of InetAddress instances.
  • Constructor Details

    • InMemoryDnsResolver

      public InMemoryDnsResolver()
      Builds a DNS resolver that will resolve the host names against a collection held in-memory.
  • Method Details

    • add

      public void add(String host, InetAddress... ips)
      Associates the given array of IP addresses to the given host in this DNS overrider. The IP addresses are assumed to be already resolved.
      Parameters:
      host - The host name to be associated with the given IP.
      ips - array of IP addresses to be resolved by this DNS overrider to the given host name.
    • resolve

      public InetAddress[] resolve(String host) throws UnknownHostException
      Returns the IP address for the specified host name, or null if the given host is not recognized or the associated IP address cannot be used to build an InetAddress instance.
      Specified by:
      resolve in interface DnsResolver
      Parameters:
      host - The host name to be resolved by this resolver.
      Returns:
      The IP address associated to the given host name, or null if the host name is not known by the implementation class.
      Throws:
      UnknownHostException
      See Also:
    • resolveCanonicalHostname

      public String resolveCanonicalHostname(String host) throws UnknownHostException
      Description copied from interface: DnsResolver
      Gets the fully qualified domain name for given host name.
      Specified by:
      resolveCanonicalHostname in interface DnsResolver
      Throws:
      UnknownHostException