Class PooledBasedBackEnd<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 PooledBasedBackEnd<K,​V>
    extends ConcurrentHashMap<K,​V>
    implements HeapCacheBackEnd<K,​V>
    A backend to a OnHeapCachingTier that will be cap'ed using a pool
    Author:
    Alex Snaps
    • Constructor Detail

      • PooledBasedBackEnd

        public PooledBasedBackEnd​(Policy memoryEvictionPolicy)
        Constructs a Pooled backend
        Parameters:
        memoryEvictionPolicy - the policy it'll use to decide what to evict
    • Method Detail

      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Description copied from class: ConcurrentHashMap
        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
      • get

        public V get​(java.lang.Object key)
        Description copied from class: ConcurrentHashMap
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

        More formally, if this map contains a mapping from a key k to a value v such that key.equals(k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

        Specified by:
        get in interface HeapCacheBackEnd<K,​V>
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class ConcurrentHashMap<K,​V>
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this map contains no mapping for the key
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Description copied from class: ConcurrentHashMap
        Copies all of the mappings from the specified map to this one. These mappings replace any mappings that this map had for any of the keys currently in the specified map.
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Overrides:
        putAll in class ConcurrentHashMap<K,​V>
        Parameters:
        m - mappings to be stored in this map
      • put

        public V put​(K key,
                     V value)
        Description copied from class: ConcurrentHashMap
        Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

        The value can be retrieved by calling the get method with a key that is equal to the original key.

        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put 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 key, or null if there was no mapping for 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
      • remove

        public boolean remove​(java.lang.Object key,
                              java.lang.Object value)
        Description copied from class: ConcurrentHashMap
        Specified by:
        remove in interface java.util.concurrent.ConcurrentMap<K,​V>
        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 - key with which the specified value is associated
        value - value expected to be associated with the specified key
        Returns:
        true if the value was removed
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Description copied from class: ConcurrentHashMap
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface HeapCacheBackEnd<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
        Overrides:
        replace in class ConcurrentHashMap<K,​V>
        Parameters:
        key - key with which the specified value is associated
        oldValue - value expected to be associated with the specified key
        newValue - value to be associated with the specified key
        Returns:
        true if the value was replaced
      • replace

        public V replace​(K key,
                         V value)
        Description copied from class: ConcurrentHashMap
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
        Overrides:
        replace in class ConcurrentHashMap<K,​V>
        Returns:
        the previous value associated with the specified key, or null if there was no mapping for the 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.
      • evict

        public boolean evict​(int evictions)
        tries to evict as many entries as specified
        Parameters:
        evictions - amount of entries to be evicted
        Returns:
        return true if exactly the right amount of evictions could happen, false otherwise
      • 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
      • registerAccessor

        public void registerAccessor​(PoolAccessor poolAccessor)
        Registers the accessor with the backend. This can only happen once!
        Parameters:
        poolAccessor - the pool accessor to use
      • getSizeInBytes

        @Deprecated
        public long getSizeInBytes()
        Deprecated.
        Returns the size in bytes
        Returns:
        the amount of bytes for this backend