Package com.alibaba.dcm
Class DnsCacheManipulator
- java.lang.Object
-
- com.alibaba.dcm.DnsCacheManipulator
-
public class DnsCacheManipulator extends Object
Setting dns (in fact dns cache).Throw
DnsCacheManipulatorExceptionif operation fail for all methods.- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
DnsCacheEntry,DnsCacheManipulatorException
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidclearDnsCache()Clear all dns cache entries, cause lookup dns server for all host after.static List<DnsCacheEntry>getAllDnsCache()Deprecated.uselistDnsCache()instead.static DnsCacheEntrygetDnsCache(String host)Get dns cache.static intgetDnsCachePolicy()Get JVM DNS cache policy.static intgetDnsNegativeCachePolicy()JVM DNS negative cache policystatic DnsCachegetWholeDnsCache()Get whole dns cache info.static List<DnsCacheEntry>listDnsCache()Get all dns cache entries.static voidloadDnsCacheConfig()Load dns config from properties filedns-cache.propertieson classpath, then set to dns cache.static voidloadDnsCacheConfig(String propertiesFileName)Load dns config from the specified properties file on classpath, then set dns cache.static voidremoveDnsCache(String host)Remove dns cache entry, cause lookup dns server for host after.static voidsetDnsCache(long expireMillis, String host, String... ips)Set a dns cache entry.static voidsetDnsCache(String host, String... ips)Set a never expired dns cache entrystatic voidsetDnsCache(Properties properties)Set dns cache entries by propertiesstatic voidsetDnsCachePolicy(int cacheSeconds)Set JVM DNS cache policystatic voidsetDnsNegativeCachePolicy(int negativeCacheSeconds)Set JVM DNS negative cache policy
-
-
-
Method Detail
-
setDnsCache
public static void setDnsCache(@Nonnull String host, @Nonnull String... ips)
Set a never expired dns cache entry- Parameters:
host- hostips- ips- Throws:
DnsCacheManipulatorException- Operation fail- See Also:
setDnsCache(long, java.lang.String, java.lang.String...)
-
setDnsCache
public static void setDnsCache(long expireMillis, @Nonnull String host, @Nonnull String... ips)Set a dns cache entry.- Parameters:
expireMillis- expire time in milliseconds.host- hostips- ips- Throws:
DnsCacheManipulatorException- Operation fail
-
setDnsCache
public static void setDnsCache(@Nonnull Properties properties)
Set dns cache entries by properties- Parameters:
properties- input properties. e.g.www.example.com=42.42.42.42, orwww.example.com=42.42.42.42,43.43.43.43- Throws:
DnsCacheManipulatorException- Operation fail
-
loadDnsCacheConfig
public static void loadDnsCacheConfig()
Load dns config from properties filedns-cache.propertieson classpath, then set to dns cache.dns-cache.propertiescan be reset/customized byJVM -D optiondcm.config.filename- Throws:
DnsCacheManipulatorException- Operation fail- See Also:
setDnsCache(java.util.Properties),loadDnsCacheConfig(java.lang.String)
-
loadDnsCacheConfig
public static void loadDnsCacheConfig(@Nonnull 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)
-
getDnsCache
@Nullable public static DnsCacheEntry getDnsCache(@Nonnull String host)
Get dns cache.- Returns:
- dns cache. return
nullif no entry for host or dns cache is expired. - Throws:
DnsCacheManipulatorException- Operation fail
-
getAllDnsCache
@Deprecated @Nonnull public static List<DnsCacheEntry> getAllDnsCache()
Deprecated.uselistDnsCache()instead.Get all dns cache entries.- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException- Operation fail
-
listDnsCache
@Nonnull public static List<DnsCacheEntry> listDnsCache()
Get all dns cache entries.- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.2.0
- See Also:
getWholeDnsCache()
-
getWholeDnsCache
@Nonnull public static DnsCache getWholeDnsCache()
Get whole dns cache info.- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.2.0
-
removeDnsCache
public static void removeDnsCache(@Nonnull String host)
Remove dns cache entry, cause lookup dns server for host after.- Parameters:
host- host- Throws:
DnsCacheManipulatorException- Operation fail- See Also:
clearDnsCache()
-
clearDnsCache
public static void clearDnsCache()
Clear all dns cache entries, 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.
-
-1means never expired.(In effect, all negative value) -
0never cached.
-
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.3.0
-
setDnsCachePolicy
public static void setDnsCachePolicy(int cacheSeconds)
Set JVM DNS cache policyNOTE: 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:-
-1means never expired.(In effect, all negative value) -
0never cached.
-
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.3.0
-
getDnsNegativeCachePolicy
public static int getDnsNegativeCachePolicy()
JVM DNS negative cache policy- Returns:
- negative cache seconds.
-
-1means never expired.(In effect, all negative value) -
0never cached.
-
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.3.0
-
setDnsNegativeCachePolicy
public static void setDnsNegativeCachePolicy(int negativeCacheSeconds)
Set JVM DNS negative cache policy- Parameters:
negativeCacheSeconds- set default dns cache time. Special input case:-
-1means never expired.(In effect, all negative value) -
0never cached.
-
- Throws:
DnsCacheManipulatorException- Operation fail- Since:
- 1.3.0
-
-