Package com.alibaba.dcm
Class DnsCacheManipulator
- java.lang.Object
-
- com.alibaba.dcm.DnsCacheManipulator
-
@ParametersAreNonnullByDefault @ReturnValuesAreNonnullByDefault public final class DnsCacheManipulator extends Object
DNS cache manipulator for querying/setting dns(in fact dns cache).Throw
DnsCacheManipulatorException
if operation fail for all methods.- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
DnsCache
,DnsCacheEntry
,DnsCacheManipulatorException
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
clearDnsCache()
Clear whole dns cache entries(including cache and negative cache), cause lookup dns server for all host after.static List<DnsCacheEntry>
getAllDnsCache()
Deprecated.this method name is confused: method name is "all" but without negative cache.static DnsCacheEntry
getDnsCache(String host)
Get a dns cache entry byhost
.static int
getDnsCachePolicy()
Get JVM DNS cache policy.static int
getDnsNegativeCachePolicy()
JVM DNS negative cache policy.static DnsCache
getWholeDnsCache()
Get whole dns cache infoDnsCache
including cache and negative cache.static List<DnsCacheEntry>
listDnsCache()
Get dns cache entries, without negative cache.static List<DnsCacheEntry>
listDnsNegativeCache()
Get dns negative cache entries.static void
loadDnsCacheConfig()
Load dns config from properties filedns-cache.properties
on classpath, then set to dns cache.static void
loadDnsCacheConfig(String propertiesFileName)
Load dns config from the specified properties file on classpath, then set dns cache.static void
removeDnsCache(String host)
Remove dns cache entry(including cache and negative cache), cause lookup dns server for host after.static void
setDnsCache(long expireMillis, String host, String... ips)
Set a dns cache entry.static void
setDnsCache(String host, String... ips)
Set a never expired dns cache entry.static void
setDnsCache(Properties properties)
Set dns cache entries by properties.static void
setDnsCachePolicy(int cacheSeconds)
Set JVM DNS cache policy.static void
setDnsNegativeCachePolicy(int negativeCacheSeconds)
Set JVM DNS negative cache policy.
-
-
-
Method Detail
-
setDnsCache
public static void setDnsCache(String host, 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, String host, 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(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 bycomma
www.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.properties
on classpath, then set to dns cache.dns-cache.properties
can be reset/customized byJVM -D option
dcm.config.filename
- Throws:
DnsCacheManipulatorException
- Operation fail- See Also:
setDnsCache(java.util.Properties)
,loadDnsCacheConfig(java.lang.String)
-
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)
-
getDnsCache
@Nullable public static DnsCacheEntry getDnsCache(String host)
Get a dns cache entry byhost
.- Returns:
- dns cache. return
null
if no entry for host or dns cache is expired. - Throws:
DnsCacheManipulatorException
- Operation fail
-
getWholeDnsCache
public static DnsCache getWholeDnsCache()
Get whole dns cache infoDnsCache
including cache and negative cache.If you only need cache without negative cache use convenient method
listDnsCache()
.- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException
- Operation fail- Since:
- 1.2.0
- See Also:
listDnsCache()
-
listDnsCache
public static List<DnsCacheEntry> listDnsCache()
Get dns cache entries, without negative cache.Same as
getWholeDnsCache().getCache()
- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException
- Operation fail- Since:
- 1.2.0
- See Also:
getWholeDnsCache()
-
getAllDnsCache
@Deprecated public static List<DnsCacheEntry> getAllDnsCache()
Deprecated.this method name is confused: method name is "all" but without negative cache. uselistDnsCache()
instead.Get dns cache entries, without negative cache.- Returns:
- dns cache entries
- Throws:
DnsCacheManipulatorException
- Operation fail
-
listDnsNegativeCache
public static List<DnsCacheEntry> listDnsNegativeCache()
Get dns negative cache entries.Same as
getWholeDnsCache().getNegativeCache()
- Returns:
- dns negative cache entries
- Throws:
DnsCacheManipulatorException
- Operation fail- Since:
- 1.6.0
- See Also:
getWholeDnsCache()
-
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
-
-