org.terracotta.modules.ehcache.store
Class ClusteredStore

java.lang.Object
  extended by org.terracotta.modules.ehcache.store.ClusteredStore
All Implemented Interfaces:
net.sf.ehcache.config.CacheConfigurationListener, net.sf.ehcache.store.Store, net.sf.ehcache.store.TerracottaStore, ConfigChangeListener

public class ClusteredStore
extends Object
implements net.sf.ehcache.store.TerracottaStore, net.sf.ehcache.config.CacheConfigurationListener, ConfigChangeListener


Field Summary
protected  net.sf.ehcache.Ehcache cache
          The cache this store is associated with.
 
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
 
Constructor Summary
ClusteredStore(net.sf.ehcache.Ehcache cache)
           
 
Method Summary
 void addStoreListener(net.sf.ehcache.store.StoreListener listener)
           
 boolean bufferFull()
          Memory stores are never backed up and always return false
protected  void clear()
           
 void configChanged(String cacheName, String configName, Object oldValue, Object newValue)
           
 boolean containsKey(Object key)
           
 boolean containsKeyInMemory(Object key)
           
 boolean containsKeyOnDisk(Object key)
           
 void deregistered(net.sf.ehcache.config.CacheConfiguration config)
           
protected static net.sf.ehcache.store.Policy determineEvictionPolicy(net.sf.ehcache.Ehcache cache)
          Chooses the Policy from the cache configuration
 void diskCapacityChanged(int oldCapacity, int newCapacity)
           
 void dispose()
           
 void expireElements()
          Expire all elements.
 void fireClusterCoherent(boolean clusterCoherent)
           
 void fireNodeCoherent(boolean nodeCoherent)
           
 void flush()
           
 Object generatePortableKeyFor(Object obj)
          Generates a portable key for the supplied object.
 net.sf.ehcache.Element get(Object key)
           
 net.sf.ehcache.store.Policy getInMemoryEvictionPolicy()
           
 int getInMemorySize()
           
 long getInMemorySizeInBytes()
           
 Object getInternalContext()
           
 Object[] getKeyArray()
           This might return duplicate keys when in incoherent mode
 int getOnDiskSize()
           
 long getOnDiskSizeInBytes()
           
 net.sf.ehcache.Element getQuiet(Object key)
           
 int getSize()
           
 net.sf.ehcache.Status getStatus()
           
 int getTerracottaClusteredSize()
           
 void initalizeTransients(net.sf.ehcache.Ehcache ehcache)
          This method is used for common on-load and instantiation logic.
 boolean isCacheCoherent()
          
 boolean isClusterCoherent()
          
 boolean isNodeCoherent()
          returns true if the cache is coherent locally, or false otherwise This does not consider the state of the other nodes.
 void loggingChanged(boolean oldValue, boolean newValue)
           
 void memoryCapacityChanged(int oldCapacity, int newCapacity)
           
 boolean put(net.sf.ehcache.Element element)
           
 net.sf.ehcache.Element putIfAbsent(net.sf.ehcache.Element element)
           
 boolean putWithWriter(net.sf.ehcache.Element element, net.sf.ehcache.writer.CacheWriterManager writerManager)
           
 void registered(net.sf.ehcache.config.CacheConfiguration config)
           
 net.sf.ehcache.Element remove(Object key)
           
 void removeAll()
           
 net.sf.ehcache.Element removeElement(net.sf.ehcache.Element element)
           
protected  net.sf.ehcache.Element removeFromBackend(Object key)
           
 void removeStoreListener(net.sf.ehcache.store.StoreListener listener)
           
 net.sf.ehcache.Element removeWithWriter(Object key, net.sf.ehcache.writer.CacheWriterManager writerManager)
           
 net.sf.ehcache.Element replace(net.sf.ehcache.Element element)
           
 boolean replace(net.sf.ehcache.Element old, net.sf.ehcache.Element element)
           
 void setInMemoryEvictionPolicy(net.sf.ehcache.store.Policy policy)
           
 void setNodeCoherent(boolean coherent)
           
 void timeToIdleChanged(long oldTti, long newTti)
           
 void timeToLiveChanged(long oldTtl, long newTtl)
           
 net.sf.ehcache.Element unlockedGet(Object key)
           
 net.sf.ehcache.Element unlockedGetQuiet(Object key)
           
 net.sf.ehcache.Element unsafeGet(Object key)
           
 net.sf.ehcache.Element unsafeGetQuiet(Object key)
           
 void waitUntilClusterCoherent()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected net.sf.ehcache.Ehcache cache
The cache this store is associated with.

Constructor Detail

ClusteredStore

public ClusteredStore(net.sf.ehcache.Ehcache cache)
Method Detail

initalizeTransients

