Top Description Inners Fields Constructors Methods
io.netty.resolver.dns

public Class DefaultDnsCache

extends Object
implements DnsCache
Class Inheritance
All Implemented Interfaces
io.netty.resolver.dns.DnsCache
Imports
io.netty.channel.EventLoop, io.netty.handler.codec.dns.DnsRecord, io.netty.util.internal.StringUtil, java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .ObjectInputStream, .ObjectOutputStream, java.net.InetAddress, .UnknownHostException, java.util.AbstractList, .Collections, .List, java.util.concurrent.ConcurrentMap

Default implementation of DnsCache, backed by a ConcurrentMap. If any additional DnsRecord is used, no caching takes place.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final int
private final int
private final int
private final Cache<DefaultDnsCache.DefaultDnsCacheEntry>

Constructor Summary

AccessConstructor and Description
public
DefaultDnsCache()

Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.

public
DefaultDnsCache(int
the minimum TTL
minTtl
,
int
the maximum TTL
maxTtl
,
int
the TTL for failed queries
negativeTtl
)

Create a cache.

Method Summary

Modifier and TypeMethod and Description
private static String
appendDot(String hostname)

public DnsCacheEntry
cache(String
the hostname
hostname
,
DnsRecord[]
the additional records
additionals
,
InetAddress
the resolved address
address
,
long
the TTL as returned by the DNS server
originalTtl
,
EventLoop
the EventLoop used to register the TTL timeout
loop
)

Implements io.netty.resolver.dns.DnsCache.cache.

Create a new DnsCacheEntry and cache a resolved address for a given hostname.
public DnsCacheEntry
cache(String
the hostname
hostname
,
DnsRecord[]
the additional records
additionals
,
Throwable
the resolution failure
cause
,
EventLoop
the EventLoop used to register the TTL timeout
loop
)

Implements io.netty.resolver.dns.DnsCache.cache.

Cache the resolution failure for a given hostname.
public void
clear()

Implements io.netty.resolver.dns.DnsCache.clear.

Clears all the resolved addresses cached by this resolver.
public boolean
clear(String hostname)

Implements io.netty.resolver.dns.DnsCache.clear.

Clears the resolved addresses of the specified host name from the cache of this resolver.
private static Throwable
private static boolean
emptyAdditionals(DnsRecord[] additionals)

public List<? extends DnsCacheEntry>
get(String
the hostname
hostname
,
DnsRecord[]
the additional records
additionals
)

Implements io.netty.resolver.dns.DnsCache.get.

Return the cached entries for the given hostname.
public int
maxTtl()

Returns the maximum TTL of the cached DNS resource records (in seconds).

public int
minTtl()

Returns the minimum TTL of the cached DNS resource records (in seconds).

public int
negativeTtl()

Returns the TTL of the cache for the failed DNS queries (in seconds).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

maxTtlback to summary
private final int maxTtl
minTtlback to summary
private final int minTtl
negativeTtlback to summary
private final int negativeTtl
resolveCacheback to summary
private final Cache<DefaultDnsCache.DefaultDnsCacheEntry> resolveCache

Constructor Detail

DefaultDnsCacheback to summary
public DefaultDnsCache()

Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.

DefaultDnsCacheback to summary
public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl)

Create a cache.

Parameters
minTtl:int

the minimum TTL

maxTtl:int

the maximum TTL

negativeTtl:int

the TTL for failed queries

Method Detail

appendDotback to summary
private static String appendDot(String hostname)
cacheback to summary
public DnsCacheEntry cache(String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl, EventLoop loop)

Implements io.netty.resolver.dns.DnsCache.cache.

Doc from io.netty.resolver.dns.DnsCache.cache.

Create a new DnsCacheEntry and cache a resolved address for a given hostname.

Parameters
hostname:String

the hostname

additionals:DnsRecord[]

the additional records

address:InetAddress

the resolved address

originalTtl:long

the TTL as returned by the DNS server

loop:EventLoop

the EventLoop used to register the TTL timeout

Returns:DnsCacheEntry

The DnsCacheEntry corresponding to this cache entry.

Annotations
@Override
cacheback to summary
public DnsCacheEntry cache(String hostname, DnsRecord[] additionals, Throwable cause, EventLoop loop)

Implements io.netty.resolver.dns.DnsCache.cache.

Doc from io.netty.resolver.dns.DnsCache.cache.

Cache the resolution failure for a given hostname. Be aware this won't be called with timeout / cancel / transport exceptions.

Parameters
hostname:String

the hostname

additionals:DnsRecord[]

the additional records

cause:Throwable

the resolution failure

loop:EventLoop

the EventLoop used to register the TTL timeout

Returns:DnsCacheEntry

