ehcache

net.sf.ehcache.store.compound.impl
Class DiskPersistentStore

java.lang.Object
  extended by net.sf.ehcache.store.AbstractStore
      extended by net.sf.ehcache.store.compound.CompoundStore
          extended by net.sf.ehcache.store.compound.impl.DiskPersistentStore
All Implemented Interfaces:
CacheConfigurationListener, Store

public final class DiskPersistentStore
extends CompoundStore
implements CacheConfigurationListener

Implements a persistent-to-disk store.

All new elements are automatically scheduled for writing to disk. In addition the store will cache Elements in memory up to the in-memory capacity.

Author:
Chris Dennis

Field Summary
 
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
 
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.
static DiskPersistentStore create(Cache cache, String diskStorePath)
          Creates a persitent-to-disk store for the given cache, using the given disk path.
 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 expireElements()
          Expire all elements.
 void flush()
          Flush elements to persistent store.
 File getDataFile()
          Return a reference to the data file backing this store.
 File getIndexFile()
          Return a reference to the index file for this 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 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.
 int getTerracottaClusteredSize()
          Returns the current Terracotta clustered store size
 void loggingChanged(boolean oldValue, boolean newValue)
          Indicates a change in the configuration for enable/disable logging
 void memoryCapacityChanged(int oldCapacity, int newCapacity)
          Indicates a change in the configurations memory store capacity
 void registered(CacheConfiguration config)
          Indicates that this listener was registered with the given configuration
 void setInMemoryEvictionPolicy(Policy policy)
          Sets the eviction policy strategy.
 void timeToIdleChanged(long oldTimeToIdle, long newTimeToIdle)
          Indicates a change in the configurations time to idle
 void timeToLiveChanged(long oldTimeToLive, long newTimeToLive)
          Indicates a change in the configurations time to live
 
Methods inherited from class net.sf.ehcache.store.compound.CompoundStore
containsKey, dispose, elementSet, evict, fault, get, getInternalContext, getKeys, getQuiet, getRandomSample, getSize, getStatus, keySet, put, putIfAbsent, putRawIfAbsent, putWithWriter, remove, removeAll, removeElement, removeWithWriter, replace, replace, tryFault, unretrievedGet
 
Methods inherited from class net.sf.ehcache.store.AbstractStore
addStoreListener, executeQuery, getEventListenerList, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static DiskPersistentStore create(Cache cache,
                                         String diskStorePath)
Creates a persitent-to-disk store for the given cache, using the given disk path.

Parameters:
cache - cache that fronts this store
diskStorePath - disk path to store data in
Returns:
a fully initialized 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:
bufferFull in interface Store
Returns:
true if the store write buffer is backed up.

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.

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.

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.

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

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)

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

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

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

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

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

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

getTerracottaClusteredSize

public int getTerracottaClusteredSize()
Returns the current Terracotta clustered store size

Specified by:
getTerracottaClusteredSize in interface Store
Returns:
the count of the Elements in the Store across the cluster

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

deregistered

public void deregistered(CacheConfiguration config)
Indicates that this listener was removed from the given configuration

A NO-OP

Specified by:
deregistered in interface CacheConfigurationListener

diskCapacityChanged

public void diskCapacityChanged(int oldCapacity,
                                int newCapacity)
Indicates a change in the configurations disk store capacity

Specified by:
diskCapacityChanged in interface CacheConfigurationListener
Parameters:
oldCapacity - previous capacity
newCapacity - new capacity

loggingChanged

public void loggingChanged(boolean oldValue,
                           boolean newValue)
Indicates a change in the configuration for enable/disable logging

A NO-OP

Specified by:
loggingChanged in interface CacheConfigurationListener
Parameters:
oldValue - old value whether logging was enabled or not
newValue - new value whether logging was enabled or not

memoryCapacityChanged

public void memoryCapacityChanged(int oldCapacity,
                                  int newCapacity)
Indicates a change in the configurations memory store capacity

Specified by:
memoryCapacityChanged in interface CacheConfigurationListener
Parameters:
oldCapacity - previous capacity
newCapacity - new capacity

registered

public void registered(CacheConfiguration config)
Indicates that this listener was registered with the given configuration

A NO-OP

Specified by:
registered in interface CacheConfigurationListener

timeToIdleChanged

public void timeToIdleChanged(long oldTimeToIdle,
                              long newTimeToIdle)
Indicates a change in the configurations time to idle

A NO-OP

Specified by:
timeToIdleChanged in interface CacheConfigurationListener
Parameters:
oldTimeToIdle - previous time to idle value
newTimeToIdle - new time to idle value

timeToLiveChanged

public void timeToLiveChanged(long oldTimeToLive,
                              long newTimeToLive)
Indicates a change in the configurations time to live

A NO-OP

Specified by:
timeToLiveChanged in interface CacheConfigurationListener
Parameters:
oldTimeToLive - previous time to live value
newTimeToLive - new time to live value

getDataFile

public File getDataFile()
Return a reference to the data file backing this store.


getIndexFile

public File getIndexFile()
Return a reference to the index file for this store.


getMBean

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

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

ehcache

true