Class LocalhostResolver

  • All Implemented Interfaces:
    org.apache.cassandra.sidecar.common.server.dns.DnsResolver

    public class LocalhostResolver
    extends java.lang.Object
    implements org.apache.cassandra.sidecar.common.server.dns.DnsResolver
    A DnsResolver instance used for tests that provides fast DNS resolution, to avoid blocking DNS resolution at the JDK/OS-level.

    NOTE: The resolver assumes that the addresses are of the form 127.0.0.x, which is what is currently configured for integration tests.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String resolve​(java.lang.String hostname)
      Returns the resolved IP address from the hostname.
      java.lang.String reverseResolve​(java.lang.String address)
      Returns the resolved hostname from the given address.
      • Methods inherited from class java.lang.Object

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

      • LocalhostResolver

        public LocalhostResolver()
    • Method Detail

      • resolve

        public java.lang.String resolve​(java.lang.String hostname)
                                 throws java.net.UnknownHostException
        Returns the resolved IP address from the hostname. If the hostname pattern is not matched, delegate the resolution to the delegate resolver.
         resolver.resolve("localhost") = "127.0.0.1"
         resolver.resolve("localhost2") = "127.0.0.2"
         resolver.resolve("localhost20") = "127.0.0.20"
         resolver.resolve("127.0.0.5") = "127.0.0.5"
         
        Specified by:
        resolve in interface org.apache.cassandra.sidecar.common.server.dns.DnsResolver
        Parameters:
        hostname - the hostname to resolve
        Returns:
        the resolved IP address
        Throws:
        java.net.UnknownHostException
      • reverseResolve

        public java.lang.String reverseResolve​(java.lang.String address)
                                        throws java.net.UnknownHostException
        Returns the resolved hostname from the given address. When an invalid IP address is provided, delegates address resolution to the delegate.
         resolver.reverseResolve("127.0.0.1") = "localhost"
         resolver.reverseResolve("127.0.0.2") = "localhost2"
         resolver.reverseResolve("127.0.0.20") = "localhost20"
         resolver.reverseResolve("localhost5") = "localhost5"
         
        Specified by:
        reverseResolve in interface org.apache.cassandra.sidecar.common.server.dns.DnsResolver
        Parameters:
        address - the IP address to perform the reverse resolution
        Returns:
        the resolved hostname for the given address
        Throws:
        java.net.UnknownHostException