The DnsCacheEntry corresponding to this cache entry, or null if this cache doesn't support caching failed responses.

Annotations
@Override
clearback to summary
public void clear()

Implements io.netty.resolver.dns.DnsCache.clear.

Doc from io.netty.resolver.dns.DnsCache.clear.

Clears all the resolved addresses cached by this resolver.

Annotations
@Override
clearback to summary
public boolean clear(String hostname)

Implements io.netty.resolver.dns.DnsCache.clear.

Doc from io.netty.resolver.dns.DnsCache.clear.

Clears the resolved addresses of the specified host name from the cache of this resolver.

Returns:boolean

true if and only if there was an entry for the specified host name in the cache and it has been removed by this method

Annotations
@Override
copyThrowableback to summary
private static Throwable copyThrowable(Throwable error)
emptyAdditionalsback to summary
private static boolean emptyAdditionals(DnsRecord[] additionals)
getback to summary
public List<? extends DnsCacheEntry> get(String hostname, DnsRecord[] additionals)

Implements io.netty.resolver.dns.DnsCache.get.

Doc from io.netty.resolver.dns.DnsCache.get.

Return the cached entries for the given hostname.

Parameters
hostname:String

the hostname

additionals:DnsRecord[]

the additional records

Returns:List<? extends DnsCacheEntry>

the cached entries

Annotations
@Override
maxTtlback to summary
public int maxTtl()

Returns the maximum TTL of the cached DNS resource records (in seconds).

See Also
minTtl()
minTtlback to summary
public int minTtl()

Returns the minimum TTL of the cached DNS resource records (in seconds).

See Also
maxTtl()
negativeTtlback to summary
public int negativeTtl()

Returns the TTL of the cache for the failed DNS queries (in seconds). The default value is 0, which disables the cache for negative results.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
io.netty.resolver.dns back to summary

private final Class DefaultDnsCache.DefaultDnsCacheEntry

extends Object
implements DnsCacheEntry
Class Inheritance
All Implemented Interfaces
io.netty.resolver.dns.DnsCacheEntry

Field Summary

Modifier and TypeField and Description
private final InetAddress
private final Throwable
private final int
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
private

Method Summary

Modifier and TypeMethod and Description
public InetAddress
address()

Implements io.netty.resolver.dns.DnsCacheEntry.address.

Get the resolved address.
public Throwable
cause()

Implements io.netty.resolver.dns.DnsCacheEntry.cause.

If the DNS query failed this will provide the rational.
pack-priv DnsCacheEntry
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
pack-priv String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

addressback to summary
private final InetAddress address
causeback to summary
private final Throwable cause
hashback to summary
private final int hash
hostnameback to summary
private final String hostname

Constructor Detail

DefaultDnsCacheEntryback to summary
pack-priv DefaultDnsCacheEntry(String hostname, InetAddress address)
DefaultDnsCacheEntryback to summary
pack-priv DefaultDnsCacheEntry(String hostname, Throwable cause)
DefaultDnsCacheEntryback to summary
private DefaultDnsCacheEntry(DefaultDnsCache.DefaultDnsCacheEntry entry)

Method Detail

addressback to summary
public InetAddress address()

Implements io.netty.resolver.dns.DnsCacheEntry.address.

Doc from io.netty.resolver.dns.DnsCacheEntry.address.

Get the resolved address.

This may be null if the resolution failed, and in that case cause() will describe the failure.

Returns:InetAddress

the resolved address.

Annotations
@Override
causeback to summary
public Throwable cause()

Implements io.netty.resolver.dns.DnsCacheEntry.cause.

Doc from io.netty.resolver.dns.DnsCacheEntry.cause.

If the DNS query failed this will provide the rational.

Returns:Throwable

the rational for why the DNS query failed, or null if the query hasn't failed.

Annotations
@Override
copyIfNeededback to summary
pack-priv DnsCacheEntry copyIfNeeded()
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hostnameback to summary
pack-priv String hostname()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
io.netty.resolver.dns back to summary

private final Class DefaultDnsCache.DnsCacheEntryList

extends AbstractList<DnsCacheEntry>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final List<? extends DnsCacheEntry>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv
DnsCacheEntryList(List<? extends DnsCacheEntry> entries)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the object to be compared for equality with this list
o
)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public DnsCacheEntry
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

entriesback to summary
private final List<? extends DnsCacheEntry> entries

Constructor Detail

DnsCacheEntryListback to summary
pack-priv DnsCacheEntryList(List<? extends DnsCacheEntry> entries)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.AbstractList.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

Parameters
o:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public DnsCacheEntry get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:DnsCacheEntry

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.AbstractList.hashCode.

Returns the hash code value for this list.

Returns:int

the hash code value for this list

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override