Class LazyInitializedCacheMap<K,V>

java.lang.Object
org.apache.mina.util.LazyInitializedCacheMap<K,V>
Type Parameters:
K - The key type
V - The value type
All Implemented Interfaces:
Map<K,V>

public class LazyInitializedCacheMap<K,V> extends Object implements Map<K,V>
This map is specially useful when reads are much more frequent than writes and if the cost of instantiating the values is high like allocating an IoBuffer for example. Based on the final implementation of Memoizer written by Brian Goetz and Tim Peierls. This implementation will return an UnsupportedOperationException on each method that is not intended to be called by user code for performance reasons.
Since:
MINA 2.0.0-M2
  • Field Details

  • Constructor Details

    • LazyInitializedCacheMap

      public LazyInitializedCacheMap()
      Default constructor. Uses the default parameters to initialize its internal ConcurrentHashMap.
    • LazyInitializedCacheMap

      public LazyInitializedCacheMap(ConcurrentHashMap<K, LazyInitializer<V>> map)
      This constructor allows to provide a fine tuned ConcurrentHashMap to stick with each special case the user needs.
      Parameters:
      map - The map to use as a cache
  • Method Details

    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • putIfAbsent

      public V putIfAbsent(K key, LazyInitializer<V> value)
      If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
        if (!map.containsKey(key))
            return map.put(key, value);
        else
            return map.get(key);
      except that the action is performed atomically.
      Parameters:
      key - key with which the specified value is to be associated
      value - a lazy initialized value object.
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Throws UnsupportedOperationException as this method would imply performance drops.
      Specified by:
      containsValue in interface Map<K,V>
    • values

      public Collection<V> values()
      Throws UnsupportedOperationException as this method would imply performance drops.
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Throws UnsupportedOperationException as this method would imply performance drops.
      Specified by:
      entrySet in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K, ? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • getValues

      public Collection<LazyInitializer<V>> getValues()
      Returns:
      return the values from the cache
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>