Package net.sf.ehcache.store.cachingtier
Class CountBasedBackEnd<K,V>
- java.lang.Object
-
- net.sf.ehcache.util.concurrent.ConcurrentHashMap<K,V>
-
- net.sf.ehcache.store.cachingtier.CountBasedBackEnd<K,V>
-
- Type Parameters:
K- the key typeV- 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.ehcache.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.EntrySetView<K,V>, ConcurrentHashMap.KeySetView<K,V>, ConcurrentHashMap.Node, ConcurrentHashMap.RemovalCallback, ConcurrentHashMap.Spliterator<T>, ConcurrentHashMap.TreeNode, ConcurrentHashMap.ValuesView<K,V>
-
Nested classes/interfaces inherited from interface net.sf.ehcache.store.cachingtier.HeapCacheBackEnd
HeapCacheBackEnd.EvictionCallback<K,V>
-
-
Field Summary
-
Fields inherited from class net.sf.ehcache.util.concurrent.ConcurrentHashMap
FAKE_NODE, FAKE_TREE_NODE
-
-
Constructor Summary
Constructors Constructor Description CountBasedBackEnd(long maxEntriesLocalHeap)Constructs a cap'ed backendCountBasedBackEnd(long maxEntriesLocalHeap, Policy policy)Constructs a cap'ed backend
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(boolean notify)BasicallyCHM.clear()longgetMaxEntriesLocalHeap()Reads the current capacity limitPolicygetPolicy()queries the potential eviction policy for the heap caching tierbooleanhasSpace()Returntrueif this tier has enough space for more entries.VputIfAbsent(K key, V value)voidrecalculateSize(K key)This is evil! Don't call this!voidregisterEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)Let's you register a single callback for evictionsVremove(java.lang.Object key)Removes the key (and its corresponding value) from this map.voidsetMaxEntriesLocalHeap(long maxEntriesLocalHeap)Sets the capacity limitvoidsetPolicy(Policy policy)Dynamic property to switch the policy out-
Methods inherited from class net.sf.ehcache.util.concurrent.ConcurrentHashMap
clear, contains, containsKey, containsValue, elements, entrySet, entrySpliterator, equals, get, getRandomValues, getValueOrDefault, hashCode, internalPutIfAbsent, isEmpty, keys, keySet, keySet, keySpliterator, mappingCount, newKeySet, newKeySet, put, putAll, remove, remove, removeAndNotify, removeAndNotify, replace, replace, setPoolAccessor, size, toString, values, valueSpliterator
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
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 evictingpolicy- 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:
setPolicyin interfaceHeapCacheBackEnd<K,V>- Parameters:
policy- the new eviction Policy to use
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsentin interfacejava.util.concurrent.ConcurrentMap<K,V>- Specified by:
putIfAbsentin interfaceHeapCacheBackEnd<K,V>- Specified by:
putIfAbsentin interfacejava.util.Map<K,V>- Overrides:
putIfAbsentin classConcurrentHashMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key,
or
nullif there was no mapping for the key
-
registerEvictionCallback
public void registerEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)
Let's you register a single callback for evictions- Specified by:
registerEvictionCallbackin interfaceHeapCacheBackEnd<K,V>- Parameters:
evictionCallback- the thing to call back on
-
recalculateSize
public void recalculateSize(K key)
Description copied from interface:HeapCacheBackEndThis is evil! Don't call this!- Specified by:
recalculateSizein interfaceHeapCacheBackEnd<K,V>- Overrides:
recalculateSizein classConcurrentHashMap<K,V>
-
remove
public V remove(java.lang.Object key)
Description copied from class:ConcurrentHashMapRemoves the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.- Specified by:
removein interfaceHeapCacheBackEnd<K,V>- Specified by:
removein interfacejava.util.Map<K,V>- Overrides:
removein classConcurrentHashMap<K,V>- Parameters:
key- the key that needs to be removed- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey
-
getPolicy
public Policy getPolicy()
Description copied from interface:HeapCacheBackEndqueries the potential eviction policy for the heap caching tier- Specified by:
getPolicyin interfaceHeapCacheBackEnd<K,V>- Returns:
- the policy
-
clear
public void clear(boolean notify)
Description copied from interface:HeapCacheBackEndBasicallyCHM.clear()- Specified by:
clearin interfaceHeapCacheBackEnd<K,V>- Parameters:
notify- whether to notify listeners or not
-
hasSpace
public boolean hasSpace()
Description copied from interface:HeapCacheBackEndReturntrueif this tier has enough space for more entries.- Specified by:
hasSpacein interfaceHeapCacheBackEnd<K,V>- Returns:
trueif 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
-
-