|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.store.AbstractStore
net.sf.ehcache.store.MemoryStore
public class MemoryStore
A Store implementation suitable for fast, concurrent in memory stores. The policy is determined by that configured in the cache.
Field Summary | |
---|---|
protected Ehcache |
cache
The cache this store is associated with. |
protected static int |
CONCURRENCY_LEVEL
Set optimisation for 100 concurrent threads. |
protected static float |
DEFAULT_LOAD_FACTOR
This is the default from ConcurrentHashMap . |
protected Store |
diskStore
The DiskStore associated with this MemoryStore. |
protected SelectableConcurrentHashMap |
map
Map where items are stored by key. |
protected int |
maximumSize
The maximum size of the store (0 == no limit) |
protected Policy |
policy
The eviction policy to use |
protected Status |
status
status. |
protected static int |
TOO_LARGE_TO_EFFICIENTLY_ITERATE
This number is magic. |
protected boolean |
useKeySample
when sampling elements, whether to iterate or to use the keySample array for faster random access |
Fields inherited from interface net.sf.ehcache.store.Store |
---|
CLUSTER_COHERENT, NODE_COHERENT |
Constructor Summary | |
---|---|
protected |
MemoryStore(Ehcache cache,
Store diskStore)
Constructs things that all MemoryStores have in common. |
Method Summary | |
---|---|
boolean |
bufferFull()
Memory stores are never backed up and always return false |
protected void |
clear()
Clears any data structures and places it back to its state when it was first created. |
boolean |
containsKey(Object key)
A check to see if a key is in the Store. |
boolean |
containsKeyInMemory(Object key)
A check to see if a key is in the Store and is currently held in memory. |
boolean |
containsKeyOffHeap(Object key)
A check to see if a key is in the Store and is currently held off-heap. |
boolean |
containsKeyOnDisk(Object key)
A check to see if a key is in the Store and is currently held on disk. |
static MemoryStore |
create(Ehcache cache,
Store diskStore)
A factory method to create a MemoryStore. |
void |
deregistered(CacheConfiguration config)
Indicates that this listener was removed from the given configuration |
protected Policy |
determineEvictionPolicy()
Chooses the Policy from the cache configuration |
void |
diskCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations disk store capacity |
void |
dispose()
Prepares for shutdown. |
protected void |
doPut(Element elementJustAdded)
Puts an element into the store |
protected void |
evict(Element element)
Evict the Element . |
void |
expireElements()
Expire all elements. |
protected Element |
findEvictionCandidate(Element elementJustAdded)
Find a "relatively" unused element, but not the element just added. |
void |
flush()
Flush to disk only if the cache is diskPersistent. |
Element |
get(Object key)
Gets an item from the cache. |
Policy |
getEvictionPolicy()
|
Policy |
getInMemoryEvictionPolicy()
|
int |
getInMemorySize()
Returns the current local in-memory store size |
long |
getInMemorySizeInBytes()
Gets the size of the in-memory portion of the store, in bytes. |
Object |
getInternalContext()
This should not be used, and will generally return null |
List |
getKeys()
Gets an Array of the keys for all elements in the memory cache. |
Object |
getMBean()
Optional implementation specific MBean exposed by the store. |
int |
getOffHeapSize()
Returns the current local off-heap store size |
long |
getOffHeapSizeInBytes()
Gets the size of the off-heap portion of the store, in bytes. |
int |
getOnDiskSize()
Returns the current local on-disk store size |
long |
getOnDiskSizeInBytes()
Gets the size of the on-disk portion of the store, in bytes. |
Element |
getQuiet(Object key)
Gets an item from the cache, without updating statistics. |
int |
getSize()
Returns the current store size. |
long |
getSizeInBytes()
Measures the size of the memory store by measuring the serialized size of all elements. |
Status |
getStatus()
Gets the status of the MemoryStore. |
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered |
boolean |
isFull()
An algorithm to tell if the MemoryStore is at or beyond its carrying capacity. |
void |
loggingChanged(boolean oldValue,
boolean newValue)
Indicates a change in the configuration for enable/disable logging |
void |
memoryCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations memory store capacity |
protected void |
notifyExpiry(Element element)
Before eviction elements are checked. |
boolean |
put(Element element)
Puts an item in the store. |
Element |
putIfAbsent(Element element)
Unsupported in MemoryStore |
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation |
void |
registered(CacheConfiguration config)
Indicates that this listener was registered with the given configuration |
Element |
remove(Object key)
Removes an Element from the store. |
void |
removeAll()
Remove all of the elements from the store. |
Element |
removeElement(Element element,
ElementValueComparator comparator)
Unsupported in MemoryStore |
protected void |
removeElementChosenByEvictionPolicy(Element elementJustAdded)
Removes the element chosen by the eviction policy |
Element |
removeWithWriter(Object key,
CacheWriterManager writerManager)
Removes an item from the store and the cache writer manager in an atomic operation. |
Element |
replace(Element element)
Unsupported in MemoryStore |
boolean |
replace(Element old,
Element element,
ElementValueComparator comparator)
Unsupported in MemoryStore |
protected Element[] |
sampleElements(int size)
Uses random numbers to sample the entire map. |
protected Element[] |
sampleElements(Object keyHint)
Uses random numbers to sample the entire map. |
void |
setEvictionPolicy(Policy policy)
Sets the policy. |
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
protected void |
spoolAllToDisk()
Spools all elements to disk, in preparation for shutdown. |
protected void |
spoolToDisk(Element element)
Puts the element in the DiskStore. |
void |
timeToIdleChanged(long oldTti,
long newTti)
Indicates a change in the configurations time to idle |
void |
timeToLiveChanged(long oldTtl,
long newTtl)
Indicates a change in the configurations time to live |
Methods inherited from class net.sf.ehcache.store.AbstractStore |
---|
addStoreListener, executeQuery, getEventListenerList, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int TOO_LARGE_TO_EFFICIENTLY_ITERATE
protected static final float DEFAULT_LOAD_FACTOR
ConcurrentHashMap
. It should never be used, because
we size the map to the max size of the store.
protected static final int CONCURRENCY_LEVEL
protected Ehcache cache
protected volatile boolean useKeySample
protected SelectableConcurrentHashMap map
protected final Store diskStore
protected volatile int maximumSize
protected volatile Status status
protected volatile Policy policy
Constructor Detail |
---|
protected MemoryStore(Ehcache cache, Store diskStore)
cache
- diskStore
- Method Detail |
---|
public static MemoryStore create(Ehcache cache, Store diskStore)
cache
- diskStore
-
public final boolean put(Element element) throws CacheException
put
in interface Store
element
- the element to add
CacheException
public final boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter
in interface Store
CacheException
public final Element get(Object key)
Element
is updated.
get
in interface Store
key
- the key of the Element
public final Element getQuiet(Object key)
getQuiet
in interface Store
key
- the cache key
public final Element remove(Object key)
remove
in interface Store
key
- the key of the Element, usually a String
public final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException
removeWithWriter
in interface Store
CacheException
public final boolean bufferFull()
bufferFull
in interface Store
public void expireElements()
expireElements
in interface Store
protected final Policy determineEvictionPolicy()
public final void removeAll() throws CacheException
removeAll
in interface Store
CacheException
protected final void clear()
public final void dispose()
dispose
in interface Store
public final void flush()
flush
in interface Store
protected final void spoolAllToDisk()
protected void spoolToDisk(Element element)
element
- The Elementpublic final List getKeys()
getKeys
in interface Store
public final int getSize()
getSize
in interface Store
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize
in interface Store
public final boolean containsKey(Object key)
containsKey
in interface Store
key
- The Element key
public final long getSizeInBytes() throws CacheException
CacheException
protected final void evict(Element element) throws CacheException
Element
.
Evict means that the Element
is:
Element
is spooled to the DiskStore
Element
is removed.
element
- the Element
to be evicted.
CacheException
protected final void notifyExpiry(Element element)
element
- public final boolean isFull()
protected void doPut(Element elementJustAdded)
protected void removeElementChosenByEvictionPolicy(Element elementJustAdded)
elementJustAdded
- it is possible for this to be nullprotected final Element findEvictionCandidate(Element elementJustAdded)
protected Element[] sampleElements(Object keyHint)
protected Element[] sampleElements(int size)
ConcurrentHashMap
iterator.
public Policy getEvictionPolicy()
public void setEvictionPolicy(Policy policy)
policy
- a new policy to be used in evicting elements in this storepublic Object getInternalContext()
getInternalContext
in interface Store
public final Status getStatus()
getStatus
in interface Store
public void timeToIdleChanged(long oldTti, long newTti)
timeToIdleChanged
in interface CacheConfigurationListener
oldTti
- previous time to idle valuenewTti
- new time to idle valuepublic void timeToLiveChanged(long oldTtl, long newTtl)
timeToLiveChanged
in interface CacheConfigurationListener
oldTtl
- previous time to live valuenewTtl
- new time to live valuepublic void diskCapacityChanged(int oldCapacity, int newCapacity)
diskCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void loggingChanged(boolean oldValue, boolean newValue)
loggingChanged
in interface CacheConfigurationListener
oldValue
- old value whether logging was enabled or notnewValue
- new value whether logging was enabled or notpublic void memoryCapacityChanged(int oldCapacity, int newCapacity)
memoryCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void registered(CacheConfiguration config)
registered
in interface CacheConfigurationListener
public void deregistered(CacheConfiguration config)
deregistered
in interface CacheConfigurationListener
public boolean containsKeyInMemory(Object key)
containsKeyInMemory
in interface Store
key
- The Element key
public boolean containsKeyOffHeap(Object key)
containsKeyOffHeap
in interface Store
key
- The Element key
public boolean containsKeyOnDisk(Object key)
containsKeyOnDisk
in interface Store
key
- The Element key
public Policy getInMemoryEvictionPolicy()
getInMemoryEvictionPolicy
in interface Store
Store.setInMemoryEvictionPolicy(Policy)
public int getInMemorySize()
getInMemorySize
in interface Store
public long getInMemorySizeInBytes()
getInMemorySizeInBytes
in interface Store
public int getOffHeapSize()
getOffHeapSize
in interface Store
public long getOffHeapSizeInBytes()
getOffHeapSizeInBytes
in interface Store
public int getOnDiskSize()
getOnDiskSize
in interface Store
public long getOnDiskSizeInBytes()
getOnDiskSizeInBytes
in interface Store
public void setInMemoryEvictionPolicy(Policy policy)
setInMemoryEvictionPolicy
in interface Store
policy
- the new policypublic Element putIfAbsent(Element element) throws NullPointerException
putIfAbsent
in interface Store
element
- element to be added
NullPointerException
- if the element is null, or has a null keypublic Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
removeElement
in interface Store
element
- Element to be removedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the element is null, or has a null keypublic boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException
replace
in interface Store
old
- Element to be test againstelement
- Element to be cachedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the either Element is null or has a null key
IllegalArgumentException
- if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
replace
in interface Store
element
- Element to be cached
NullPointerException
- if the Element is null or has a null keypublic Object getMBean()
getMBean
in interface Store
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |