Class CountBasedBackEnd<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.util.concurrent.ConcurrentMap<K,​V>, java.util.Map<K,​V>, HeapCacheBackEnd<K,​V>

    public class CountBasedBackEnd<K,​V>
    extends ConcurrentHashMap<K,​V>
    implements HeapCacheBackEnd<K,​V>
    A backend to a OnHeapCachingTier that will be cap'ed based on the amount of entries
    Author:
    Alex Snaps
    • Constructor Detail

      • CountBasedBackEnd

        public CountBasedBackEnd​(long maxEntriesLocalHeap)
        Constructs a cap'ed backend
        Parameters:
        maxEntriesLocalHeap - amount of mappings this should hold before it starts evicting
      • CountBasedBackEnd

        public CountBasedBackEnd​(long maxEntriesLocalHeap,
                                 Policy policy)
        Constructs a cap'ed backend
        Parameters:
        maxEntriesLocalHeap - amount of mappings this should hold before it starts evicting
        policy - the policy it'll use to decide what to evict
    • Method Detail

      • setPolicy

        public void setPolicy​(Policy policy)
        Dynamic property to switch the policy out
        Specified by:
        setPolicy in interface HeapCacheBackEnd<K,​V>
        Parameters:
        policy - the new eviction Policy to use
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Specified by:
        putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        putIfAbsent in interface HeapCacheBackEnd<K,​V>
        Specified by:
        putIfAbsent in interface java.util.Map<K,​V>
        Overrides:
        putIfAbsent in class ConcurrentHashMap<K,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with the specified key, or null if there was no mapping for the key
      • remove

        public V remove​(java.lang.Object key)
        Description copied from class: ConcurrentHashMap
        Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.
        Specified by:
        remove in interface HeapCacheBackEnd<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class ConcurrentHashMap<K,​V>
        Parameters:
        key - the key that needs to be removed
        Returns:
        the previous value associated with key, or null if there was no mapping for key
      • clear

        public void clear​(boolean notify)
        Description copied from interface: HeapCacheBackEnd
        Basically CHM.clear()
        Specified by:
        clear in interface HeapCacheBackEnd<K,​V>
        Parameters:
        notify - whether to notify listeners or not
      • hasSpace

        public boolean hasSpace()
        Description copied from interface: HeapCacheBackEnd
        Return true if this tier has enough space for more entries.
        Specified by:
        hasSpace in interface HeapCacheBackEnd<K,​V>
        Returns:
        true if there is space for more entries.
      • setMaxEntriesLocalHeap

        public void setMaxEntriesLocalHeap​(long maxEntriesLocalHeap)
        Sets the capacity limit
        Parameters:
        maxEntriesLocalHeap - the new limit
      • getMaxEntriesLocalHeap

        public long getMaxEntriesLocalHeap()
        Reads the current capacity limit
        Returns:
        the capacity limit