Class DnsCacheManipulator

    • Method Detail

      • setDnsCache

        public static void setDnsCache​(long expireMillis,
                                       String host,
                                       String... ips)
        Set a dns cache entry.
        Parameters:
        expireMillis - expire time in milliseconds.
        host - host
        ips - ips
        Throws:
        DnsCacheManipulatorException - Operation fail
      • setDnsCache

        public static void setDnsCache​(Properties properties)
        Set dns cache entries by properties.
        Parameters:
        properties - input properties.
        e.g. www.example.com=42.42.42.42,
        or value is multiply ips seperated by comma www.example.com=42.42.42.42,43.43.43.43
        Throws:
        DnsCacheManipulatorException - Operation fail
      • loadDnsCacheConfig

        public static void loadDnsCacheConfig​(String propertiesFileName)
        Load dns config from the specified properties file on classpath, then set dns cache.
        Parameters:
        propertiesFileName - specified properties file name on classpath.
        Throws:
        DnsCacheManipulatorException - Operation fail
        See Also:
        setDnsCache(java.util.Properties)
      • removeDnsCache

        public static void removeDnsCache​(String host)
        Remove dns cache entry(including cache and negative cache), cause lookup dns server for host after.
        Parameters:
        host - host
        Throws:
        DnsCacheManipulatorException - Operation fail
        See Also:
        clearDnsCache()
      • clearDnsCache

        public static void clearDnsCache()
        Clear whole dns cache entries(including cache and negative cache), cause lookup dns server for all host after.
        Throws:
        DnsCacheManipulatorException - Operation fail
      • getDnsCachePolicy

        public static int getDnsCachePolicy()
        Get JVM DNS cache policy.
        Returns:
        cache seconds.
        • InetAddressCachePolicy.FOREVER(-1) means never expired.(In effect, all negative value)
        • InetAddressCachePolicy.NEVER(0) never cached.
        Throws:
        DnsCacheManipulatorException - Operation fail
        Since:
        1.3.0
        See Also:
        InetAddressCachePolicy.get(), InetAddressCachePolicy.FOREVER, InetAddressCachePolicy.NEVER, InetAddressCachePolicy.DEFAULT_POSITIVE
      • setDnsCachePolicy

        public static void setDnsCachePolicy​(int cacheSeconds)
        Set JVM DNS cache policy.

        NOTE: if Security Manage is turn on, JVM DNS cache policy set will not take effective. You can check by method getDnsCachePolicy().

        Parameters:
        cacheSeconds - set default dns cache time. Special input case:
        • InetAddressCachePolicy.FOREVER(-1) means never expired.(In effect, all negative value)
        • InetAddressCachePolicy.NEVER(0) never cached.
        Throws:
        DnsCacheManipulatorException - Operation fail
        Since:
        1.3.0
        See Also:
        InetAddressCachePolicy, InetAddressCachePolicy.cachePolicy, InetAddressCachePolicy.get(), InetAddressCachePolicy.FOREVER, InetAddressCachePolicy.NEVER, InetAddressCachePolicy.DEFAULT_POSITIVE
      • getDnsNegativeCachePolicy

        public static int getDnsNegativeCachePolicy()
        JVM DNS negative cache policy.
        Returns:
        negative cache seconds.
        • InetAddressCachePolicy.FOREVER(-1) means never expired.(In effect, all negative value)
        • InetAddressCachePolicy.NEVER(0) never cached.
        Throws:
        DnsCacheManipulatorException - Operation fail
        Since:
        1.3.0
        See Also:
        InetAddressCachePolicy.getNegative(), InetAddressCachePolicy.FOREVER, InetAddressCachePolicy.NEVER
      • setDnsNegativeCachePolicy

        public static void setDnsNegativeCachePolicy​(int negativeCacheSeconds)
        Set JVM DNS negative cache policy.
        Parameters:
        negativeCacheSeconds - set default dns cache time. Special input case:
        • InetAddressCachePolicy.FOREVER(-1) means never expired.(In effect, all negative value)
        • InetAddressCachePolicy.NEVER(0) never cached.
        Throws:
        DnsCacheManipulatorException - Operation fail
        Since:
        1.3.0
        See Also:
        InetAddressCachePolicy, InetAddressCachePolicy.FOREVER, InetAddressCachePolicy.NEVER