ehcache

net.sf.ehcache.store.cachingtier
Class PooledBasedBackEnd<K,V>

java.lang.Object
  extended by net.sf.ehcache.util.concurrent.ConcurrentHashMap<K,V>
      extended by net.sf.ehcache.store.cachingtier.PooledBasedBackEnd<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
ConcurrentMap<K,V>, 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
static class PooledBasedBackEnd.PoolParticipant
          A 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>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class net.sf.ehcache.util.concurrent.ConcurrentHashMap
FAKE_NODE, FAKE_TREE_NODE
 
Constructor Summary
PooledBasedBackEnd(Policy memoryEvictionPolicy)
          Constructs a Pooled backend
 
Method Summary
 void clear(boolean notify)
          Basically CHM.clear()
 boolean evict(int evictions)
          tries to evict as many entries as specified
 V get(Object key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 Policy getPolicy()
          queries the potential eviction policy for the heap caching tier
 long getSizeInBytes()
          Deprecated. 
 boolean hasSpace()
          Return true if this tier has enough space for more entries.
 V put(K key, V value)
          Maps the specified key to the specified value in this table.
 void putAll(Map<? extends K,? extends V> m)
          Copies all of the mappings from the specified map to this one.
 V putIfAbsent(K key, V value)
          
 void registerAccessor(PoolAccessor poolAccessor)
          Registers the accessor with the backend.
 void registerEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)
          Let's you register a single callback for evictions
 V remove(Object key)
          Removes the key (and its corresponding value) from this map.
 boolean remove(Object key, Object value)
          
 V replace(K key, V value)
          
 boolean replace(K key, V oldValue, V newValue)
          
 void setPolicy(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 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:
putIfAbsent in interface ConcurrentMap<K,V>
Specified by:
putIfAbsent in interface HeapCacheBackEnd<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(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 Map<K,V>
Specified by:
get in interface HeapCacheBackEnd<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(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 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 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(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 Map<K,V>
Specified by:
remove in interface HeapCacheBackEnd<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(Object key,
                      Object value)
Description copied from class: ConcurrentHashMap

Specified by:
remove in interface ConcurrentMap<K,V>
Specified by:
remove in interface HeapCacheBackEnd<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 ConcurrentMap<K,V>
Specified by:
replace in interface HeapCacheBackEnd<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 ConcurrentMap<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

registerEvictionCallback

public void registerEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)
Description copied from interface: HeapCacheBackEnd
Let's you register a single callback for evictions

Specified by:
registerEvictionCallback in interface HeapCacheBackEnd<K,V>
Parameters:
evictionCallback - the thing to call back on

getPolicy

public Policy getPolicy()
Description copied from interface: HeapCacheBackEnd
queries the potential eviction policy for the heap caching tier

Specified by:
getPolicy in interface HeapCacheBackEnd<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

ehcache

Copyright 2001-2014, Terracotta, Inc.