ehcache

net.sf.ehcache.transaction
Class AbstractTransactionStore

java.lang.Object
  extended by net.sf.ehcache.store.AbstractStore
      extended by 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
protected  ReadWriteCopyStrategy<Element> copyStrategy
          The copy strategy for this store
protected  Store underlyingStore
          The underlying store wrapped by this store
 
Fields inherited from class net.sf.ehcache.store.AbstractStore
attributeExtractors
 
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
 
Constructor Summary
protected AbstractTransactionStore(Store underlyingStore, ReadWriteCopyStrategy<Element> copyStrategy)
          Constructor
 
Method Summary
 boolean bufferFull()
          Some store types, such as the disk stores can fill their write buffers if puts come in too fast.
 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.
protected  Element copyElementForRead(Element element)
          Copy element for read operation
protected  Element copyElementForWrite(Element element)
          Copy element for write operation
 WriteBehind createWriteBehind()
          WriteBehind createWriteBehind
 void dispose()
          Prepares for shutdown.
 Results executeQuery(StoreQuery query)
          Execute the given query on this store
 void expireElements()
          Expire all elements.
 void flush()
          Flush elements to persistent store.
 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
 Set getLocalKeys()
          Returns set of keys from the cache which are present in the node locally.
 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.
<T> Attribute<T>
getSearchAttribute(String attributeName)
          Retrieve the given named search attribute
 Status getStatus()
          Returns the cache status.
 CacheConfiguration.TransactionalMode getTransactionalMode()
          Get the transactional mode of this store.
 boolean hasAbortedSizeOf()
          Checks if the cache may contain elements for which the SizeOf engine gave up and only partially calculated the size.
 boolean isCacheCoherent()
          Indicates whether this store provides a coherent view of all the elements in a cache.
 boolean isClusterCoherent()
          Returns true if the cache is in coherent mode cluster-wide.
 boolean isNodeCoherent()
          Returns true if the cache is in coherent mode for the current node.
 void notifyCacheEventListenersChanged()
          Notify the underlying store that some change has occured in the set of registered cache listeners.
 void setAttributeExtractors(Map<String,AttributeExtractor> extractors)
          Inform this store of the configured attribute extractors.
 void setInMemoryEvictionPolicy(Policy policy)
          Sets the eviction policy strategy.
 void setNodeCoherent(boolean coherent)
          Sets the cache in coherent or incoherent mode for the current node depending on the parameter.
 Element unsafeGet(Object key)
          Returns the local value associated with the key.
 void waitUntilClusterCoherent()
          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


copyStrategy

protected final ReadWriteCopyStrategy<Element> copyStrategy
The copy strategy for this store

Constructor Detail

AbstractTransactionStore

protected AbstractTransactionStore(Store underlyingStore,
                                   ReadWriteCopyStrategy<Element> copyStrategy)
Constructor

Parameters:
underlyingStore - the underlying store
Method Detail

copyElementForRead

protected Element copyElementForRead(Element element)
Copy element for read operation

Parameters:
element -
Returns:
copied element

copyElementForWrite

protected Element copyElementForWrite(Element element)
Copy element for write operation

Parameters:
element -
Returns:
copied element

executeQuery

public Results executeQuery(StoreQuery query)
Execute the given query on this store

Specified by:
executeQuery in interface Store
Overrides:
executeQuery in class AbstractStore
Parameters:
query - query to execute
Returns:
query results

getInMemorySize

public int getInMemorySize()
Returns the current local in-memory store size

Specified by:
getInMemorySize in interface Store
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:
getOffHeapSize in interface Store
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:
getOnDiskSize in interface Store
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:
getInMemorySizeInBytes in interface Store
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:
getOffHeapSizeInBytes in interface Store
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:
getOnDiskSizeInBytes in interface Store
Returns:
the on-disk size of the store in bytes

containsKeyOnDisk

public boolean containsKeyOnDisk(Object key)
A check to see if a key is in the Store and is currently held on disk.

Specified by:
containsKeyOnDisk in interface Store
Parameters:
key - The Element key
Returns:
true if found. No check is made to see if the Element is expired.

containsKeyOffHeap

public boolean containsKeyOffHeap(Object key)
A check to see if a key is in the Store and is currently held off-heap.

Specified by:
containsKeyOffHeap in interface Store
Parameters:
key - The Element key
Returns:
true if found. No check is made to see if the Element is expired.

containsKeyInMemory

public boolean containsKeyInMemory(Object key)
A check to see if a key is in the Store and is currently held in memory.

