Package net.sf.ehcache.store.cachingtier
Class PooledBasedBackEnd<K,V>
- java.lang.Object
-
- net.sf.ehcache.util.concurrent.ConcurrentHashMap<K,V>
-
- net.sf.ehcache.store.cachingtier.PooledBasedBackEnd<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 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPooledBasedBackEnd.PoolParticipantA pool participant to use with this Backend-
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 PooledBasedBackEnd(Policy memoryEvictionPolicy)Constructs a Pooled backend
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear(boolean notify)BasicallyCHM.clear()booleanevict(int evictions)tries to evict as many entries as specifiedVget(java.lang.Object key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.PolicygetPolicy()queries the potential eviction policy for the heap caching tierlonggetSizeInBytes()Deprecated.booleanhasSpace()Returntrueif this tier has enough space for more entries.Vput(K key, V value)Maps the specified key to the specified value in this table.voidputAll(java.util.Map<? extends K,? extends V> m)Copies all of the mappings from the specified map to this one.VputIfAbsent(K key, V value)voidregisterAccessor(PoolAccessor poolAccessor)Registers the accessor with the backend.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.booleanremove(java.lang.Object key, java.lang.Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)voidsetPolicy(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, getRandomValues, getValueOrDefault, hashCode, internalPutIfAbsent, isEmpty, keys, keySet, keySet, keySpliterator, mappingCount, newKeySet, newKeySet, recalculateSize, remove, removeAndNotify, removeAndNotify, setPoolAccessor, size, toString, values, valueSpliterator
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Methods inherited from interface net.sf.ehcache.store.cachingtier.HeapCacheBackEnd
entrySet, recalculateSize, size
-
-
-
-
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:
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
-
get
public V get(java.lang.Object key)
Description copied from class:ConcurrentHashMapReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatkey.equals(k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)- Specified by:
getin interfaceHeapCacheBackEnd<K,V>- Specified by:
getin interfacejava.util.Map<K,V>- Overrides:
getin classConcurrentHashMap<K,V>- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
putAll
public void putAll(java.util.Map<? extends K,? extends V> m)
Description copied from class:ConcurrentHashMapCopies 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.
-
put
public V put(K key, V value)
Description copied from class:ConcurrentHashMapMaps 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
getmethod with a key that is equal to the original key.- Specified by:
putin interfacejava.util.Map<K,V>- Overrides:
putin 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
key, ornullif there was no mapping forkey
-
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
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)Description copied from class:ConcurrentHashMap- Specified by:
removein interfacejava.util.concurrent.ConcurrentMap<K,V>- Specified by:
removein interfaceHeapCacheBackEnd<K,V>- Specified by:
removein interfacejava.util.Map<K,V>- Overrides:
removein classConcurrentHashMap<K,V>- Parameters:
key- key with which the specified value is associatedvalue- 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:
replacein interfacejava.util.concurrent.ConcurrentMap<K,V>- Specified by:
replacein interfaceHeapCacheBackEnd<K,V>- Specified by:
replacein interfacejava.util.Map<K,V>- Overrides:
replacein classConcurrentHashMap<K,V>- Parameters:
key- key with which the specified value is associatedoldValue- value expected to be associated with the specified keynewValue- 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
-
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.
-
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:
setPolicyin interfaceHeapCacheBackEnd<K,V>- Parameters:
policy- the new eviction Policy to use
-
registerEvictionCallback
public void registerEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)
Description copied from interface:HeapCacheBackEndLet's you register a single callback for evictions- Specified by:
registerEvictionCallbackin interfaceHeapCacheBackEnd<K,V>- Parameters:
evictionCallback- the thing to call back on
-
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
-
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
-
-