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
Direct Known Subclasses:
JtaLocalTransactionStore, LocalTransactionStore, XATransactionStore

public abstract class AbstractTransactionStore
extends AbstractStore

Abstract transactional store which provides implementation of all non-transactional methods

Author:
Ludovic Orban

Field Summary
protected  Store underlyingStore
          The underlying store wrapped by this store
 
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
 
Constructor Summary
protected AbstractTransactionStore(Store underlyingStore)
          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.
 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
 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.
 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 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.
 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, fireClusterCoherent, fireNodeCoherent, getEventListenerList, 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
containsKey, get, getKeys, getQuiet, getSize, getTerracottaClusteredSize, put, putIfAbsent, putWithWriter, remove, removeAll, removeElement, 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

getInMemorySize

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

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

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

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.

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.

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.

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.

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.

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.

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.


getStatus

public Status getStatus()
Returns the cache status.


expireElements

public void expireElements()
Expire all elements.


flush

public void flush()
           throws IOException
Flush elements to persistent 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.

Returns:
true if the store write buffer is backed up.

getInMemoryEvictionPolicy

public Policy getInMemoryEvictionPolicy()

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.

Parameters:
policy - the new policy

getInternalContext

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

Returns:
some internal context (probably null)

getMBean

public Object getMBean()
Optional implementation specific MBean exposed by the 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()
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
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

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

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

ehcache

true