Specified by:
containsKeyInMemory in interface Store
Parameters:
key - The Element key
Returns:
true if found. No check is made to see if the Element is expired.

dispose

public void dispose()
Prepares for shutdown.

Specified by:
dispose in interface Store

getStatus

public Status getStatus()
Returns the cache status.

Specified by:
getStatus in interface Store

expireElements

public void expireElements()
Expire all elements.

Specified by:
expireElements in interface Store

flush

public void flush()
           throws IOException
Flush elements to persistent store.

Specified by:
flush in interface Store
Throws:
IOException - if any IO error occurs

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:
bufferFull in interface Store
Returns:
true if the store write buffer is backed up.

getInMemoryEvictionPolicy

public Policy getInMemoryEvictionPolicy()

Specified by:
getInMemoryEvictionPolicy in interface Store
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:
setInMemoryEvictionPolicy in interface Store
Parameters:
policy - the new policy

getInternalContext

public Object getInternalContext()
This should not be used, and will generally return null

Specified by:
getInternalContext in interface Store
Returns:
some internal context (probably null)

getMBean

public Object getMBean()
Optional implementation specific MBean exposed by the store.

Specified by:
getMBean in interface Store
Returns:
implementation specific management bean

setNodeCoherent

public void setNodeCoherent(boolean coherent)
Sets the cache in coherent or incoherent mode for the current node depending on the parameter. Calling setNodeCoherent(true) when the cache is already in coherent mode or calling setNodeCoherent(false) when already in incoherent mode will be a no-op.

It applies to coherent clustering mechanisms only e.g. Terracotta

Specified by:
setNodeCoherent in interface Store
Overrides:
setNodeCoherent in class AbstractStore
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:
isNodeCoherent in interface Store
Overrides:
isNodeCoherent in class AbstractStore
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 calling Store.isClusterCoherent() (introduced since 2.0) Use Store.isNodeCoherent() to find out if the cache is coherent in the current node in the cluster

Specified by:
isCacheCoherent in interface Store
Overrides:
isCacheCoherent in class AbstractStore
Returns:
true if the store is coherent; or false if 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:
isClusterCoherent in interface Store
Overrides:
isClusterCoherent in class AbstractStore
Returns:
true if the cache is in coherent mode cluster-wide, false otherwise
See Also:
Store.isClusterCoherent()

waitUntilClusterCoherent

public void waitUntilClusterCoherent()
                              throws TerracottaNotRunningException,
                                     UnsupportedOperationException,
                                     InterruptedException
This method waits until the cache is in coherent mode in all the connected nodes. If the cache is already in coherent mode it returns immediately

It applies to coherent clustering mechanisms only e.g. Terracotta

Specified by:
waitUntilClusterCoherent in interface Store
Overrides:
waitUntilClusterCoherent in class AbstractStore
Throws:
InterruptedException
UnsupportedOperationException
TerracottaNotRunningException
See Also:
Store.waitUntilClusterCoherent()

setAttributeExtractors

public void setAttributeExtractors(Map<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:
setAttributeExtractors in interface Store
Overrides:
setAttributeExtractors in class AbstractStore

getSearchAttribute

public <T> Attribute<T> getSearchAttribute(String attributeName)
                                throws CacheException
Retrieve the given named search attribute

Specified by:
getSearchAttribute in interface Store
Overrides:
getSearchAttribute in class AbstractStore
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

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:
hasAbortedSizeOf in interface Store
Overrides:
hasAbortedSizeOf in class AbstractStore
Returns:
true if at least one partially sized element may be in the cache

unsafeGet

public Element unsafeGet(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:
unsafeGet in interface TerracottaStore
Parameters:
key - the key
Returns:
the element associated with key or null

getLocalKeys

public Set getLocalKeys()
Returns set of keys from the cache which are present in the node locally.

Specified by:
getLocalKeys in interface TerracottaStore
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:
getTransactionalMode in interface TerracottaStore
Returns:
a String representation of this store's transactional mode.
See Also:
CacheConfiguration.TransactionalMode

createWriteBehind

public WriteBehind createWriteBehind()
Description copied from interface: TerracottaStore
WriteBehind createWriteBehind

Specified by:
createWriteBehind in interface TerracottaStore

notifyCacheEventListenersChanged

public void notifyCacheEventListenersChanged()
Description copied from interface: TerracottaStore
Notify the underlying store that some change has occured in the set of registered cache listeners.

Specified by:
notifyCacheEventListenersChanged in interface TerracottaStore

ehcache

Copyright 2001-2014, Terracotta, Inc.