public void initalizeTransients(net.sf.ehcache.Ehcache ehcache)
This method is used for common on-load and instantiation logic. We can't rely on the standard DSO on-load feature since roots of ClusteredStore are explicitly created in TerracottaClusteredInstanceFactory through ManagerUtil call, as opposed to the regular root declaration in DSO instrumented classes.

This approach is needed for 'express' features since none of the application context classes can be instrumented by Terracotta due to the lack of a boot jar.


put

public boolean put(net.sf.ehcache.Element element)
            throws net.sf.ehcache.CacheException
Specified by:
put in interface net.sf.ehcache.store.Store
Throws:
net.sf.ehcache.CacheException

putWithWriter

public boolean putWithWriter(net.sf.ehcache.Element element,
                             net.sf.ehcache.writer.CacheWriterManager writerManager)
                      throws net.sf.ehcache.CacheException
Specified by:
putWithWriter in interface net.sf.ehcache.store.Store
Throws:
net.sf.ehcache.CacheException

get

public net.sf.ehcache.Element get(Object key)
Specified by:
get in interface net.sf.ehcache.store.Store

getQuiet

public net.sf.ehcache.Element getQuiet(Object key)
Specified by:
getQuiet in interface net.sf.ehcache.store.Store

unlockedGet

public net.sf.ehcache.Element unlockedGet(Object key)
Specified by:
unlockedGet in interface net.sf.ehcache.store.TerracottaStore

unlockedGetQuiet

public net.sf.ehcache.Element unlockedGetQuiet(Object key)
Specified by:
unlockedGetQuiet in interface net.sf.ehcache.store.TerracottaStore

unsafeGet

public net.sf.ehcache.Element unsafeGet(Object key)
Specified by:
unsafeGet in interface net.sf.ehcache.store.TerracottaStore

unsafeGetQuiet

public net.sf.ehcache.Element unsafeGetQuiet(Object key)
Specified by:
unsafeGetQuiet in interface net.sf.ehcache.store.TerracottaStore

remove

public net.sf.ehcache.Element remove(Object key)
Specified by:
remove in interface net.sf.ehcache.store.Store

removeWithWriter

public net.sf.ehcache.Element removeWithWriter(Object key,
                                               net.sf.ehcache.writer.CacheWriterManager writerManager)
                                        throws net.sf.ehcache.CacheException
Specified by:
removeWithWriter in interface net.sf.ehcache.store.Store
Throws:
net.sf.ehcache.CacheException

removeFromBackend

protected net.sf.ehcache.Element removeFromBackend(Object key)

bufferFull

public final boolean bufferFull()
Memory stores are never backed up and always return false

Specified by:
bufferFull in interface net.sf.ehcache.store.Store

expireElements

public final void expireElements()
Expire all elements.

This is a default implementation which does nothing. Expiration on demand is only implemented for disk stores.

Specified by:
expireElements in interface net.sf.ehcache.store.Store

determineEvictionPolicy

protected static final net.sf.ehcache.store.Policy determineEvictionPolicy(net.sf.ehcache.Ehcache cache)
Chooses the Policy from the cache configuration

Parameters:
cache -

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface net.sf.ehcache.store.Store

containsKeyInMemory

public boolean containsKeyInMemory(Object key)
Specified by:
containsKeyInMemory in interface net.sf.ehcache.store.Store

containsKeyOnDisk

public boolean containsKeyOnDisk(Object key)
Specified by:
containsKeyOnDisk in interface net.sf.ehcache.store.Store

getSize

public int getSize()
Specified by:
getSize in interface net.sf.ehcache.store.Store

getInMemorySize

public int getInMemorySize()
Specified by:
getInMemorySize in interface net.sf.ehcache.store.Store

getInMemorySizeInBytes

public long getInMemorySizeInBytes()
Specified by:
getInMemorySizeInBytes in interface net.sf.ehcache.store.Store

getOnDiskSize

public int getOnDiskSize()
Specified by:
getOnDiskSize in interface net.sf.ehcache.store.Store

getOnDiskSizeInBytes

public long getOnDiskSizeInBytes()
Specified by:
getOnDiskSizeInBytes in interface net.sf.ehcache.store.Store

getTerracottaClusteredSize

public int getTerracottaClusteredSize()
Specified by:
getTerracottaClusteredSize in interface net.sf.ehcache.store.Store

removeAll

public void removeAll()
               throws net.sf.ehcache.CacheException
Specified by:
removeAll in interface net.sf.ehcache.store.Store
Throws:
net.sf.ehcache.CacheException

getStatus

public net.sf.ehcache.Status getStatus()
Specified by:
getStatus in interface net.sf.ehcache.store.Store

clear

protected final void clear()

flush

public void flush()
Specified by:
flush in interface net.sf.ehcache.store.Store

dispose

