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 int
DEFAULT_MAX_SIZE
protected static int
DEFAULT_NEGATIVE_TTL_SECS
protected static int
MAX_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 ExtendedDnsCacheEntry
cache(String hostname, io.netty.handler.codec.dns.DnsPtrRecord ptrRecord, io.netty.channel.EventLoop loop)
Positive caching for reverse lookups.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).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.void
clear()
boolean
clear(String hostname)
List<? extends io.netty.resolver.dns.DnsCacheEntry>
get(String hostname, io.netty.handler.codec.dns.DnsRecord[] additionals)
long
getSize()
long
maxSize()
Returns the maximum number of elements allows in the cache.int
maxTtl()
Returns the maximum TTL of the cached DNS resource records (in seconds).int
minTtl()
Returns the minimum TTL of the cached DNS resource records (in seconds).int
negativeTtl()
Returns the TTL of the cache for the failed DNS queries (in seconds).void
registerMetrics(com.codahale.metrics.MetricRegistry metrics)
String
toString()
void
unregisterMetrics(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:
clear
in interfaceio.netty.resolver.dns.DnsCache
-
clear
public boolean clear(String hostname)
- Specified by:
clear
in 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:
get
in 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:
cache
in 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:
cache
in 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:
cache
in 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)
-
-