ehcache

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

java.lang.Object
  extended by net.sf.ehcache.util.concurrent.ConcurrentHashMap<K,V>
      extended by net.sf.ehcache.store.cachingtier.CountBasedBackEnd<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 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>
 
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
CountBasedBackEnd(long maxEntriesLocalHeap)
          Constructs a cap'ed backend
CountBasedBackEnd(long maxEntriesLocalHeap, Policy policy)
          Constructs a cap'ed backend
 
Method Summary
 void clear(boolean notify)
          Basically CHM.clear()
 long getMaxEntriesLocalHeap()
          Reads the current capacity limit
 Policy getPolicy()
          queries the potential eviction policy for the heap caching tier
 boolean hasSpace()
          Return true if this tier has enough space for more entries.
 V putIfAbsent(K key, V value)
          
 void recalculateSize(K key)
          This is evil! Don't call this!
 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.
 void setMaxEntriesLocalHeap(long maxEntriesLocalHeap)
          Sets the capacity limit
 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, 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
 
Methods inherited from interface net.sf.ehcache.store.cachingtier.HeapCacheBackEnd
entrySet, get, remove, replace, size
 

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 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

registerEvictionCallback

public void registerEvictionCallback(HeapCacheBackEnd.EvictionCallback<K,V> evictionCallback)
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

recalculateSize

public void recalculateSize(K key)
Description copied from interface: HeapCacheBackEnd
This is evil! Don't call this!

Specified by:
recalculateSize in interface HeapCacheBackEnd<K,V>
Overrides:
recalculateSize in class ConcurrentHashMap<K,V>

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

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

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

ehcache

Copyright 2001-2014, Terracotta, Inc.