Package net.sf.ehcache.store.disk
Class DiskStorageFactory
- java.lang.Object
-
- net.sf.ehcache.store.disk.DiskStorageFactory
-
public class DiskStorageFactory extends java.lang.ObjectA mock-up of a on-disk element proxy factory.- Author:
- Chris Dennis, Ludovic Orban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiskStorageFactory.DiskMarkerDiskMarker instances point to the location of their associated serialized Element instance.static classDiskStorageFactory.DiskSubstituteAbstract superclass for all disk substitutes.
-
Constructor Summary
Constructors Constructor Description DiskStorageFactory(Ehcache cache, RegisteredEventListeners cacheEventNotificationService)Constructs an disk persistent factory for the given cache and disk path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(DiskStore store)Bind a store instance to this factory.booleanbufferFull()Returntrueif the disk write queue is full.DiskStorageFactory.DiskSubstitutecreate(Element element)Create a disk substitute for an elementbooleancreated(java.lang.Object object)Returnstrueif this factory created the given object.protected voiddelete()Deletes the data file for this factory.protected static voiddeleteFile(java.io.File f)Attempt to delete the corresponding file and log an error on failure.voidexpireElements()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.voidfree(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute)Free any manually managed resources used by thisDiskStorageFactory.DiskSubstitute.voidfree(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute, boolean faultFailure)Free any manually managed resources used by thisDiskStorageFactory.DiskSubstitute.protected voidfree(DiskStorageFactory.DiskMarker marker)Free the given marker to be used by a subsequent write.java.io.FilegetDataFile()Return a reference to the data file backing this factory.java.io.FilegetIndexFile()Return the index file for this store.intgetOnDiskSize()Return the number of on-disk elementslonggetOnDiskSizeInBytes()Return this size in bytes of this factoryprotected voidmarkUsed(DiskStorageFactory.DiskMarker marker)Mark this on-disk marker as used (hooks into the file space allocation structure).protected Elementread(DiskStorageFactory.DiskMarker marker)Read the data at the given marker, and return the associated deserialized Element.Elementretrieve(DiskStorageFactory.DiskSubstitute object)Decodes the suppliedDiskStorageFactory.DiskSubstitute.Elementretrieve(DiskStorageFactory.DiskSubstitute object, Segment segment)Decodes the suppliedDiskStorageFactory.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.voidsetOnDiskCapacity(int capacity)Set the maximum on-disk capacity for this factory.protected voidshrinkDataFile()Shrink this store's data file down to a minimal size for its contents.protected voidshutdown()Shuts down this disk factory.voidunbind()Unbinds a store instance from this factoryprotected DiskStorageFactory.DiskMarkerwrite(Element element)Write the given element to disk, and return the associated marker.
-
-
-
Field Detail
-
store
protected volatile DiskStore store
The store bound to this factory.
-
-
Constructor Detail
-
DiskStorageFactory
public DiskStorageFactory(Ehcache cache, RegisteredEventListeners cacheEventNotificationService)
Constructs an disk persistent factory for the given cache and disk path.- Parameters:
cache- cache that fronts this factory
-
-
Method Detail
-
getOnDiskSizeInBytes
public long getOnDiskSizeInBytes()
Return this size in bytes of this factory- Returns:
- this size in bytes of this factory
-
bind
public void bind(DiskStore store)
Bind a store instance to this factory.- Parameters:
store- store to bind
-
free
public void free(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute)Free any manually managed resources used by thisDiskStorageFactory.DiskSubstitute.- Parameters:
lock- the lock protecting the DiskSubstitutesubstitute- DiskSubstitute being freed.
-
free
public void free(java.util.concurrent.locks.Lock lock, DiskStorageFactory.DiskSubstitute substitute, boolean faultFailure)Free any manually managed resources used by thisDiskStorageFactory.DiskSubstitute.- Parameters:
lock- the lock protecting the DiskSubstitutesubstitute- DiskSubstitute being freed.faultFailure- true if this DiskSubstitute should be freed because of a disk failure
-
markUsed
protected void markUsed(DiskStorageFactory.DiskMarker marker)
Mark this on-disk marker as used (hooks into the file space allocation structure).- Parameters:
marker- on-disk marker to mark as used
-
shrinkDataFile
protected void shrinkDataFile()
Shrink this store's data file down to a minimal size for its contents.
-
shutdown
protected void shutdown() throws java.io.IOExceptionShuts down this disk factory.This shuts down the executor and then waits for its termination, before closing the data file.
- Throws:
java.io.IOException- if an IO error occurred
-
delete
protected void delete()
Deletes the data file for this factory.
-
schedule
protected <U> java.util.concurrent.Future<U> schedule(java.util.concurrent.Callable<U> call)
Schedule to given task on the disk writer executor service.- Type Parameters:
U- return type of the callable- Parameters:
call- callable to call- Returns:
- Future representing the return of this call
-
read
protected Element read(DiskStorageFactory.DiskMarker marker) throws java.io.IOException, java.lang.ClassNotFoundException
Read the data at the given marker, and return the associated deserialized Element.- Parameters:
marker- marker to read- Returns:
- deserialized Element
- Throws:
java.io.IOException- on read errorjava.lang.ClassNotFoundException- on deserialization error
-
write
protected DiskStorageFactory.DiskMarker write(Element element) throws java.io.IOException
Write the given element to disk, and return the associated marker.- Parameters:
element- to write- Returns:
- marker representing the element
- Throws:
java.io.IOException- on write error
-
free
protected void free(DiskStorageFactory.DiskMarker marker)
Free the given marker to be used by a subsequent write.- Parameters:
marker- marker to be free'd
-
bufferFull
public boolean bufferFull()
Returntrueif the disk write queue is full.- Returns:
trueif the disk write queue is full.
-
getDataFile
public java.io.File getDataFile()
Return a reference to the data file backing this factory.- Returns:
- a reference to the data file backing this factory.
-
expireElements
public void expireElements()
Remove elements created by this factory if they have expired.
-
deleteFile
protected static void deleteFile(java.io.File f)
Attempt to delete the corresponding file and log an error on failure.- Parameters:
f- the file to delete
-
create
public DiskStorageFactory.DiskSubstitute create(Element element) throws java.lang.IllegalArgumentException
Create a disk substitute for an element- Parameters:
element- the element to create a disk substitute for- Returns:
- The substitute element
- Throws:
java.lang.IllegalArgumentException- if element cannot be substituted
-
retrieve
public Element retrieve(DiskStorageFactory.DiskSubstitute object)
Decodes the suppliedDiskStorageFactory.DiskSubstitute.- Parameters:
object- ElementSubstitute to decode- Returns:
- the decoded element
-
retrieve
public Element retrieve(DiskStorageFactory.DiskSubstitute object, Segment segment)
Decodes the suppliedDiskStorageFactory.DiskSubstitute, updating statistics.- Parameters:
object- ElementSubstitute to decode- Returns:
- the decoded element
-
created
public boolean created(java.lang.Object object)
Returnstrueif this factory created the given object.- Parameters:
object- object to check- Returns:
trueif object created by this factory
-
unbind
public void unbind()
Unbinds a store instance from this factory
-
flush
public java.util.concurrent.Future<java.lang.Void> flush()
Schedule a flush (index write) for this factory.- Returns:
- a Future
-
getOnDiskSize
public int getOnDiskSize()
Return the number of on-disk elements- Returns:
- the number of on-disk elements
-
setOnDiskCapacity
public void setOnDiskCapacity(int capacity)
Set the maximum on-disk capacity for this factory.- Parameters:
capacity- the maximum on-disk capacity for this factory.
-
getIndexFile
public java.io.File getIndexFile()
Return the index file for this store.- Returns:
- the index file
-
-