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

public Class PooledBasedBackEnd<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.pool.PoolAccessor, net.sf.ehcache.store.Policy, .StoreOperationOutcomes.GetOutcome, net.sf.ehcache.util.concurrent.ConcurrentHashMap, java.util.ArrayList, .EnumSet, .List, .Map, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicReference, org.slf4j.Logger, .LoggerFactory, org.terracotta.statistics.observer.OperationObserver, org.terracotta.statistics.OperationStatistic, .StatisticsManager, org.terracotta.statistics.derived.EventRateSimpleMovingAverage, .OperationResultFilter

A backend to a OnHeapCachingTier that will be cap'ed using a pool
Author
Alex Snaps

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PooledBasedBackEnd.PoolParticipant

A pool participant to use with this Backend

Field Summary

Modifier and TypeField and Description
private volatile ConcurrentHashMap.RemovalCallback
private final OperationObserver<StoreOperationOutcomes.GetOutcome>
private static final Logger
private static final int
private volatile Policy
private final AtomicReference<PoolAccessor<T extends PoolParticipant>>
private static final float
Inherited from net.sf.ehcache.util.concurrent.ConcurrentHashMap:
FAKE_NODEFAKE_TREE_NODE

Constructor Summary

AccessConstructor and Description
public
PooledBasedBackEnd(final Policy
the policy it'll use to decide what to evict
memoryEvictionPolicy
)

Constructs a Pooled 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()
public boolean

Returns:

return true if exactly the right amount of evictions could happen, false otherwise
evict
(int
amount of entries to be evicted
evictions
)

tries to evict as many entries as specified

private Element
public V
get(final Object
the key whose associated value is to be returned
key
)

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

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

Access a key, basically CHM.get()
public Policy
getPolicy()

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

queries the potential eviction policy for the heap caching tier
public long

Returns:

the amount of bytes for this backend
getSizeInBytes
()

Deprecated
Returns the size in bytes
public boolean
hasSpace()

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

Return true if this tier has enough space for more entries.
public V
put(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.put.

Implements java.util.Map.put.

Maps the specified key to the specified value in this table.
public void
putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map
m
)

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

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this one.
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
registerAccessor(final PoolAccessor<T extends PoolParticipant>
the pool accessor to use
poolAccessor
)

Registers the accessor with the backend.

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 boolean
remove(final Object
key with which the specified value is associated
key
,
final Object
value expected to be associated with the specified key
value
)

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

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

Basically java.util.concurrent.ConcurrentMap#remove(Object, Object) CHM.remove(Object, Object)}
public boolean
replace(final K
key with which the specified value is associated
key
,
final V
value expected to be associated with the specified key
oldValue
,
final V
value to be associated with the specified key
newValue
)

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

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

Basically CHM.remove(Object, Object, Object)
public V
replace(final K
key with which the specified value is associated
key
,
final V
value to be associated with the specified key
value
)

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

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to some value.
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:
clearcontainscontainsKeycontainsValueelementsentrySetentrySpliteratorequalsgetRandomValuesgetValueOrDefaulthashCodeinternalPutIfAbsentisEmptykeyskeySetkeySetkeySpliteratormappingCountnewKeySetnewKeySetrecalculateSizeremoveremoveAndNotifyremoveAndNotifysetPoolAccessorsizetoStringvaluesvalueSpliterator

Field Detail

callbackback to summary
private volatile ConcurrentHashMap.RemovalCallback callback
getObserverback to summary
private final OperationObserver<StoreOperationOutcomes.GetOutcome> getObserver
LOGback to summary
private static final Logger LOG
MAX_EVICTIONSback to summary
private static final int MAX_EVICTIONS
policyback to summary
private volatile Policy policy
poolAccessorback to summary
private final AtomicReference<PoolAccessor<T extends PoolParticipant>> poolAccessor

Hides net.sf.ehcache.util.concurrent.ConcurrentHashMap.poolAccessor.

PUT_LOAD_THRESHOLDback to summary
private static final float PUT_LOAD_THRESHOLD

Constructor Detail

PooledBasedBackEndback to summary
public PooledBasedBackEnd(final Policy memoryEvictionPolicy)

Constructs a Pooled backend

Parameters
memoryEvictionPolicy: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
evictback to summary
public boolean evict(int evictions)

tries to evict as many entries as specified

Parameters
evictions:int

amount of entries to be evicted

Returns:boolean

return true if exactly the right amount of evictions could happen, false otherwise

findEvictionCandidateback to summary
private Element findEvictionCandidate()
getback to summary
public V get(final Object key)

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

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

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

Access a key, basically CHM.get()

Parameters
key:Object

the key whose associated value is to be returned

Returns:V

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
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
getSizeInBytesback to summary
public long getSizeInBytes()

Deprecated

Returns the size in bytes

Returns:long

the amount of bytes for this backend

Annotations
@Deprecated
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
putback to summary
public V put(final K key, final V value)

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

Implements java.util.Map.put.

Doc from net.sf.ehcache.util.concurrent.ConcurrentHashMap.put.

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.

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 key, or null if there was no mapping for key

