Class InMemoryDnsResolver

  • All Implemented Interfaces:
    DnsResolver

    public class InMemoryDnsResolver
    extends java.lang.Object
    implements DnsResolver
    In-memory DnsResolver implementation.
    Since:
    4.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.net.InetAddress[]> dnsMap
      In-memory collection that will hold the associations between a host name and an array of InetAddress instances.
      private org.apache.commons.logging.Log log
      Logger associated to this class.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String host, java.net.InetAddress... ips)
      Associates the given array of IP addresses to the given host in this DNS overrider.
      java.net.InetAddress[] resolve​(java.lang.String host)
      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.
      • Methods inherited from class java.lang.Object

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

      • log

        private final org.apache.commons.logging.Log log
        Logger associated to this class.
      • dnsMap

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

      • InMemoryDnsResolver

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

      • add

        public void add​(java.lang.String host,
                        java.net.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 java.net.InetAddress[] resolve​(java.lang.String host)
                                       throws java.net.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:
        java.net.UnknownHostException
        See Also:
        InetAddress