Package net.sf.ehcache.transaction
Class AbstractTransactionStore
- java.lang.Object
-
- net.sf.ehcache.store.AbstractStore
-
- net.sf.ehcache.transaction.AbstractTransactionStore
-
- All Implemented Interfaces:
Store,TerracottaStore
- Direct Known Subclasses:
JtaLocalTransactionStore,LocalTransactionStore,XATransactionStore
public abstract class AbstractTransactionStore extends AbstractStore implements TerracottaStore
Abstract transactional store which provides implementation of all non-transactional methods- Author:
- Ludovic Orban
-
-
Field Summary
Fields Modifier and Type Field Description protected StoreunderlyingStoreThe underlying store wrapped by this store-
Fields inherited from class net.sf.ehcache.store.AbstractStore
attributeExtractors, searchManager
-
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTransactionStore(Store underlyingStore)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbufferFull()Some store types, such as the disk stores can fill their write buffers if puts come in too fast.booleancontainsKeyInMemory(java.lang.Object key)A check to see if a key is in the Store and is currently held in memory.booleancontainsKeyOffHeap(java.lang.Object key)A check to see if a key is in the Store and is currently held off-heap.booleancontainsKeyOnDisk(java.lang.Object key)A check to see if a key is in the Store and is currently held on disk.WriteBehindcreateWriteBehind()WriteBehindcreateWriteBehindvoiddispose()Prepares for shutdown.ResultsexecuteQuery(StoreQuery query)Execute the given query on this storevoidexpireElements()Expire all elements.voidflush()Flush elements to persistent store.PolicygetInMemoryEvictionPolicy()intgetInMemorySize()Returns the current local in-memory store sizelonggetInMemorySizeInBytes()Gets the size of the in-memory portion of the store, in bytes.java.lang.ObjectgetInternalContext()This should not be used, and will generally return nulljava.util.SetgetLocalKeys()Returns set of keys from the cache which are present in the node locally.java.lang.ObjectgetMBean()Optional implementation specific MBean exposed by the store.intgetOffHeapSize()Returns the current local off-heap store sizelonggetOffHeapSizeInBytes()Gets the size of the off-heap portion of the store, in bytes.ElementgetOldElement(java.lang.Object key)Method to get to theElementmatching the key, oblivious of any in-flight transaction.intgetOnDiskSize()Returns the current local on-disk store sizelonggetOnDiskSizeInBytes()Gets the size of the on-disk portion of the store, in bytes.<T> Attribute<T>getSearchAttribute(java.lang.String attributeName)Retrieve the given named search attributejava.util.Set<Attribute>getSearchAttributes()StatusgetStatus()Returns the cache status.CacheConfiguration.TransactionalModegetTransactionalMode()Get the transactional mode of this store.booleanhasAbortedSizeOf()Checks if the cache may contain elements for which the SizeOf engine gave up and only partially calculated the size.booleanisCacheCoherent()Indicates whether this store provides a coherent view of all the elements in a cache.booleanisClusterCoherent()Returns true if the cache is in coherent mode cluster-wide.booleanisNodeCoherent()Returns true if the cache is in coherent mode for the current node.voidnotifyCacheEventListenersChanged()Notify the underlying store that some change has occured in the set of registered cache listeners.voidquickClear()Remove all the contents of the store.intquickSize()Get an approximate count of elements in the store.voidsetAttributeExtractors(java.util.Map<java.lang.String,AttributeExtractor> extractors)Inform this store of the configured attribute extractors.voidsetInMemoryEvictionPolicy(Policy policy)Sets the eviction policy strategy.voidsetNodeCoherent(boolean coherent)Sets the cache in coherent or incoherent mode for the current node depending on the parameter.ElementunsafeGet(java.lang.Object key)Returns the local value associated with the key.voidwaitUntilClusterCoherent()This method waits until the cache is in coherent mode in all the connected nodes.-
Methods inherited from class net.sf.ehcache.store.AbstractStore
addStoreListener, getAll, getAllQuiet, getEventListenerList, putAll, recalculateSize, removeAll, removeStoreListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.ehcache.store.Store
addStoreListener, containsKey, get, getAll, getAllQuiet, getKeys, getQuiet, getSize, getTerracottaClusteredSize, put, putAll, putIfAbsent, putWithWriter, recalculateSize, remove, removeAll, removeAll, removeElement, removeStoreListener, removeWithWriter, replace, replace
-
-
-
-
Field Detail
-
underlyingStore
protected final Store underlyingStore
The underlying store wrapped by this store
-
-
Constructor Detail
-
AbstractTransactionStore
protected AbstractTransactionStore(Store underlyingStore)
Constructor- Parameters:
underlyingStore- the underlying store
-
-
Method Detail
-
executeQuery
public Results executeQuery(StoreQuery query)
Execute the given query on this store- Specified by:
executeQueryin interfaceStore- Overrides:
executeQueryin classAbstractStore- Parameters:
query- query to execute- Returns:
- query results
-
getInMemorySize
public int getInMemorySize()
Returns the current local in-memory store size- Specified by:
getInMemorySizein interfaceStore- Returns:
- the count of the Elements in the Store and in-memory on the local machine
-
getOffHeapSize
public int getOffHeapSize()
Returns the current local off-heap store size- Specified by:
getOffHeapSizein interfaceStore- Returns:
- the count of the Elements in the Store and off-heap on the local machine
-
getOnDiskSize
public int getOnDiskSize()
Returns the current local on-disk store size- Specified by:
getOnDiskSizein interfaceStore- Returns:
- the count of the Elements in the Store and on-disk on the local machine
-
getInMemorySizeInBytes
public long getInMemorySizeInBytes()
Gets the size of the in-memory portion of the store, in bytes.This method may be expensive to run, depending on implementation. Implementers may choose to return an approximate size.
- Specified by:
getInMemorySizeInBytesin interfaceStore- Returns:
- the approximate in-memory size of the store in bytes
-
getOffHeapSizeInBytes
public long getOffHeapSizeInBytes()
Gets the size of the off-heap portion of the store, in bytes.- Specified by:
getOffHeapSizeInBytesin interfaceStore- Returns:
- the approximate off-heap size of the store in bytes
-
getOnDiskSizeInBytes
public long getOnDiskSizeInBytes()
Gets the size of the on-disk portion of the store, in bytes.- Specified by:
getOnDiskSizeInBytesin interfaceStore- Returns:
- the on-disk size of the store in bytes
-
containsKeyOnDisk
public boolean containsKeyOnDisk(java.lang.Object key)
A check to see if a key is in the Store and is currently held on disk.- Specified by:
containsKeyOnDiskin interfaceStore- Parameters:
key- The Element key- Returns:
- true if found. No check is made to see if the Element is expired.
-
containsKeyOffHeap
public boolean containsKeyOffHeap(java.lang.Object key)
A check to see if a key is in the Store and is currently held off-heap.- Specified by:
containsKeyOffHeapin interfaceStore- Parameters:
key- The Element key- Returns:
- true if found. No check is made to see if the Element is expired.
-
containsKeyInMemory
public boolean containsKeyInMemory(java.lang.Object key)
A check to see if a key is in the Store and is currently held in memory.- Specified by:
containsKeyInMemoryin interfaceStore- Parameters:
key- The Element key- Returns:
- true if found. No check is made to see if the Element is expired.
-
getStatus
public Status getStatus()
Returns the cache status.
-
expireElements
public void expireElements()
Expire all elements.- Specified by:
expireElementsin interfaceStore
-
flush
public void flush() throws java.io.IOExceptionFlush elements to persistent store.
-
bufferFull
public boolean bufferFull()
Some store types, such as the disk stores can fill their write buffers if puts come in too fast. The thread will wait for a short time before checking again.- Specified by:
bufferFullin interfaceStore- Returns:
- true if the store write buffer is backed up.
-
getInMemoryEvictionPolicy
public Policy getInMemoryEvictionPolicy()
- Specified by:
getInMemoryEvictionPolicyin interfaceStore- Returns:
- the current eviction policy. This may not be the configured policy, if it has been dynamically set.
- See Also:
Store.setInMemoryEvictionPolicy(Policy)
-
setInMemoryEvictionPolicy
public void setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy. The Store will use a policy at startup. The store may allow changing the eviction policy strategy dynamically. Otherwise implementations will throw an exception if this method is called.- Specified by:
setInMemoryEvictionPolicyin interfaceStore- Parameters:
policy- the new policy
-
getInternalContext
public java.lang.Object getInternalContext()
This should not be used, and will generally return null- Specified by:
getInternalContextin interfaceStore- Returns:
- some internal context (probably null)
-
getMBean
public java.lang.Object getMBean()
Optional implementation specific MBean exposed by the store.
-
setNodeCoherent
public void setNodeCoherent(boolean coherent)
Sets the cache in coherent or incoherent mode for the current node depending on the parameter. CallingsetNodeCoherent(true)when the cache is already in coherent mode or callingsetNodeCoherent(false)when already in incoherent mode will be a no-op.It applies to coherent clustering mechanisms only e.g. Terracotta
- Specified by:
setNodeCoherentin interfaceStore- Overrides:
setNodeCoherentin classAbstractStore- Parameters:
coherent- true transitions to coherent mode, false to incoherent mode- See Also:
Store.setNodeCoherent(boolean)
-
isNodeCoherent
public boolean isNodeCoherent()
Returns true if the cache is in coherent mode for the current node. Returns false otherwise.It applies to coherent clustering mechanisms only e.g. Terracotta
- Specified by:
isNodeCoherentin interfaceStore- Overrides:
isNodeCoherentin classAbstractStore- Returns:
- true if the cache is in coherent mode cluster-wide, false otherwise
- See Also:
Store.isNodeCoherent()
-
isCacheCoherent
public boolean isCacheCoherent()
Indicates whether this store provides a coherent view of all the elements in a cache. Note that this is same as callingStore.isClusterCoherent()(introduced since 2.0) UseStore.isNodeCoherent()to find out if the cache is coherent in the current node in the cluster- Specified by:
isCacheCoherentin interfaceStore- Overrides:
isCacheCoherentin classAbstractStore- Returns:
trueif the store is coherent; orfalseif the store potentially splits the cache storage with another store or isn't internally coherent- See Also:
Store.isCacheCoherent()
-
isClusterCoherent
public boolean isClusterCoherent()
Returns true if the cache is in coherent mode cluster-wide. Returns false otherwise.It applies to coherent clustering mechanisms only e.g. Terracotta
- Specified by:
isClusterCoherentin interfaceStore- Overrides:
isClusterCoherentin classAbstractStore- Returns:
- true if the cache is in coherent mode cluster-wide, false otherwise
- See Also:
Store.isClusterCoherent()
-
waitUntilClusterCoherent
public void waitUntilClusterCoherent() throws TerracottaNotRunningException, java.lang.UnsupportedOperationException, java.lang.InterruptedExceptionThis method waits until the cache is in coherent mode in all the connected nodes. If the cache is already in coherent mode it returns immediatelyIt applies to coherent clustering mechanisms only e.g. Terracotta
- Specified by:
waitUntilClusterCoherentin interfaceStore- Overrides:
waitUntilClusterCoherentin classAbstractStore- Throws:
java.lang.InterruptedExceptionjava.lang.UnsupportedOperationExceptionTerracottaNotRunningException- See Also:
Store.waitUntilClusterCoherent()
-
setAttributeExtractors
public void setAttributeExtractors(java.util.Map<java.lang.String,AttributeExtractor> extractors)
Inform this store of the configured attribute extractors. Stores that will not invoke extractors are free to ignore this call- Specified by:
setAttributeExtractorsin interfaceStore- Overrides:
setAttributeExtractorsin classAbstractStore
-
getSearchAttribute
public <T> Attribute<T> getSearchAttribute(java.lang.String attributeName) throws CacheException
Retrieve the given named search attribute- Specified by:
getSearchAttributein interfaceStore- Overrides:
getSearchAttributein classAbstractStore- Type Parameters:
T- type of the attribute- Parameters:
attributeName- the name of the attribute to retrieve- Returns:
- the search attribute or null if non-existent
- Throws:
CacheException
-
getSearchAttributes
public java.util.Set<Attribute> getSearchAttributes()
- Specified by:
getSearchAttributesin interfaceStore- Overrides:
getSearchAttributesin classAbstractStore- Returns:
- all search attributes known to this store at the time of invoking the method
-
hasAbortedSizeOf
public boolean hasAbortedSizeOf()
Checks if the cache may contain elements for which the SizeOf engine gave up and only partially calculated the size.- Specified by:
hasAbortedSizeOfin interfaceStore- Overrides:
hasAbortedSizeOfin classAbstractStore- Returns:
- true if at least one partially sized element may be in the cache
-
unsafeGet
public Element unsafeGet(java.lang.Object key)
Returns the local value associated with the key. Local value means that the object mapped to the key is present in the VM locally. In case its not, will return null. Note that even when returning null, the value may be present in the Terracotta server array.This operation does not acquire any locks when doing the operation and may return stale values. This Operation does not update last usage statistics
- Specified by:
unsafeGetin interfaceTerracottaStore- Parameters:
key- the key- Returns:
- the element associated with key or null
-
getLocalKeys
public java.util.Set getLocalKeys()
Returns set of keys from the cache which are present in the node locally.- Specified by:
getLocalKeysin interfaceTerracottaStore- Returns:
- set of keys present locally in the node
-
getTransactionalMode
public CacheConfiguration.TransactionalMode getTransactionalMode()
Get the transactional mode of this store. The returned value is the String value of CacheConfiguration.TransactionalMode.- Specified by:
getTransactionalModein interfaceTerracottaStore- Returns:
- a String representation of this store's transactional mode.
- See Also:
CacheConfiguration.TransactionalMode
-
createWriteBehind
public WriteBehind createWriteBehind()
Description copied from interface:TerracottaStoreWriteBehindcreateWriteBehind- Specified by:
createWriteBehindin interfaceTerracottaStore
-
quickClear
public void quickClear()
Description copied from interface:TerracottaStoreRemove all the contents of the store.- Specified by:
quickClearin interfaceTerracottaStore
-
quickSize
public int quickSize()
Description copied from interface:TerracottaStoreGet an approximate count of elements in the store.- Specified by:
quickSizein interfaceTerracottaStore- Returns:
- an approximate count of elements in the store.
-
getOldElement
public Element getOldElement(java.lang.Object key)
Method to get to theElementmatching the key, oblivious of any in-flight transaction.- Parameters:
key- the key to look for- Returns:
- the mapped element, outside of any transaction
-
notifyCacheEventListenersChanged
public void notifyCacheEventListenersChanged()
Description copied from interface:TerracottaStoreNotify the underlying store that some change has occured in the set of registered cache listeners.- Specified by:
notifyCacheEventListenersChangedin interfaceTerracottaStore
-
-