Top Description Inners Fields Constructors Methods
net.sf.ehcache.store.disk

public final Class DiskStore

extends AbstractStore
implements StripedReadWriteLockProvider, AuthoritativeTier
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.AuthoritativeTier, net.sf.ehcache.store.Store, net.sf.ehcache.store.StripedReadWriteLockProvider
Imports
net.sf.ehcache.Cache, .CacheEntry, .CacheException, .CacheOperationOutcomes.EvictionOutcome, .Ehcache, .Element, .Status, net.sf.ehcache.concurrent.CacheLockProvider, .LockType, .StripedReadWriteLock, .Sync, net.sf.ehcache.config.CacheConfiguration, .CacheConfigurationListener, .SizeOfPolicyConfiguration, net.sf.ehcache.pool.Pool, .PoolAccessor, .PoolParticipant, net.sf.ehcache.pool.impl.UnboundedPool, net.sf.ehcache.store.AbstractStore, .AuthoritativeTier, .CacheStore, .ElementValueComparator, .Policy, .Store, .StoreOperationOutcomes.GetOutcome, .StoreOperationOutcomes.PutOutcome, .StoreOperationOutcomes.RemoveOutcome, .StripedReadWriteLockProvider, net.sf.ehcache.store.cachingtier.OnHeapCachingTier, net.sf.ehcache.store.disk.DiskStorageFactory.DiskMarker, .DiskStorageFactory.DiskSubstitute, .DiskStorageFactory.Placeholder, net.sf.ehcache.writer.CacheWriterManager, org.terracotta.statistics.OperationStatistic, .Statistic, .StatisticsManager, org.terracotta.statistics.derived.EventRateSimpleMovingAverage, .OperationResultFilter, org.terracotta.statistics.observer.OperationObserver, java.io.File, .IOException, java.util.AbstractSet, .ArrayList, .Collection, .Collections, .EnumSet, .Iterator, .List, .Random, .Set, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicReference, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock

Implements a persistent-to-disk store.

All new elements are automatically scheduled for writing to disk.

Authors
Chris Dennis, Ludovic Orban

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class
DiskStore.DiskStoreDiskPoolParticipant

PoolParticipant that is used with the DiskPool.

private class
DiskStore.DiskStoreHeapPoolParticipant

PoolParticipant that is used with the HeapPool.

private abstract class
DiskStore.DiskStorePoolParticipant

PoolParticipant that encapsulate shared logic for both DiskStorePoolParticipant

private class
DiskStore.DiskStoreStripedReadWriteLock

StripedReadWriteLock impl.

pack-priv abstract class
DiskStore.HashIterator

Superclass for all store iterators.

private class
DiskStore.KeyIterator

Iterator over the store key set.

pack-priv class
DiskStore.KeySet

Key set implementation for the DiskStore

private class
DiskStore.LockProvider

LockProvider implementation that uses the segment locks.

private static class
DiskStore.ReadWriteLockSync

Sync implementation that wraps the segment locks

Field Summary

Modifier and TypeField and Description
private static final int
private static final float
private static final int
private final DiskStorageFactory
private final OperationObserver<CacheOperationOutcomes.EvictionOutcome>
private static final int
private static final int
private static final int
private final OperationObserver<StoreOperationOutcomes.GetOutcome>
private volatile Set<Object>
private volatile CacheLockProvider
private final PoolAccessor<T extends PoolParticipant>
private final PoolAccessor<T extends PoolParticipant>
private final OperationObserver<StoreOperationOutcomes.PutOutcome>
private final OperationObserver<StoreOperationOutcomes.RemoveOutcome>
private static final int
private final Random
private final Segment[]
private final int
private static final int
private static final int
private final AtomicReference<Status>
private static final int
private static final int
Inherited from net.sf.ehcache.store.AbstractStore:
attributeExtractorssearchManager

Constructor Summary

AccessConstructor and Description
private
DiskStore(DiskStorageFactory disk, Ehcache cache, Pool onHeapPool, Pool onDiskPool)

Method Summary

Modifier and TypeMethod and Description
public boolean
bufferFull()

Implements net.sf.ehcache.store.Store.bufferFull.

Some store types, such as the disk stores can fill their write buffers if puts come in too fast.
public void
changeDiskCapacity(int
the new max elements on disk
newCapacity
)