public void dispose()
Specified by:
dispose in interface net.sf.ehcache.store.Store

getKeyArray

public Object[] getKeyArray()
This might return duplicate keys when in incoherent mode

Specified by:
getKeyArray in interface net.sf.ehcache.store.Store

generatePortableKeyFor

public Object generatePortableKeyFor(Object obj)
Generates a portable key for the supplied object.


getInMemoryEvictionPolicy

public net.sf.ehcache.store.Policy getInMemoryEvictionPolicy()
Specified by:
getInMemoryEvictionPolicy in interface net.sf.ehcache.store.Store

setInMemoryEvictionPolicy

public void setInMemoryEvictionPolicy(net.sf.ehcache.store.Policy policy)
Specified by:
setInMemoryEvictionPolicy in interface net.sf.ehcache.store.Store

getInternalContext

public Object getInternalContext()
Specified by:
getInternalContext in interface net.sf.ehcache.store.Store

isCacheCoherent

public boolean isCacheCoherent()

Specified by:
isCacheCoherent in interface net.sf.ehcache.store.Store

isClusterCoherent

public boolean isClusterCoherent()

Specified by:
isClusterCoherent in interface net.sf.ehcache.store.Store

isNodeCoherent

public boolean isNodeCoherent()
returns true if the cache is coherent locally, or false otherwise This does not consider the state of the other nodes.

Specified by:
isNodeCoherent in interface net.sf.ehcache.store.Store

timeToIdleChanged

public void timeToIdleChanged(long oldTti,
                              long newTti)
Specified by:
timeToIdleChanged in interface net.sf.ehcache.config.CacheConfigurationListener

timeToLiveChanged

public void timeToLiveChanged(long oldTtl,
                              long newTtl)
Specified by:
timeToLiveChanged in interface net.sf.ehcache.config.CacheConfigurationListener

diskCapacityChanged

public void diskCapacityChanged(int oldCapacity,
                                int newCapacity)
Specified by:
diskCapacityChanged in interface net.sf.ehcache.config.CacheConfigurationListener

memoryCapacityChanged

public void memoryCapacityChanged(int oldCapacity,
                                  int newCapacity)
Specified by:
memoryCapacityChanged in interface net.sf.ehcache.config.CacheConfigurationListener

loggingChanged

public void loggingChanged(boolean oldValue,
                           boolean newValue)
Specified by:
loggingChanged in interface net.sf.ehcache.config.CacheConfigurationListener

registered

public void registered(net.sf.ehcache.config.CacheConfiguration config)
Specified by:
registered in interface net.sf.ehcache.config.CacheConfigurationListener

deregistered

public void deregistered(net.sf.ehcache.config.CacheConfiguration config)
Specified by:
deregistered in interface net.sf.ehcache.config.CacheConfigurationListener

configChanged

public void configChanged(String cacheName,
                          String configName,
                          Object oldValue,
                          Object newValue)
Specified by:
configChanged in interface ConfigChangeListener

setNodeCoherent

public void setNodeCoherent(boolean coherent)
Specified by:
setNodeCoherent in interface net.sf.ehcache.store.Store

waitUntilClusterCoherent

public void waitUntilClusterCoherent()
Specified by:
waitUntilClusterCoherent in interface net.sf.ehcache.store.Store

addStoreListener

public void addStoreListener(net.sf.ehcache.store.StoreListener listener)
Specified by:
addStoreListener in interface net.sf.ehcache.store.Store

removeStoreListener

public void removeStoreListener(net.sf.ehcache.store.StoreListener listener)
Specified by:
removeStoreListener in interface net.sf.ehcache.store.Store

fireNodeCoherent

public void fireNodeCoherent(boolean nodeCoherent)

fireClusterCoherent

public void fireClusterCoherent(boolean clusterCoherent)

putIfAbsent

public net.sf.ehcache.Element putIfAbsent(net.sf.ehcache.Element element)
                                   throws NullPointerException
Specified by:
putIfAbsent in interface net.sf.ehcache.store.Store
Throws:
NullPointerException

removeElement

public net.sf.ehcache.Element removeElement(net.sf.ehcache.Element element)
                                     throws NullPointerException
Specified by:
removeElement in interface net.sf.ehcache.store.Store
Throws:
NullPointerException

replace

public boolean replace(net.sf.ehcache.Element old,
                       net.sf.ehcache.Element element)
                throws NullPointerException,
                       IllegalArgumentException
Specified by:
replace in interface net.sf.ehcache.store.Store
Throws:
NullPointerException
IllegalArgumentException

replace

public net.sf.ehcache.Element replace(net.sf.ehcache.Element element)
                               throws NullPointerException
Specified by:
replace in interface net.sf.ehcache.store.Store
Throws:
NullPointerException


Copyright © 2010 Terracotta, Inc.. All Rights Reserved.