inet.ipaddr

Class IPAddressNetwork.HostIdentifierStringCache<T extends HostIdentifierString>

  • java.lang.Object
    • inet.ipaddr.IPAddressNetwork.HostIdentifierStringCache<T>
  • Type Parameters:
    T - the type to be cached, typically either IPAddressString or HostName
    All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    IPAddressNetwork.HostNameCache, IPAddressNetwork.IPAddressStringCache
    Enclosing class:
    IPAddressNetwork


    public abstract static class IPAddressNetwork.HostIdentifierStringCache<T extends HostIdentifierString>
    extends java.lang.Object
    implements java.io.Serializable
    Choose a map of your choice to implement a cache of addresses and/or host names.

    For long-running programs or servers that handle many addresses, the benefits of using a cache are that

    • the lookup can provide the same objects for different strings that identify the same host name or address
    • parsing and resolving repeated instances of the same address or host string is minimized. Both IPAddressString and HostName cache their parsed and resolved addresses.
    • other functionality is optimized through caching, since Host Name, IPAddressString, and IPAddress also caches objects such as generated strings. With cached objects, switching between host names, address strings and numeric addresses is constant time.

    You choose the map of your choice to be the backing map for the cache. For example, for thread-safe access to the cache, ConcurrentHashMap is a good choice. For maps of bounded size, LinkedHashMap provides the removeEldestEntry method to override to implement LRU or other eviction mechanisms.

    See Also:
    Serialized Form
    • Constructor Detail

      • HostIdentifierStringCache

        public HostIdentifierStringCache(java.util.Map<java.lang.String,T> backingMap)
    • Method Detail

      • getBackingMap

        public java.util.Map<java.lang.String,T> getBackingMap()
      • contains

        public boolean contains(T value)
        Returns whether the given instance is in the cache.
        Parameters:
        value -
        Returns:
        whether the given instance of T is in the cache
      • get

        public T get(java.lang.String key)
        Gets the object for the given key. If the object does not exist yet then it is created and added to the cache.
        Parameters:
        key -
        Returns:
        the object for the given key
        Throws:
        HostIdentifierException - if the key does not correspond to an instance of type T
      • get

        public T get(byte[] bytes)