Change the disk capacity, in number of elements

public void
clearFaultedBit()

Marks all entries has flushed (i.e. not faulted)

public boolean
containsKey(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKey.

A check to see if a key is in the Store.
public boolean
containsKeyInMemory(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKeyInMemory.

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

Implements net.sf.ehcache.store.Store.containsKeyOffHeap.

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

Implements net.sf.ehcache.store.Store.containsKeyOnDisk.

A check to see if a key is in the Store and is currently held on disk.
public static DiskStore

Returns:

a fully initialized store
create
(Ehcache
cache that fronts this store
cache
,
Pool
pool to track heap usage
onHeapPool
,
Pool
pool to track disk usage
onDiskPool
)

Creates a persitent-to-disk store for the given cache, using the given disk path.

public static DiskStore

Returns:

a fully initialized store
create
(Cache
cache that fronts this store
cache
)

Creates a persitent-to-disk store for the given cache, using the given disk path.

public static Store

Returns:

a DiskBackedMemoryStore instance
createCacheStore
(Ehcache
the cache
cache
,
Pool
the pool tracking on-heap usage
onHeapPool
,
Pool
the pool tracking on-disk usage
onDiskPool
)

Create a DiskBackedMemoryStore instance

public StripedReadWriteLock
createStripedReadWriteLock()

Implements net.sf.ehcache.store.StripedReadWriteLockProvider.createStripedReadWriteLock.

Will create a StripedReadWriteLock always using the same spreading function
public void
dispose()

Implements net.sf.ehcache.store.Store.dispose.

Prepares for shutdown.
public boolean

Returns:

true on a successful remove
evict
(Object
key to match against
key
,
DiskStorageFactory.DiskSubstitute
optional value to match against
substitute
)

Remove the matching mapping.

public Element

Returns:

the evicted element on a successful remove
evictElement
(Object
key to match against
key
,
DiskStorageFactory.DiskSubstitute
optional value to match against
substitute
)

Remove the matching mapping.

public void
public Element
fault(final Object key, final boolean updateStats)

Implements net.sf.ehcache.store.AuthoritativeTier.fault.

Marks the entry as not evictable and returns it atomically
public boolean

Returns:

true if fault was installed
fault
(Object
key to which this element (proxy) is mapped
key
,
DiskStorageFactory.Placeholder
element (proxy) expected
expect
,
DiskStorageFactory.DiskMarker
element (proxy) to install
fault
)

Atomically switch (CAS) the expect representation of this element for the fault representation.

public void
flush(final Element element)

Implements net.sf.ehcache.store.AuthoritativeTier.flush.

This marks the entry as evictable again and updates relevant access stats
public void
flush()

Implements net.sf.ehcache.store.Store.flush.

Flush elements to persistent store.
public Element
get(Object key)

Implements net.sf.ehcache.store.Store.get.

Gets an item from the cache.
public File

Returns:

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

Return a reference to the data file backing this store.

public File

Returns:

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

Return a reference to the index file for this store.

public Policy
public int
getInMemorySize()

Implements net.sf.ehcache.store.Store.getInMemorySize.

Returns the current local in-memory store size
public long
getInMemorySizeInBytes()

Implements net.sf.ehcache.store.Store.getInMemorySizeInBytes.

Gets the size of the in-memory portion of the store, in bytes.
public Object
getInternalContext()

Implements net.sf.ehcache.store.Store.getInternalContext.

This should not be used, and will generally return null
public List<E>
getKeys()

Implements net.sf.ehcache.store.Store.getKeys.

Gets an Array of the keys for all elements in the disk store.
public Object
getMBean()

Implements net.sf.ehcache.store.Store.getMBean.

Optional implementation specific MBean exposed by the store.
public int
getOffHeapSize()

Implements net.sf.ehcache.store.Store.getOffHeapSize.

Returns the current local off-heap store size
public long
getOffHeapSizeInBytes()

Implements net.sf.ehcache.store.Store.getOffHeapSizeInBytes.

Gets the size of the off-heap portion of the store, in bytes.
public int
getOnDiskSize()

Implements net.sf.ehcache.store.Store.getOnDiskSize.

Returns the current local on-disk store size
public long
getOnDiskSizeInBytes()

Implements net.sf.ehcache.store.Store.getOnDiskSizeInBytes.

Gets the size of the on-disk portion of the store, in bytes.
public Element
getQuiet(Object key)

Implements net.sf.ehcache.store.Store.getQuiet.

Gets an Element from the Store, without updating statistics
public List<DiskStorageFactory.DiskSubstitute>

Returns:

list of sampled elements/element substitute
getRandomSample
(ElementSubstituteFilter
generator of the given type
factory
,
int
minimum number of elements to return
sampleSize
,
Object
a key on which we are currently working
keyHint
)

Select a random sample of elements generated by the supplied factory.

public int
getSize()

Implements net.sf.ehcache.store.Store.getSize.

Returns the current local store size
public Status
getStatus()

Implements net.sf.ehcache.store.Store.getStatus.

Returns the cache status.
public int
getTerracottaClusteredSize()

Implements net.sf.ehcache.store.Store.getTerracottaClusteredSize.

Returns the current Terracotta clustered store size
private static int
hash(int hash)

public boolean

Returns:

true if faulted, false otherwise (including no mapping)
isFaulted
(final Object
the key to check the mapping for
key
)

Verifies if the mapping for a key is marked as faulted

public Set<Object>

Returns:

a set view of the keys in this store
keySet
()

Get a set view of the keys in this store

private static long
public boolean
put(Element element)

Implements net.sf.ehcache.store.Store.put.

Puts an item into the store.
public boolean
putFaulted(final Element element)

Implements net.sf.ehcache.store.AuthoritativeTier.putFaulted.

Stupid "implicit" contract in tests that dictates that entries put, will be in highest tier!
public Element
putIfAbsent(Element
element to be added
element
)

Implements net.sf.ehcache.store.Store.putIfAbsent.

Put an element in the store if no element is currently mapped to the elements key.
public boolean

Returns:

true if the encoded element was installed
putRawIfAbsent
(Object
the key of the element
key
,
DiskStorageFactory.DiskMarker
the encoded element
encoded
)

Put the given encoded element directly into the store

public boolean
putWithWriter(Element element, CacheWriterManager writerManager)

Implements net.sf.ehcache.store.Store.putWithWriter.

Puts an item into the store and the cache writer manager in an atomic operation
public Element
remove(Object key)

Implements net.sf.ehcache.store.Store.remove.

Removes an item from the cache.
public void
removeAll()

Implements net.sf.ehcache.store.Store.removeAll.

Remove all of the elements from the store.
public Element
removeElement(Element
Element to be removed
element
,
ElementValueComparator
ElementValueComparator to use to compare elements
comparator
)

Implements net.sf.ehcache.store.Store.removeElement.

Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element.
public Element
removeWithWriter(Object key, CacheWriterManager writerManager)

Implements net.sf.ehcache.store.Store.removeWithWriter.

Removes an item from the store and the cache writer manager in an atomic operation.
public boolean
replace(Element
Element to be test against
old
,
Element
Element to be cached
element
,
ElementValueComparator
ElementValueComparator to use to compare elements
comparator
)

Implements net.sf.ehcache.store.Store.replace.

Replace the cached element only if the value of the current Element is equal to the value of the supplied old Element.
public Element
replace(Element
Element to be cached
element
)

Implements net.sf.ehcache.store.Store.replace.

Replace the cached element only if an Element is currently cached for this key
private Segment
segmentFor(int hash)

public void
setInMemoryEvictionPolicy(Policy
the new policy
policy
)

Implements net.sf.ehcache.store.Store.setInMemoryEvictionPolicy.

Sets the eviction policy strategy.
public Object

Returns:

Element or ElementSubstitute
unretrievedGet
(Object
key to lookup
key
)

Return the unretrieved (undecoded) value for this key

private static long
Inherited from net.sf.ehcache.store.AbstractStore:
addStoreListenerexecuteQuerygetAllgetAllQuietgetEventListenerListgetSearchAttributegetSearchAttributeshasAbortedSizeOfisCacheCoherentisClusterCoherentisNodeCoherentputAllrecalculateSizeremoveAllremoveStoreListenersetAttributeExtractorssetNodeCoherentwaitUntilClusterCoherent