public class DiskStorageFactory
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private class |
DiskStorageFactory.DiskExpiryTask
Causes removal of all expired elements (and fires the relevant events).
|
private class |
DiskStorageFactory.DiskFreeTask
Disk free tasks are used to asynchronously free DiskMarker instances under the correct
exclusive write lock.
|
static class |
DiskStorageFactory.DiskMarker
DiskMarker instances point to the location of their
associated serialized Element instance.
|
static class |
DiskStorageFactory.DiskSubstitute
Abstract superclass for all disk substitutes.
|
(package private) class |
DiskStorageFactory.DiskWriteTask
DiskWriteTasks are used to serialize elements
to disk and fault in the resultant DiskMarker
instance.
|
(package private) class |
DiskStorageFactory.IndexWriteTask
Task that writes the index file for this factory.
|
private class |
DiskStorageFactory.OnDiskFilter
Filters for on-disk elements created by this factory
|
private class |
DiskStorageFactory.PersistentDiskWriteTask
Disk write task implementation for disk persistent stores.
|
(package private) class |
DiskStorageFactory.Placeholder
Placeholder instances are put in place to prevent
duplicate write requests while Elements are being
written to disk.
|
Modifier and Type | Field and Description |
---|---|
private FileAllocationTree |
allocator |
private java.io.RandomAccessFile[] |
dataAccess |
private int |
diskCapacity |
private boolean |
diskPersistent |
private java.util.concurrent.BlockingQueue<java.lang.Runnable> |
diskQueue |
private DiskStorePathManager |
diskStorePathManager |
private java.util.concurrent.ScheduledThreadPoolExecutor |
diskWriter
Executor service used to write elements to disk
|
private int |
elementSize |
private RegisteredEventListeners |
eventService |
private java.io.File |
file |
private DiskStorageFactory.IndexWriteTask |
flushTask |
private java.io.File |
indexFile |
private static org.slf4j.Logger |
LOG |
private static int |
MAX_EVICT |
private static int |
MEGABYTE |
private java.util.concurrent.atomic.AtomicInteger |
onDisk |
private ElementSubstituteFilter |
onDiskFilter |
private boolean |
pinningEnabled |
private long |
queueCapacity |
private static int |
SAMPLE_SIZE |
private static int |
SERIALIZATION_CONCURRENCY_DELAY
Path stub used to create unique ehcache directories.
|
private static int |
SHUTDOWN_GRACE_PERIOD |
protected DiskStore |
store
The store bound to this factory.
|
Constructor and Description |
---|
DiskStorageFactory(Ehcache cache,
RegisteredEventListeners cacheEventNotificationService)
Constructs an disk persistent factory for the given cache and disk path.
|
Modifier and Type | Method and Description |
---|---|
private DiskStorageFactory.DiskMarker |
alloc(Element element,
int size) |
private static java.io.RandomAccessFile[] |
allocateRandomAccessFiles(java.io.File f,
int stripes) |
void |
bind(DiskStore store)
Bind a store instance to this factory.
|
boolean |
bufferFull()
Return
true if the disk write queue is full. |
DiskStorageFactory.DiskSubstitute |
create(Element element)
Create a disk substitute for an element
|
boolean |
created(java.lang.Object object)
Returns
true if this factory created the given object. |
private DiskStorageFactory.DiskMarker |
createMarker(long position,
int size,
Element element) |
protected void |
delete()
Deletes the data file for this factory.
|
protected static void |
deleteFile(java.io.File f)
Attempt to delete the corresponding file and log an error on failure.
|
private boolean |
determineCachePinned(CacheConfiguration cacheConfiguration) |
(package private) int |
evict(int count)
Evict some elements, if possible
|
void |
expireElements()
Remove elements created by this factory if they have expired.
|
java.util.concurrent.Future<java.lang.Void> |
flush()
Schedule a flush (index write) for this factory.
|
protected void |
free(DiskStorageFactory.DiskMarker marker)
Free the given marker to be used by a subsequent write.
|
void |
free(java.util.concurrent.locks.Lock lock,
DiskStorageFactory.DiskSubstitute substitute)
Free any manually managed resources used by this
DiskStorageFactory.DiskSubstitute . |
void |
free(java.util.concurrent.locks.Lock lock,
DiskStorageFactory.DiskSubstitute substitute,
boolean faultFailure)
Free any manually managed resources used by this
DiskStorageFactory.DiskSubstitute . |
private java.io.RandomAccessFile |
getDataAccess(java.lang.Object key) |
java.io.File |
getDataFile()
Return a reference to the data file backing this factory.
|
private DiskStorageFactory.DiskSubstitute |
getDiskEvictionTarget(java.lang.Object keyHint,
int size) |
java.io.File |
getIndexFile()
Return the index file for this store.
|
int |
getOnDiskSize()
Return the number of on-disk elements
|
long |
getOnDiskSizeInBytes()
Return this size in bytes of this factory
|
private boolean |
isPinningEnabled() |
private void |
loadIndex() |
protected void |
markUsed(DiskStorageFactory.DiskMarker marker)
Mark this on-disk marker as used (hooks into the file space allocation structure).
|
private void |
onDiskEvict(int size,
java.lang.Object keyHint) |
protected Element |
read(DiskStorageFactory.DiskMarker marker)
Read the data at the given marker, and return the associated deserialized Element.
|
Element |
retrieve(DiskStorageFactory.DiskSubstitute object)
Decodes the supplied
DiskStorageFactory.DiskSubstitute . |
Element |
retrieve(DiskStorageFactory.DiskSubstitute object,
Segment segment)
Decodes the supplied
DiskStorageFactory.DiskSubstitute , updating statistics. |
protected <U> java.util.concurrent.Future<U> |
schedule(java.util.concurrent.Callable<U> call)
Schedule to given task on the disk writer executor service.
|
private MemoryEfficientByteArrayOutputStream |
serializeElement(Element element) |
void |
setOnDiskCapacity(int capacity)
Set the maximum on-disk capacity for this factory.
|
protected void |
shrinkDataFile()
Shrink this store's data file down to a minimal size for its contents.
|
protected void |
shutdown()
Shuts down this disk factory.
|
void |
unbind()
Unbinds a store instance from this factory
|
protected DiskStorageFactory.DiskMarker |
write(Element element)
Write the given element to disk, and return the associated marker.
|
private static final int SERIALIZATION_CONCURRENCY_DELAY
private static final int SHUTDOWN_GRACE_PERIOD
private static final int MEGABYTE
private static final int MAX_EVICT
private static final int SAMPLE_SIZE
private static final org.slf4j.Logger LOG
protected volatile DiskStore store
private final java.util.concurrent.BlockingQueue<java.lang.Runnable> diskQueue
private final java.util.concurrent.ScheduledThreadPoolExecutor diskWriter
private final long queueCapacity
private final java.io.File file
private final java.io.RandomAccessFile[] dataAccess
private final FileAllocationTree allocator
private final RegisteredEventListeners eventService
private volatile int elementSize
private final ElementSubstituteFilter onDiskFilter
private final java.util.concurrent.atomic.AtomicInteger onDisk
private final java.io.File indexFile
private final DiskStorageFactory.IndexWriteTask flushTask
private volatile int diskCapacity
private volatile boolean pinningEnabled
private final boolean diskPersistent
private final DiskStorePathManager diskStorePathManager
public DiskStorageFactory(Ehcache cache, RegisteredEventListeners cacheEventNotificationService)
cache
- cache that fronts this factoryprivate boolean determineCachePinned(CacheConfiguration cacheConfiguration)
private static java.io.RandomAccessFile[] allocateRandomAccessFiles(java.io.File f, int stripes) throws java.io.FileNotFoundException
java.io.FileNotFoundException
private java.io.RandomAccessFile getDataAccess(java.lang.Object key)
public long getOnDiskSizeInBytes()
public void bind(DiskStore store)
store
- store to bindpublic void free(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute)
DiskStorageFactory.DiskSubstitute
.lock
- the lock protecting the DiskSubstitutesubstitute
- DiskSubstitute being freed.public void free(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute, boolean faultFailure)
DiskStorageFactory.DiskSubstitute
.lock
- the lock protecting the DiskSubstitutesubstitute
- DiskSubstitute being freed.faultFailure
- true if this DiskSubstitute should be freed because of a disk failureprotected void markUsed(DiskStorageFactory.DiskMarker marker)
marker
- on-disk marker to mark as usedprotected void shrinkDataFile()
protected void shutdown() throws java.io.IOException
This shuts down the executor and then waits for its termination, before closing the data file.
java.io.IOException
- if an IO error occurredprotected void delete()
protected <U> java.util.concurrent.Future<U> schedule(java.util.concurrent.Callable<U> call)
U
- return type of the callablecall
- callable to callprotected Element read(DiskStorageFactory.DiskMarker marker) throws java.io.IOException, java.lang.ClassNotFoundException
marker
- marker to readjava.io.IOException
- on read errorjava.lang.ClassNotFoundException
- on deserialization errorprotected DiskStorageFactory.DiskMarker write(Element element) throws java.io.IOException
element
- to writejava.io.IOException
- on write errorprivate MemoryEfficientByteArrayOutputStream serializeElement(Element element) throws java.io.IOException
java.io.IOException
private DiskStorageFactory.DiskMarker alloc(Element element, int size) throws java.io.IOException
java.io.IOException
protected void free(DiskStorageFactory.DiskMarker marker)
marker
- marker to be free'dpublic boolean bufferFull()
true
if the disk write queue is full.true
if the disk write queue is full.public java.io.File getDataFile()
public void expireElements()
protected static void deleteFile(java.io.File f)
f
- the file to deletepublic DiskStorageFactory.DiskSubstitute create(Element element) throws java.lang.IllegalArgumentException
element
- the element to create a disk substitute forjava.lang.IllegalArgumentException
- if element cannot be substitutedpublic Element retrieve(DiskStorageFactory.DiskSubstitute object)
DiskStorageFactory.DiskSubstitute
.object
- ElementSubstitute to decodepublic Element retrieve(DiskStorageFactory.DiskSubstitute object, Segment segment)
DiskStorageFactory.DiskSubstitute
, updating statistics.object
- ElementSubstitute to decodepublic boolean created(java.lang.Object object)
true
if this factory created the given object.object
- object to checktrue
if object created by this factorypublic void unbind()
public java.util.concurrent.Future<java.lang.Void> flush()
private DiskStorageFactory.DiskMarker createMarker(long position, int size, Element element)
private boolean isPinningEnabled()
int evict(int count)
count
- the number of elements to evictpublic int getOnDiskSize()
public void setOnDiskCapacity(int capacity)
capacity
- the maximum on-disk capacity for this factory.private void onDiskEvict(int size, java.lang.Object keyHint)
private DiskStorageFactory.DiskSubstitute getDiskEvictionTarget(java.lang.Object keyHint, int size)
private void loadIndex()
public java.io.File getIndexFile()