Package javax.jmdns.impl
Class DNSCache
- All Implemented Interfaces:
Serializable
,ConcurrentMap<String,
,List<DNSEntry>> Map<String,
List<DNSEntry>>
A table of DNS entries. This is a map table which can handle multiple entries with the same name.
Storing multiple entries with the same name is implemented using a linked list. This is hidden from the user and can change in later implementation.
Here's how to iterate over all entries:
for (Iterator i=dnscache.allValues().iterator(); i.hasNext(); ) { DNSEntry entry = i.next(); ...do something with entry... }And here's how to iterate over all entries having a given name:
for (Iterator i=dnscache.getDNSEntryList(name).iterator(); i.hasNext(); ) { DNSEntry entry = i.next(); ...do something with entry... }
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.KeySetView<K,
V> Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static org.slf4j.Logger
private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Collection
<? extends DNSEntry> _getDNSEntryList
(String name) boolean
addDNSEntry
(DNSEntry dnsEntry) Adds an entry to the table.Returns all entries in the cacheprotected Object
clone()
getDNSEntry
(String name, DNSRecordType type, DNSRecordClass recordClass) Get a matching DNS entry from the table.getDNSEntry
(DNSEntry dnsEntry) Get a matching DNS entry from the table (using isSameEntry).Collection
<? extends DNSEntry> getDNSEntryList
(String name) Iterate only over items with matching name.Collection
<? extends DNSEntry> getDNSEntryList
(String name, DNSRecordType type, DNSRecordClass recordClass) Get all matching DNS entries from the table.void
Prints the content of the cache to thelogger
.boolean
removeDNSEntry
(DNSEntry dnsEntry) Removes a specific entry from the table.boolean
replaceDNSEntry
(DNSEntry newDNSEntry, DNSEntry existingDNSEntry) Replace an existing entry by a new one.
Note: the 2 entries must have the same key.toString()
Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, values
-
Field Details
-
logger
private static org.slf4j.Logger logger -
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
DNSCache
public DNSCache() -
DNSCache
- Parameters:
map
-
-
DNSCache
public DNSCache(int initialCapacity) Create a table with a given initial size.- Parameters:
initialCapacity
-
-
-
Method Details
-
clone
- Overrides:
clone
in classAbstractMap<String,
List<DNSEntry>> - Throws:
CloneNotSupportedException
-
allValues
Returns all entries in the cache- Returns:
- all entries in the cache
-
getDNSEntryList
Iterate only over items with matching name. Returns an list of DNSEntry or null. To retrieve all entries, one must iterate over this linked list.- Parameters:
name
-- Returns:
- list of DNSEntries
-
_getDNSEntryList
-
getDNSEntry
Get a matching DNS entry from the table (using isSameEntry). Returns the entry that was found.- Parameters:
dnsEntry
-- Returns:
- DNSEntry
-
getDNSEntry
Get a matching DNS entry from the table.- Parameters:
name
-type
-recordClass
-- Returns:
- DNSEntry
-
getDNSEntryList
public Collection<? extends DNSEntry> getDNSEntryList(String name, DNSRecordType type, DNSRecordClass recordClass) Get all matching DNS entries from the table.- Parameters:
name
-type
-recordClass
-- Returns:
- list of entries
-
addDNSEntry
Adds an entry to the table.- Parameters:
dnsEntry
-- Returns:
- true if the entry was added
-
removeDNSEntry
Removes a specific entry from the table. Returns true if the entry was found.- Parameters:
dnsEntry
-- Returns:
- true if the entry was removed
-
replaceDNSEntry
Replace an existing entry by a new one.
Note: the 2 entries must have the same key.- Parameters:
newDNSEntry
-existingDNSEntry
-- Returns:
true
if the entry has been replace,false
otherwise.
-
toString
- Overrides:
toString
in classConcurrentHashMap<String,
List<DNSEntry>>
-
logCachedContent
public void logCachedContent()Prints the content of the cache to thelogger
.
-