Class DNSCache

  • All Implemented Interfaces:
    java.io.Serializable, java.util.concurrent.ConcurrentMap<java.lang.String,​java.util.List<DNSEntry>>, java.util.Map<java.lang.String,​java.util.List<DNSEntry>>

    public class DNSCache
    extends java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.util.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...
           }
     
    Author:
    Arthur van Hoff, Werner Randelshofer, Rick Blair, Pierre Frisch
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap

        java.util.concurrent.ConcurrentHashMap.KeySetView<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      DNSCache()  
      DNSCache​(int initialCapacity)
      Create a table with a given initial size.
      DNSCache​(DNSCache map)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addDNSEntry​(DNSEntry dnsEntry)
      Adds an entry to the table.
      java.util.Collection<DNSEntry> allValues()
      Returns all entries in the cache
      protected java.lang.Object clone()
      DNSEntry getDNSEntry​(java.lang.String name, DNSRecordType type, DNSRecordClass recordClass)
      Get a matching DNS entry from the table.
      DNSEntry getDNSEntry​(DNSEntry dnsEntry)
      Get a matching DNS entry from the table (using isSameEntry).
      java.util.Collection<? extends DNSEntry> getDNSEntryList​(java.lang.String name)
      Iterate only over items with matching name.
      java.util.Collection<? extends DNSEntry> getDNSEntryList​(java.lang.String name, DNSRecordType type, DNSRecordClass recordClass)
      Get all matching DNS entries from the table.
      void logCachedContent()
      Prints the content of the cache to the logger.
      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.
      java.lang.String 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
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DNSCache

        public DNSCache()
      • DNSCache

        public DNSCache​(DNSCache map)
        Parameters:
        map -
      • DNSCache

        public DNSCache​(int initialCapacity)
        Create a table with a given initial size.
        Parameters:
        initialCapacity -
    • Method Detail

      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.util.AbstractMap<java.lang.String,​java.util.List<DNSEntry>>
        Throws:
        java.lang.CloneNotSupportedException
      • allValues

        public java.util.Collection<DNSEntry> allValues()
        Returns all entries in the cache
        Returns:
        all entries in the cache
      • getDNSEntryList

        public java.util.Collection<? extends DNSEntry> getDNSEntryList​(java.lang.String name)
        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
      • getDNSEntry

        public DNSEntry getDNSEntry​(DNSEntry dnsEntry)
        Get a matching DNS entry from the table (using isSameEntry). Returns the entry that was found.
        Parameters:
        dnsEntry -
        Returns:
        DNSEntry
      • getDNSEntry

        public DNSEntry getDNSEntry​(java.lang.String name,
                                    DNSRecordType type,
                                    DNSRecordClass recordClass)
        Get a matching DNS entry from the table.
        Parameters:
        name -
        type -
        recordClass -
        Returns:
        DNSEntry
      • getDNSEntryList

        public java.util.Collection<? extends DNSEntry> getDNSEntryList​(java.lang.String name,
                                                                        DNSRecordType type,
                                                                        DNSRecordClass recordClass)
        Get all matching DNS entries from the table.
        Parameters:
        name -
        type -
        recordClass -
        Returns:
        list of entries
      • addDNSEntry

        public boolean addDNSEntry​(DNSEntry dnsEntry)
        Adds an entry to the table.
        Parameters:
        dnsEntry -
        Returns:
        true if the entry was added
      • removeDNSEntry

        public boolean removeDNSEntry​(DNSEntry dnsEntry)
        Removes a specific entry from the table. Returns true if the entry was found.
        Parameters:
        dnsEntry -
        Returns:
        true if the entry was removed
      • replaceDNSEntry

        public boolean replaceDNSEntry​(DNSEntry newDNSEntry,
                                       DNSEntry existingDNSEntry)
        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

        public java.lang.String toString()
        Overrides:
        toString in class java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.util.List<DNSEntry>>
      • logCachedContent

        public void logCachedContent()
        Prints the content of the cache to the logger.