Annotations
@Override
putAllback to summary
public void putAll(final Map<? extends K, ? extends V> m)

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

Implements java.util.Map.putAll.

Doc from net.sf.ehcache.util.concurrent.ConcurrentHashMap.putAll.

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.

Parameters
m:Map<? extends K, ? extends V>

mappings to be stored in this map

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
registerAccessorback to summary
public void registerAccessor(final PoolAccessor<T extends PoolParticipant> poolAccessor)

Registers the accessor with the backend. This can only happen once!

Parameters
poolAccessor:PoolAccessor<T extends PoolParticipant>

the pool accessor to use

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
removeback to summary
public boolean remove(final Object key, final Object value)

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

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

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

Basically java.util.concurrent.ConcurrentMap#remove(Object, Object) CHM.remove(Object, Object)}

Parameters
key:Object

key with which the specified value is associated

value:Object

value expected to be associated with the specified key

Returns:boolean

true if the value was removed

Annotations
@Override
replaceback to summary
public boolean replace(final K key, final V oldValue, final V newValue)

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

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

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

Basically CHM.remove(Object, Object, Object)

Parameters
key:K

key with which the specified value is associated

oldValue:V

value expected to be associated with the specified key

newValue:V

value to be associated with the specified key

Returns:boolean

true if the value was replaced

Annotations
@Override
replaceback to summary
public V replace(final K key, final V value)

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

Implements java.util.concurrent.ConcurrentMap.replace.

Doc from net.sf.ehcache.util.concurrent.ConcurrentHashMap.replace.

Replaces the entry for a key only if currently mapped to some value. This is equivalent to, for this map:

 if (map.containsKey(key))
  return map.put(key, value);
else
  return null;
except that the action is performed atomically.
Parameters
key:K

Doc from java.util.concurrent.ConcurrentMap.replace.

key with which the specified value is associated

value:V

Doc from java.util.concurrent.ConcurrentMap.replace.

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

Annotations
@Override
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

net.sf.ehcache.store.cachingtier back to summary

public Class PooledBasedBackEnd.PoolParticipant

extends Object
implements PoolParticipant
Class Inheritance
  • java.lang.Object
  • net.sf.ehcache.store.cachingtier.PooledBasedBackEnd.PoolParticipant
All Implemented Interfaces
net.sf.ehcache.pool.PoolParticipant

A pool participant to use with this Backend

Field Summary

Modifier and TypeField and Description
private final EventRateSimpleMovingAverage
private final EventRateSimpleMovingAverage
private final PooledBasedBackEnd<Object, Object>

Constructor Summary

AccessConstructor and Description
public
PoolParticipant(final PooledBasedBackEnd<Object, Object>
the backend this participant represents
pooledBasedBackEnd
)

Creates a pool participant

Method Summary

Modifier and TypeMethod and Description
public boolean
evict(final int
the number of elements to evict
count
,
final long
the size in bytes to free (hint)
size
)

Implements net.sf.ehcache.pool.PoolParticipant.evict.

Perform eviction to release resources
public long
public float
public float
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hitRateback to summary
private final EventRateSimpleMovingAverage hitRate
missRateback to summary
private final EventRateSimpleMovingAverage missRate
pooledBasedBackEndback to summary
private final PooledBasedBackEnd<Object, Object> pooledBasedBackEnd

Constructor Detail

PoolParticipantback to summary
public PoolParticipant(final PooledBasedBackEnd<Object, Object> pooledBasedBackEnd)

Creates a pool participant

Parameters
pooledBasedBackEnd:PooledBasedBackEnd<Object, Object>

the backend this participant represents

Method Detail

evictback to summary
public boolean evict(final int count, final long size)

Implements net.sf.ehcache.pool.PoolParticipant.evict.

Doc from net.sf.ehcache.pool.PoolParticipant.evict.

Perform eviction to release resources

Parameters
count:int

the number of elements to evict

size:long

the size in bytes to free (hint)

Returns:boolean

true if the requested number of elements could be evicted

Annotations
@Override
getApproximateCountSizeback to summary
public long getApproximateCountSize()

Implements net.sf.ehcache.pool.PoolParticipant.getApproximateCountSize.

Doc from net.sf.ehcache.pool.PoolParticipant.getApproximateCountSize.

Return the approximate size

Returns:long

the approximate size

Annotations
@Override
getApproximateHitRateback to summary
public float getApproximateHitRate()

Implements net.sf.ehcache.pool.PoolParticipant.getApproximateHitRate.

Doc from net.sf.ehcache.pool.PoolParticipant.getApproximateHitRate.

Return the approximate hit rate

Returns:float

the approximate hit rate

Annotations
@Override
getApproximateMissRateback to summary
public float getApproximateMissRate()

Implements net.sf.ehcache.pool.PoolParticipant.getApproximateMissRate.

Doc from net.sf.ehcache.pool.PoolParticipant.getApproximateMissRate.

Return the approximate miss rate

Returns:float

the approximate miss rate

Annotations
@Override