|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.store.AbstractStore
net.sf.ehcache.store.DiskStore
public class DiskStore
A disk store implementation.
As of ehcache-1.2 (v1.41 of this file) DiskStore has been changed to a mix of finer grained locking using synchronized collections and synchronizing on the whole instance, as was the case with earlier versions. The DiskStore, as of ehcache-1.2.4, supports eviction using an LFU policy, if a maximum disk store size is set. LFU uses statistics held at the Element level which survive moving between maps in the MemoryStore and DiskStores. As of ehcache-2.0, a cache can be configured with a DiskStore with multiple stripes. This enables much higher throughput.
Nested Class Summary | |
---|---|
static class |
DiskStore.DiskElement
A reference to an on-disk elements. |
Field Summary | |
---|---|
static String |
AUTO_DISK_PATH_DIRECTORY_PREFIX
If the CacheManager needs to resolve a conflict with the disk path, it will create a subdirectory in the given disk path with this prefix followed by a number. |
Fields inherited from interface net.sf.ehcache.store.Store |
---|
CLUSTER_COHERENT, NODE_COHERENT |
Constructor Summary | |
---|---|
protected |
DiskStore(Ehcache cache,
String diskPath)
Creates a disk store. |
Method Summary | |
---|---|
boolean |
bufferFull()
In some circumstances data can be written so quickly to the spool that the VM runs out of memory while waiting for the spooling to disk. |
float |
calculateDataFileSparseness()
The design of the layout on the data file means that there will be small gaps created when DiskElements are reused. |
boolean |
containsKey(Object key)
An unsynchronized and very low cost check to see if a key is in the Store. |
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 DiskStore |
create(Ehcache cache,
String diskStorePath)
A factory method to create a DiskStore. |
protected void |
deleteFilesInAutoGeneratedDirectory()
Delete files in the auto generated directory. |
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 |
dispose()
Shuts down the disk store in preparation for cache shutdown If a VM crash happens, the shutdown hook will not run. |
void |
expireElements()
Removes expired elements. |
void |
flush()
Flush the spool if persistent, so we don't lose any data. |
static String |
generateUniqueDirectory()
Generates a unique directory name for use in automatically creating a diskStorePath where there is a conflict. |
Element |
get(Object key)
Gets an DiskStore.DiskElement from the Disk Store. |
String |
getDataFileName()
Creates a file system safe data file. |
String |
getDataFilePath()
|
long |
getDataFileSize()
|
Policy |
getEvictionPolicy()
|
String |
getIndexFileName()
|
long |
getIndexFileSize()
|
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 |
List |
getKeys()
Gets an Array of the keys for all elements in the disk store. |
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. |
Element |
getQuiet(Object key)
Gets an DiskStore.DiskElement from the Disk Store, without updating statistics |
int |
getSize()
Returns the current store size in number of Elements. |
long |
getSizeInBytes()
Gets the size of the store, in bytes. |
Status |
getStatus()
Returns the store status. |
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered |
long |
getTotalFileSize()
|
long |
getUsedDataSize()
When elements are deleted, spaces are left in the file. |
boolean |
isSpoolThreadAlive()
The spool thread is started when the disk store is created. |
static DiskStore.DiskElement |
leastHit(DiskStore.DiskElement[] sampledElements,
DiskStore.DiskElement justAdded)
Finds the least hit of the sampled elements provided |
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 |
boolean |
put(Element element)
Puts an element into the disk store. |
Element |
putIfAbsent(Element element)
Unsupported in DiskStore |
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation |
void |
registered(CacheConfiguration config)
Indicates that this listener was registered with the given configuration |
Element |
remove(Object key)
Removes an item from the disk store. |
void |
removeAll()
Remove all of the elements from the store. |
Element |
removeElement(Element element,
ElementValueComparator comparator)
Unsupported in DiskStore |
Element |
removeWithWriter(Object key,
CacheWriterManager writerManager)
Removes an item from the store and the cache writer manager in an atomic operation. |
Element |
replace(Element element)
Unsupported in DiskStore |
boolean |
replace(Element old,
Element element,
ElementValueComparator comparator)
Unsupported in DiskStore |
void |
setEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
void |
timeToIdleChanged(long oldTti,
long newTti)
Indicates a change in the configurations time to idle |
void |
timeToLiveChanged(long oldTtl,
long newTtl)
Indicates a change in the configurations time to live |
String |
toString()
Returns a String representation of the DiskStore |
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, wait, wait, wait |
Field Detail |
---|
public static final String AUTO_DISK_PATH_DIRECTORY_PREFIX
Constructor Detail |
---|
protected DiskStore(Ehcache cache, String diskPath)
cache
- the Cache
that the store is part ofdiskPath
- the directory in which to create data and index filesMethod Detail |
---|
public static DiskStore create(Ehcache cache, String diskStorePath)
cache
- diskStorePath
-
public final Element get(Object key)
DiskStore.DiskElement
from the Disk Store.
get
in interface Store
public final boolean containsKey(Object key)
containsKey
in interface Store
key
- The Element key
public final Element getQuiet(Object key)
DiskStore.DiskElement
from the Disk Store, without updating statistics
getQuiet
in interface Store
get(Object)
public final List getKeys()
getKeys
in interface Store
Serializable
keyspublic final int getSize()
getSize
in interface Store
getDataFileSize()
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize
in interface Store
public long getSizeInBytes()
public final Status getStatus()
getStatus
in interface Store
public final boolean put(Element element)
put
in interface Store
public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter
in interface Store
CacheException
public boolean bufferFull()
bufferFull
in interface Store
public final Element remove(Object key)
remove
in interface Store
public Element removeWithWriter(Object key, CacheWriterManager writerManager)
removeWithWriter
in interface Store
public final void removeAll()
CacheEventListener
s they are notified of the expiry or removal
of the Element
as each is removed.
removeAll
in interface Store
public final void dispose()
dispose
in interface Store
protected void deleteFilesInAutoGeneratedDirectory()
public final void flush()
flush
in interface Store
public void expireElements()
expireElements
in interface Store
public final String toString()
String
representation of the DiskStore
toString
in class Object
public static String generateUniqueDirectory()
AUTO_DISK_PATH_DIRECTORY_PREFIX
followed by "_" followed by the current
time as a long e.g. ehcache_auto_created_1149389837006public void timeToIdleChanged(long oldTti, long newTti)
timeToIdleChanged
in interface CacheConfigurationListener
oldTti
- previous time to idle valuenewTti
- new time to idle valuepublic void timeToLiveChanged(long oldTtl, long newTtl)
timeToLiveChanged
in interface CacheConfigurationListener
oldTtl
- previous time to live valuenewTtl
- new time to live valuepublic void diskCapacityChanged(int oldCapacity, int newCapacity)
diskCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void memoryCapacityChanged(int oldCapacity, int newCapacity)
memoryCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void loggingChanged(boolean oldValue, boolean newValue)
loggingChanged
in interface CacheConfigurationListener
oldValue
- old value whether logging was enabled or notnewValue
- new value whether logging was enabled or notpublic void registered(CacheConfiguration config)
registered
in interface CacheConfigurationListener
public void deregistered(CacheConfiguration config)
deregistered
in interface CacheConfigurationListener
public Object getMBean()
getMBean
in interface Store
public final long getTotalFileSize()
public final long getDataFileSize()
public final float calculateDataFileSparseness()
public final long getUsedDataSize()
getDataFileSize()
as a measure of fragmentation.
public final long getIndexFileSize()
public final String getDataFileName()
/
are replaced with _
so there are no unwanted side effects.
public final String getDataFilePath()
public final String getIndexFileName()
public final boolean isSpoolThreadAlive()
dispose()
method is called,
at which time it should be interrupted and then die.
public static DiskStore.DiskElement leastHit(DiskStore.DiskElement[] sampledElements, DiskStore.DiskElement justAdded)
sampledElements
- this should be a random subset of the populationjustAdded
- we never want to select the element just added. May be null.
public Policy getEvictionPolicy()
setEvictionPolicy(Policy)
public void setEvictionPolicy(Policy policy)
policy
- the new policypublic Object getInternalContext()
getInternalContext
in interface Store
public boolean containsKeyInMemory(Object key)
containsKeyInMemory
in interface Store
key
- The Element key
public boolean containsKeyOffHeap(Object key)
containsKeyOffHeap
in interface Store
key
- The Element key
public boolean containsKeyOnDisk(Object key)
containsKeyOnDisk
in interface Store
key
- The Element key
public Policy getInMemoryEvictionPolicy()
getInMemoryEvictionPolicy
in interface Store
Store.setInMemoryEvictionPolicy(Policy)
public int getInMemorySize()
getInMemorySize
in interface Store
public long getInMemorySizeInBytes()
getInMemorySizeInBytes
in interface Store
public int getOffHeapSize()
getOffHeapSize
in interface Store
public long getOffHeapSizeInBytes()
getOffHeapSizeInBytes
in interface Store
public int getOnDiskSize()
getOnDiskSize
in interface Store
public long getOnDiskSizeInBytes()
getOnDiskSizeInBytes
in interface Store
public void setInMemoryEvictionPolicy(Policy policy)
setInMemoryEvictionPolicy
in interface Store
policy
- the new policypublic Element putIfAbsent(Element element) throws NullPointerException
putIfAbsent
in interface Store
element
- element to be added
NullPointerException
- if the element is null, or has a null keypublic Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
removeElement
in interface Store
element
- Element to be removedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the element is null, or has a null keypublic boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException
replace
in interface Store
old
- Element to be test againstelement
- Element to be cachedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the either Element is null or has a null key
IllegalArgumentException
- if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
replace
in interface Store
element
- Element to be cached
NullPointerException
- if the Element is null or has a null key
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |