Top Description Fields Constructors Methods
net.sf.ehcache.store.cachingtier

public Class CountBasedBackEnd<K, V>

extends ConcurrentHashMap<K, V>
implements HeapCacheBackEnd<K, V>
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.cachingtier.HeapCacheBackEnd
Type Parameters
<K>
the key type
<V>
the value type
Imports
net.sf.ehcache.Element, net.sf.ehcache.store.LruPolicy, .Policy, net.sf.ehcache.util.concurrent.ConcurrentHashMap, org.slf4j.Logger, .LoggerFactory, java.util.ArrayList, .List, .Map

A backend to a OnHeapCachingTier that will be cap'ed based on the amount of entries
Author
Alex Snaps

Field Summary

Modifier and TypeField and Description
private volatile ConcurrentHashMap.RemovalCallback
private static final Logger
private static final int
private volatile long
private volatile Policy
private static final int
Inherited from net.sf.ehcache.util.concurrent.ConcurrentHashMap:
FAKE_NODEFAKE_TREE_NODE

Constructor Summary

AccessConstructor and Description
public
CountBasedBackEnd(final long
amount of mappings this should hold before it starts evicting
maxEntriesLocalHeap
)

Constructs a cap'ed backend

public
CountBasedBackEnd(final long
amount of mappings this should hold before it starts evicting
maxEntriesLocalHeap
,
final Policy
the policy it'll use to decide what to evict
policy
)

Constructs a cap'ed backend

Method Summary

Modifier and TypeMethod and Description
public void
clear(final boolean
whether to notify listeners or not
notify
)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.clear.

Basically CHM.clear()
private void
evictIfRequired(final K key, final V value)

private Element
findEvictionCandidate(final K key, final V value)

public long

Returns:

the capacity limit
getMaxEntriesLocalHeap
()

Reads the current capacity limit

public Policy
getPolicy()

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.getPolicy.

queries the potential eviction policy for the heap caching tier
public boolean
hasSpace()

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.hasSpace.

Return true if this tier has enough space for more entries.
public V
putIfAbsent(final K
key with which the specified value is to be associated
key
,
final V
value to be associated with the specified key
value
)

Overrides net.sf.ehcache.util.concurrent.ConcurrentHashMap.putIfAbsent.

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.putIfAbsent, java.util.concurrent.ConcurrentMap.putIfAbsent.

Basically java.util.concurrent.ConcurrentMap#putIfAbsent(Object, Object) CHM.putIfAbsent(Object, Object)}, but will evict if required (on successful put)
public void
public void
registerEvictionCallback(final HeapCacheBackEnd.EvictionCallback<K, V>
the thing to call back on
evictionCallback
)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.registerEvictionCallback.

Let's you register a single callback for evictions
public V
public void
setMaxEntriesLocalHeap(final long
the new limit
maxEntriesLocalHeap
)

Sets the capacity limit

public void
setPolicy(final Policy
the new eviction Policy to use
policy
)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.setPolicy.

Dynamic property to switch the policy out
Inherited from net.sf.ehcache.util.concurrent.ConcurrentHashMap:
clearcontainscontainsKeycontainsValueelementsentrySetentrySpliteratorequalsgetgetRandomValuesgetValueOrDefaulthashCodeinternalPutIfAbsentisEmptykeyskeySetkeySetkeySpliteratormappingCountnewKeySetnewKeySetputputAllremoveremoveremoveAndNotifyremoveAndNotifyreplacereplacesetPoolAccessorsizetoStringvaluesvalueSpliterator

Field Detail

callbackback to summary
private volatile ConcurrentHashMap.RemovalCallback callback
LOGback to summary
private static final Logger LOG
MAX_EVICTIONSback to summary
private static final int MAX_EVICTIONS
maxEntriesLocalHeapback to summary
private volatile long maxEntriesLocalHeap
policyback to summary
private volatile Policy policy
SAMPLING_SIZEback to summary
private static final int SAMPLING_SIZE

Constructor Detail

CountBasedBackEndback to summary
public CountBasedBackEnd(final long maxEntriesLocalHeap)

Constructs a cap'ed backend

Parameters
maxEntriesLocalHeap:long

amount of mappings this should hold before it starts evicting

CountBasedBackEndback to summary
public CountBasedBackEnd(final long maxEntriesLocalHeap, final Policy policy)

Constructs a cap'ed backend

Parameters
maxEntriesLocalHeap:long

amount of mappings this should hold before it starts evicting

policy:Policy

the policy it'll use to decide what to evict

Method Detail

clearback to summary
public void clear(final boolean notify)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.clear.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.clear.

Basically CHM.clear()

Parameters
notify:boolean

whether to notify listeners or not

Annotations
@Override
evictIfRequiredback to summary
private void evictIfRequired(final K key, final V value)
findEvictionCandidateback to summary
private Element findEvictionCandidate(final K key, final V value)
getMaxEntriesLocalHeapback to summary
public long getMaxEntriesLocalHeap()

Reads the current capacity limit

Returns:long

the capacity limit

getPolicyback to summary
public Policy getPolicy()

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.getPolicy.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.getPolicy.

queries the potential eviction policy for the heap caching tier

Returns:Policy

the policy

Annotations
@Override
hasSpaceback to summary
public boolean hasSpace()

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.hasSpace.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.hasSpace.

Return true if this tier has enough space for more entries.

Returns:boolean

true if there is space for more entries.

Annotations
@Override
putIfAbsentback to summary
public V putIfAbsent(final K key, final V value)

Overrides net.sf.ehcache.util.concurrent.ConcurrentHashMap.putIfAbsent.

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.putIfAbsent, java.util.concurrent.ConcurrentMap.putIfAbsent.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.putIfAbsent.

Basically java.util.concurrent.ConcurrentMap#putIfAbsent(Object, Object) CHM.putIfAbsent(Object, Object)}, but will evict if required (on successful put)

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)

Annotations
@Override
recalculateSizeback to summary
public void recalculateSize(final K key)

Overrides net.sf.ehcache.util.concurrent.ConcurrentHashMap.recalculateSize.

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.recalculateSize.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.recalculateSize.

This is evil! Don't call this!

Annotations
@Override
registerEvictionCallbackback to summary
public void registerEvictionCallback(final HeapCacheBackEnd.EvictionCallback<K, V> evictionCallback)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.registerEvictionCallback.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.registerEvictionCallback.

Let's you register a single callback for evictions

Parameters
evictionCallback:HeapCacheBackEnd.EvictionCallback<K, V>

the thing to call back on

Annotations
@Override
removeback to summary
public V remove(final Object key)

Overrides net.sf.ehcache.util.concurrent.ConcurrentHashMap.remove.

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.remove, java.util.Map.remove.

Doc from net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.remove.

Basically CHM.remove(Object)

Parameters
key:Object

key whose mapping is to be removed from the map

Returns:V

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
setMaxEntriesLocalHeapback to summary
public void setMaxEntriesLocalHeap(final long maxEntriesLocalHeap)

Sets the capacity limit

Parameters
maxEntriesLocalHeap:long

the new limit

setPolicyback to summary
public void setPolicy(final Policy policy)

Implements net.sf.ehcache.store.cachingtier.HeapCacheBackEnd.setPolicy.

Dynamic property to switch the policy out

Parameters
policy:Policy

the new eviction Policy to use