public class MemoryStore extends AbstractStore implements TierableStore, PoolableStore, CacheConfigurationListener
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
MemoryStore.BackingFactory
Factory interface to create a MemoryStore backing.
|
attributeExtractorsCLUSTER_COHERENT, NODE_COHERENT| Modifier | Constructor and Description |
|---|---|
protected |
MemoryStore(Ehcache cache,
Pool pool,
boolean notify,
MemoryStore.BackingFactory factory)
Constructs things that all MemoryStores have in common.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
bufferFull()
Memory stores are never backed up and always return false
|
boolean |
canPutWithoutEvicting(Element element)
Check if adding an element won't provoke an eviction.
|
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,
Pool pool)
A factory method to create a MemoryStore.
|
void |
deregistered(CacheConfiguration config)
Indicates that this listener was removed from the given configuration
|
void |
diskCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations disk store capacity
|
void |
dispose()
Prepares for shutdown.
|
Collection<Element> |
elementSet()
Get a collection of the elements in this store
|
protected boolean |
evict(Element element)
Evicts the element from the store
|
boolean |
evictFromOnDisk(int count,
long size)
Perform eviction to release on-disk resources
|
boolean |
evictFromOnHeap(int count,
long size)
Perform eviction to release on-heap resources
|
protected Element |
expireElement(Object key)
Evicts the element for the given key, if it exists and is expired
|
void |
expireElements()
Expire all elements.
|
void |
fill(Element element)
Add this element to the cache if the key is already present or the add
can succeed without resorting to eviction.
|
void |
flush()
Flush to disk only if the cache is diskPersistent.
|
Element |
get(Object key)
Gets an item from the cache.
|
long |
getApproximateDiskByteSize()
Return the approximate disk size in bytes
|
long |
getApproximateDiskCountSize()
Return the approximate disk size
|
float |
getApproximateDiskHitRate()
Return the approximate disk hit rate
|
float |
getApproximateDiskMissRate()
Return the approximate disk miss rate
|
long |
getApproximateHeapByteSize()
Return the approximate heap size in bytes
|
long |
getApproximateHeapCountSize()
Return the approximate heap size
|
float |
getApproximateHeapHitRate()
Return the approximate heap hit rate
|
float |
getApproximateHeapMissRate()
Return the approximate heap miss rate
|
protected static int |
getInitialCapacityForLoadFactor(int maximumSizeGoal,
float loadFactor)
Calculates the initialCapacity for a desired maximumSize goal and loadFactor.
|
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.
|
Set |
getPresentPinnedKeys()
Returns all the keys that are pinned, for which there is a mapping present
|
Element |
getQuiet(Object key)
Gets an item from the cache, without updating statistics.
|
int |
getSize()
Returns the current store size.
|
Status |
getStatus()
Gets the status of the MemoryStore.
|
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered
|
boolean |
hasAbortedSizeOf()
Checks if the cache may contain elements for which the SizeOf engine gave up and only
partially calculated the size.
|
boolean |
isFull()
An algorithm to tell if the MemoryStore is at or beyond its carrying capacity.
|
boolean |
isPersistent()
Is this store persistent (data survives a JVM restart)
|
boolean |
isPinned(Object key)
Check if the key is pinned
|
boolean |
isTierPinned()
Is this TierableStore pinned ?
|
protected Set<?> |
keySet()
Returns the keySet for this store
|
void |
loggingChanged(boolean oldValue,
boolean newValue)
Indicates a change in the configuration for enable/disable logging
|
void |
maxBytesLocalDiskChanged(long oldValue,
long newValue)
Indicates a change in the configuration for maxBytesLocalDisk setting
|
void |
maxBytesLocalHeapChanged(long oldValue,
long newValue)
Indicates a change in the configuration for maxBytesLocalHeap setting
|
void |
memoryCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations memory store capacity
|
protected void |
notifyDirectEviction(Element element)
Called when an element is evicted even before it could be installed inside the store
|
boolean |
put(Element element)
Puts an item in the store.
|
Element |
putIfAbsent(Element element)
Put an element in the store if no element is currently mapped to the elements key.
|
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation
|
void |
recalculateSize(Object key)
Recalculate size of the element mapped to the key
|
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)
Remove the Element mapped to the key for the supplied element if the value of the supplied Element
is equal to the value of the cached Element.
|
boolean |
removeIfNotPinned(Object key)
This method will only remove if the element or the store is not pinned and the key is present in the store
|
void |
removeNoReturn(Object key)
Removes an item from the cache.
|
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)
Replace the cached element only if an Element is currently cached for this key
|
boolean |
replace(Element old,
Element element,
ElementValueComparator comparator)
Replace the cached element only if the value of the current Element is equal to the value of the
supplied old Element.
|
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy.
|
void |
setPinned(Object key,
boolean pinned)
Mark the key as pinned or not
|
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
|
void |
unpinAll()
unpin all pinned keys
|
addStoreListener, executeQuery, getAll, getAllQuiet, getEventListenerList, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherentclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddStoreListener, executeQuery, getAll, getAllQuiet, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherentprotected MemoryStore(Ehcache cache, Pool pool, boolean notify, MemoryStore.BackingFactory factory)
cache - the cachepool - the pool tracking the on-heap usagenotify - whether to notify the Cache's EventNotificationService on eviction and expiryprotected static int getInitialCapacityForLoadFactor(int maximumSizeGoal,
float loadFactor)
maximumSizeGoal - the desired maximum size goalloadFactor - the load factorpublic static MemoryStore create(Ehcache cache, Pool pool)
cache - the cachepool - the pool tracking the on-heap usagepublic void setPinned(Object key, boolean pinned)
public boolean isPinned(Object key)
public void fill(Element element)
fill in interface TierableStoreelement - element to be addedpublic boolean removeIfNotPinned(Object key)
removeIfNotPinned in interface TierableStorekey - the key to the elementStore.remove(Object)public boolean put(Element element) throws CacheException
put in interface Storeelement - the element to addCacheExceptionpublic boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter in interface StoreCacheExceptionpublic final Element get(Object key)
Element is updated.public final Element getQuiet(Object key)
public void removeNoReturn(Object key)
removeNoReturn in interface TierableStorepublic boolean isTierPinned()
isTierPinned in interface TierableStorepublic Set getPresentPinnedKeys()
getPresentPinnedKeys in interface TierableStorepublic boolean isPersistent()
isPersistent in interface TierableStorepublic final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException
removeWithWriter in interface StoreCacheExceptionpublic final boolean bufferFull()
bufferFull in interface Storepublic void expireElements()
expireElements in interface Storeprotected Element expireElement(Object key)
key - the keypublic final void removeAll()
throws CacheException
removeAll in interface StoreCacheExceptionpublic void flush()
public final List<?> getKeys()
protected Set<?> keySet()
public final int getSize()
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize in interface Storepublic final boolean containsKey(Object key)
containsKey in interface Storekey - The Element keyprotected void notifyDirectEviction(Element element)
element - the evicted elementpublic final boolean isFull()
public final boolean canPutWithoutEvicting(Element element)
element - the elementpublic Object getInternalContext()
getInternalContext in interface Storepublic final Status getStatus()
public void timeToIdleChanged(long oldTti,
long newTti)
timeToIdleChanged in interface CacheConfigurationListeneroldTti - previous time to idle valuenewTti - new time to idle valuepublic void timeToLiveChanged(long oldTtl,
long newTtl)
timeToLiveChanged in interface CacheConfigurationListeneroldTtl - previous time to live valuenewTtl - new time to live valuepublic void diskCapacityChanged(int oldCapacity,
int newCapacity)
diskCapacityChanged in interface CacheConfigurationListeneroldCapacity - previous capacitynewCapacity - new capacitypublic void loggingChanged(boolean oldValue,
boolean newValue)
loggingChanged in interface CacheConfigurationListeneroldValue - 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 CacheConfigurationListeneroldCapacity - previous capacitynewCapacity - new capacitypublic void registered(CacheConfiguration config)
registered in interface CacheConfigurationListenerpublic void deregistered(CacheConfiguration config)
deregistered in interface CacheConfigurationListenerpublic void maxBytesLocalHeapChanged(long oldValue,
long newValue)
maxBytesLocalHeapChanged in interface CacheConfigurationListeneroldValue - old value in bytesnewValue - new value in bytespublic void maxBytesLocalDiskChanged(long oldValue,
long newValue)
maxBytesLocalDiskChanged in interface CacheConfigurationListeneroldValue - old value in bytesnewValue - new value in bytespublic boolean containsKeyInMemory(Object key)
containsKeyInMemory in interface Storekey - The Element keypublic boolean containsKeyOffHeap(Object key)
containsKeyOffHeap in interface Storekey - The Element keypublic boolean containsKeyOnDisk(Object key)
containsKeyOnDisk in interface Storekey - The Element keypublic Policy getInMemoryEvictionPolicy()
getInMemoryEvictionPolicy in interface StoreStore.setInMemoryEvictionPolicy(Policy)public int getInMemorySize()
getInMemorySize in interface Storepublic long getInMemorySizeInBytes()
getInMemorySizeInBytes in interface Storepublic int getOffHeapSize()
getOffHeapSize in interface Storepublic long getOffHeapSizeInBytes()
getOffHeapSizeInBytes in interface Storepublic int getOnDiskSize()
getOnDiskSize in interface Storepublic long getOnDiskSizeInBytes()
getOnDiskSizeInBytes in interface Storepublic boolean hasAbortedSizeOf()
hasAbortedSizeOf in interface StorehasAbortedSizeOf in class AbstractStorepublic void setInMemoryEvictionPolicy(Policy policy)
setInMemoryEvictionPolicy in interface Storepolicy - the new policypublic Element putIfAbsent(Element element) throws NullPointerException
putIfAbsent in interface Storeelement - element to be addedNullPointerException - if the element is null, or has a null keyprotected boolean evict(Element element)
element - the element to be evictedpublic Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
removeElement in interface Storeelement - Element to be removedcomparator - ElementValueComparator to use to compare elementsNullPointerException - if the element is null, or has a null keypublic boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException
replace in interface Storeold - Element to be test againstelement - Element to be cachedcomparator - ElementValueComparator to use to compare elementsNullPointerException - if the either Element is null or has a null keyIllegalArgumentException - if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
replace in interface Storeelement - Element to be cachedNullPointerException - if the Element is null or has a null keypublic Object getMBean()
public boolean evictFromOnHeap(int count,
long size)
evictFromOnHeap in interface PoolableStorecount - the number of elements to evictsize - the size in bytes to free (hint)public boolean evictFromOnDisk(int count,
long size)
evictFromOnDisk in interface PoolableStorecount - the number of elements to evictsize - the size in bytes to free (hint)public float getApproximateDiskHitRate()
getApproximateDiskHitRate in interface PoolableStorepublic float getApproximateDiskMissRate()
getApproximateDiskMissRate in interface PoolableStorepublic long getApproximateDiskCountSize()
getApproximateDiskCountSize in interface PoolableStorepublic long getApproximateDiskByteSize()
getApproximateDiskByteSize in interface PoolableStorepublic float getApproximateHeapHitRate()
getApproximateHeapHitRate in interface PoolableStorepublic float getApproximateHeapMissRate()
getApproximateHeapMissRate in interface PoolableStorepublic long getApproximateHeapCountSize()
getApproximateHeapCountSize in interface PoolableStorepublic long getApproximateHeapByteSize()
getApproximateHeapByteSize in interface PoolableStorepublic Collection<Element> elementSet()
public void recalculateSize(Object key)
AbstractStorerecalculateSize in interface StorerecalculateSize in class AbstractStorekey - the keyCopyright © 2003-2014 Terracotta, Inc.. All Rights Reserved.