Class CachingNameResolver

    • Constructor Summary

      Constructors 
      Constructor Description
      CachingNameResolver()
      Creates a new instance of this caching name resolver that will use a default timeout.
      CachingNameResolver​(int timeoutMillis)
      Creates a new instance of this caching name resolver that will use the specified timeout.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearCache()
      Clears all information from the name resolver cache.
      java.net.InetAddress[] getAllByName​(java.lang.String host)
      Retrieves an array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
      java.net.InetAddress[] getAllByNameInternal​(java.lang.String host)
      Retrieves an array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
      java.net.InetAddress getByName​(java.lang.String host)
      Retrieves an InetAddress that encapsulates an IP address associated with the provided host name.
      java.lang.String getCanonicalHostName​(java.net.InetAddress inetAddress)
      Retrieves the canonical host name for the provided InetAddress object.
      java.lang.String getHostName​(java.net.InetAddress inetAddress)
      Retrieves the host name for the provided InetAddress object.
      java.net.InetAddress getLocalHost()
      Retrieves the address of the local host.
      java.net.InetAddress getLoopbackAddress()
      Retrieves the loopback address for the system.
      int getTimeoutMillis()
      Retrieves the length of time, in milliseconds, that cache records should be considered valid.
      void toString​(java.lang.StringBuilder buffer)
      Appends a string representation of this name resolver to the provided buffer.
      • Methods inherited from class java.lang.Object

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

      • CachingNameResolver

        public CachingNameResolver()
        Creates a new instance of this caching name resolver that will use a default timeout.
      • CachingNameResolver

        public CachingNameResolver​(int timeoutMillis)
        Creates a new instance of this caching name resolver that will use the specified timeout.
        Parameters:
        timeoutMillis - The length of time, in milliseconds, that cache records should be considered valid. It must be greater than zero. If a record has been in the cache for less than this period of time, then the cached record will be used instead of making a name service call. If a record has been in the cache for longer than this period of time, then the cached record will only be used if it is not possible to get an updated version of the record from the name service.
    • Method Detail

      • getTimeoutMillis

        public int getTimeoutMillis()
        Retrieves the length of time, in milliseconds, that cache records should be considered valid. If a record has been in the cache for less than this period fo time, then the cached record will be used instead of making a name service call. If a record has been in the cache for longer than this period of time, then the cached record will only be used if it is not possible to get an updated version of the record from the name service.
        Returns:
        The length of time, in milliseconds, that cache records should be considered valid.
      • getByName

        public java.net.InetAddress getByName​(java.lang.String host)
                                       throws java.net.UnknownHostException,
                                              java.lang.SecurityException
        Retrieves an InetAddress that encapsulates an IP address associated with the provided host name.
        Overrides:
        getByName in class NameResolver
        Parameters:
        host - The host name for which to retrieve a corresponding InetAddress object. It can be a resolvable name or a textual representation of an IP address. If the provided name is the textual representation of an IPv6 address, then it can use either the form described in RFC 2373 or RFC 2732, or it can be an IPv6 scoped address. If it is null, then the returned address should represent an address of the loopback interface.
        Returns:
        An InetAddress that encapsulates an IP address associated with the provided host name.
        Throws:
        java.net.UnknownHostException - If the provided name cannot be resolved to its corresponding IP addresses.
        java.lang.SecurityException - If a security manager prevents the name resolution attempt.
      • getAllByName

        public java.net.InetAddress[] getAllByName​(java.lang.String host)
                                            throws java.net.UnknownHostException,
                                                   java.lang.SecurityException
        Retrieves an array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
        Overrides:
        getAllByName in class NameResolver
        Parameters:
        host - The host name for which to retrieve the corresponding InetAddress objects. It can be a resolvable name or a textual representation of an IP address. If the provided name is the textual representation of an IPv6 address, then it can use either the form described in RFC 2373 or RFC 2732, or it can be an IPv6 scoped address. If it is null, then the returned address should represent an address of the loopback interface.
        Returns:
        An array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
        Throws:
        java.net.UnknownHostException - If the provided name cannot be resolved to its corresponding IP addresses.
        java.lang.SecurityException - If a security manager prevents the name resolution attempt.
      • getAllByNameInternal

        public java.net.InetAddress[] getAllByNameInternal​(java.lang.String host)
                                                    throws java.net.UnknownHostException,
                                                           java.lang.SecurityException
        Retrieves an array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
        Parameters:
        host - The host name for which to retrieve the corresponding InetAddress objects. It can be a resolvable name or a textual representation of an IP address. If the provided name is the textual representation of an IPv6 address, then it can use either the form described in RFC 2373 or RFC 2732, or it can be an IPv6 scoped address. If it is null, then the returned address should represent an address of the loopback interface.
        Returns:
        An array of InetAddress objects that encapsulate all known IP addresses associated with the provided host name.
        Throws:
        java.net.UnknownHostException - If the provided name cannot be resolved to its corresponding IP addresses.
        java.lang.SecurityException - If a security manager prevents the name resolution attempt.
      • getHostName

        public java.lang.String getHostName​(java.net.InetAddress inetAddress)
        Retrieves the host name for the provided InetAddress object.
        Overrides:
        getHostName in class NameResolver
        Parameters:
        inetAddress - The address for which to retrieve the host name. It must not be null.
        Returns:
        The host name for the provided InetAddress object, or a textual representation of the IP address if the name cannot be determined.
      • getCanonicalHostName

        public java.lang.String getCanonicalHostName​(java.net.InetAddress inetAddress)
        Retrieves the canonical host name for the provided InetAddress object.
        Overrides:
        getCanonicalHostName in class NameResolver
        Parameters:
        inetAddress - The address for which to retrieve the canonical host name. It must not be null.
        Returns:
        The canonical host name for the provided InetAddress object, or a textual representation of the IP address if the name cannot be determined.
      • getLocalHost

        public java.net.InetAddress getLocalHost()
                                          throws java.net.UnknownHostException,
                                                 java.lang.SecurityException
        Retrieves the address of the local host. This should be the name of the host obtained from the system, converted to an InetAddress.
        Overrides:
        getLocalHost in class NameResolver
        Returns:
        The address of the local host.
        Throws:
        java.net.UnknownHostException - If the local host name cannot be resolved.
        java.lang.SecurityException - If a security manager prevents the name resolution attempt.
      • getLoopbackAddress

        public java.net.InetAddress getLoopbackAddress()
        Retrieves the loopback address for the system. This should be either the IPv4 loopback address of 127.0.0.1, or the IPv6 loopback address of ::1.
        Overrides:
        getLoopbackAddress in class NameResolver
        Returns:
        The loopback address for the system.
      • clearCache

        public void clearCache()
        Clears all information from the name resolver cache.
      • toString

        public void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this name resolver to the provided buffer.
        Specified by:
        toString in class NameResolver
        Parameters:
        buffer - A buffer to which the string representation should be appended.