Class CaffeineDnsCache
- java.lang.Object
-
- org.opennms.netmgt.dnsresolver.netty.CaffeineDnsCache
-
- All Implemented Interfaces:
io.netty.resolver.dns.DnsCache,ExtendedDnsCache
public class CaffeineDnsCache extends Object implements ExtendedDnsCache
DNS cache implementation largely copied from Netty's https://github.com/netty/netty/blob/netty-4.1.38.Final/resolver-dns/src/main/java/io/netty/resolver/dns/DefaultDnsCache.java but adapted slightly to work with ourCaffeineCache.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_MAX_SIZEprotected static intDEFAULT_NEGATIVE_TTL_SECSprotected static intMAX_SUPPORTED_TTL_SECS
-
Constructor Summary
Constructors Constructor Description CaffeineDnsCache()Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.CaffeineDnsCache(int minTtl, int maxTtl, int negativeTtl, long maxSize)Create a cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtendedDnsCacheEntrycache(String hostname, io.netty.handler.codec.dns.DnsPtrRecord ptrRecord, io.netty.channel.EventLoop loop)Positive caching for reverse lookups.io.netty.resolver.dns.DnsCacheEntrycache(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals, Throwable cause, io.netty.channel.EventLoop loop)Negative caching for failures (or empty reverse lookups).io.netty.resolver.dns.DnsCacheEntrycache(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals, InetAddress address, long originalTtl, io.netty.channel.EventLoop loop)Positive caching for normal lookups.voidclear()booleanclear(String hostname)List<? extends io.netty.resolver.dns.DnsCacheEntry>get(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals)longgetSize()longmaxSize()Returns the maximum number of elements allows in the cache.intmaxTtl()Returns the maximum TTL of the cached DNS resource records (in seconds).intminTtl()Returns the minimum TTL of the cached DNS resource records (in seconds).intnegativeTtl()Returns the TTL of the cache for the failed DNS queries (in seconds).voidregisterMetrics(com.codahale.metrics.MetricRegistry metrics)StringtoString()voidunregisterMetrics(com.codahale.metrics.MetricRegistry metrics)
-
-
-
Field Detail
-
MAX_SUPPORTED_TTL_SECS
protected static final int MAX_SUPPORTED_TTL_SECS
-
DEFAULT_NEGATIVE_TTL_SECS
protected static final int DEFAULT_NEGATIVE_TTL_SECS
-
DEFAULT_MAX_SIZE
protected static final int DEFAULT_MAX_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CaffeineDnsCache
public CaffeineDnsCache()
Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.
-
CaffeineDnsCache
public CaffeineDnsCache(int minTtl, int maxTtl, int negativeTtl, long maxSize)Create a cache.- Parameters:
minTtl- the minimum TTLmaxTtl- the maximum TTLnegativeTtl- the TTL for failed queries
-
-
Method Detail
-
minTtl
public int minTtl()
Returns the minimum TTL of the cached DNS resource records (in seconds).- See Also:
maxTtl()
-
maxTtl
public int maxTtl()
Returns the maximum TTL of the cached DNS resource records (in seconds).- See Also:
minTtl()
-
negativeTtl
public int negativeTtl()
Returns the TTL of the cache for the failed DNS queries (in seconds). The default value is0, which disables the cache for negative results.
-
maxSize
public long maxSize()
Returns the maximum number of elements allows in the cache.
-
clear
public void clear()
- Specified by:
clearin interfaceio.netty.resolver.dns.DnsCache
-
clear
public boolean clear(String hostname)
- Specified by:
clearin interfaceio.netty.resolver.dns.DnsCache
-
get
public List<? extends io.netty.resolver.dns.DnsCacheEntry> get(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals)
- Specified by:
getin interfaceio.netty.resolver.dns.DnsCache
-
cache
public io.netty.resolver.dns.DnsCacheEntry cache(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals, InetAddress address, long originalTtl, io.netty.channel.EventLoop loop)
Positive caching for normal lookups.- Specified by:
cachein interfaceio.netty.resolver.dns.DnsCache
-
cache
public ExtendedDnsCacheEntry cache(String hostname, io.netty.handler.codec.dns.DnsPtrRecord ptrRecord, io.netty.channel.EventLoop loop)
Positive caching for reverse lookups.- Specified by:
cachein interfaceExtendedDnsCache
-
cache
public io.netty.resolver.dns.DnsCacheEntry cache(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals, Throwable cause, io.netty.channel.EventLoop loop)
Negative caching for failures (or empty reverse lookups).- Specified by:
cachein interfaceio.netty.resolver.dns.DnsCache
-
getSize
public long getSize()
-
registerMetrics
public void registerMetrics(com.codahale.metrics.MetricRegistry metrics)
-
unregisterMetrics
public void unregisterMetrics(com.codahale.metrics.MetricRegistry metrics)
-
-