public class DiskStorageFactory extends Object
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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 |
---|---|
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(Object object)
Returns
true if this factory created the given object. |
protected void |
delete()
Deletes the data file for this factory.
|
protected static void |
deleteFile(File f)
Attempt to delete the corresponding file and log an error on failure.
|
void |
expireElements()
Remove elements created by this factory if they have expired.
|
Future<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(Lock lock,
DiskStorageFactory.DiskSubstitute substitute)
Free any manually managed resources used by this
DiskStorageFactory.DiskSubstitute . |
void |
free(Lock lock,
DiskStorageFactory.DiskSubstitute substitute,
boolean faultFailure)
Free any manually managed resources used by this
DiskStorageFactory.DiskSubstitute . |
File |
getDataFile()
Return a reference to the data file backing this factory.
|
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
|
protected void |
markUsed(DiskStorageFactory.DiskMarker marker)
Mark this on-disk marker as used (hooks into the file space allocation structure).
|
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> Future<U> |
schedule(Callable<U> call)
Schedule to given task on the disk writer executor service.
|
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.
|
protected volatile DiskStore store
public DiskStorageFactory(Ehcache cache, RegisteredEventListeners cacheEventNotificationService)
cache
- cache that fronts this factorypublic long getOnDiskSizeInBytes()
public void bind(DiskStore store)
store
- store to bindpublic void free(Lock lock, DiskStorageFactory.DiskSubstitute substitute)
DiskStorageFactory.DiskSubstitute
.lock
- the lock protecting the DiskSubstitutesubstitute
- DiskSubstitute being freed.public void free(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 IOException
This shuts down the executor and then waits for its termination, before closing the data file.
IOException
- if an IO error occurredprotected void delete()
protected <U> Future<U> schedule(Callable<U> call)
U
- return type of the callablecall
- callable to callprotected Element read(DiskStorageFactory.DiskMarker marker) throws IOException, ClassNotFoundException
marker
- marker to readIOException
- on read errorClassNotFoundException
- on deserialization errorprotected DiskStorageFactory.DiskMarker write(Element element) throws IOException
element
- to writeIOException
- on write errorprotected 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 File getDataFile()
public void expireElements()
protected static void deleteFile(File f)
f
- the file to deletepublic DiskStorageFactory.DiskSubstitute create(Element element) throws IllegalArgumentException
element
- the element to create a disk substitute forIllegalArgumentException
- 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(Object object)
true
if this factory created the given object.object
- object to checktrue
if object created by this factorypublic void unbind()
public Future<Void> flush()
public int getOnDiskSize()
public void setOnDiskCapacity(int capacity)
capacity
- the maximum on-disk capacity for this factory.public File getIndexFile()
Copyright 2001-2021, Terracotta, Inc.