ehcache

net.sf.ehcache.store.disk
Class DiskStorageFactory

java.lang.Object
  extended by net.sf.ehcache.store.disk.DiskStorageFactory

public class DiskStorageFactory
extends Object

A mock-up of a on-disk element proxy factory.

Author:
Chris Dennis, Ludovic Orban

Nested Class Summary
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.
 
Field Summary
protected  DiskStore store
          The store bound to this factory.
 
Constructor Summary
DiskStorageFactory(Ehcache cache, RegisteredEventListeners cacheEventNotificationService)
          Constructs an disk persistent factory for the given cache and disk path.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(Lock lock,
                 DiskStorageFactory.DiskSubstitute substitute)
Free any manually managed resources used by this DiskStorageFactory.DiskSubstitute.

Parameters:
lock - the lock protecting the DiskSubstitute
substitute - DiskSubstitute being freed.

free

public void free(Lock lock,
                 DiskStorageFactory.DiskSubstitute substitute,
                 boolean faultFailure)
Free any manually managed resources used by this DiskStorageFactory.DiskSubstitute.

Parameters:
lock - the lock protecting the DiskSubstitute
substitute - 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 IOException
Shuts down this disk factory.

This shuts down the executor and then waits for its termination, before closing the data file.

Throws:
IOException - if an IO error occurred

delete

protected void delete()
Deletes the data file for this factory.


schedule

protected <U> Future<U> schedule(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 IOException,
                       ClassNotFoundException
Read the data at the given marker, and return the associated deserialized Element.

Parameters:
marker - marker to read
Returns:
deserialized Element
Throws:
IOException - on read error
ClassNotFoundException - on deserialization error

write

protected DiskStorageFactory.DiskMarker write(Element element)
                                       throws IOException
Write the given element to disk, and return the associated marker.

Parameters:
element - to write
Returns:
marker representing the element
Throws:
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()
Return true if the disk write queue is full.

Returns:
true if the disk write queue is full.

getDataFile

public 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(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 IllegalArgumentException
Create a disk substitute for an element

Parameters:
element - the element to create a disk substitute for
Returns:
The substitute element
Throws:
IllegalArgumentException - if element cannot be substituted

retrieve

public Element retrieve(DiskStorageFactory.DiskSubstitute object)
Decodes the supplied DiskStorageFactory.DiskSubstitute.

Parameters:
object - ElementSubstitute to decode
Returns:
the decoded element

retrieve

public Element retrieve(DiskStorageFactory.DiskSubstitute object,
                        Segment segment)
Decodes the supplied DiskStorageFactory.DiskSubstitute, updating statistics.

Parameters:
object - ElementSubstitute to decode
Returns:
the decoded element

created

public boolean created(Object object)
Returns true if this factory created the given object.

Parameters:
object - object to check
Returns:
true if object created by this factory

unbind

public void unbind()
Unbinds a store instance from this factory


flush

public Future<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 File getIndexFile()
Return the index file for this store.

Returns:
the index file

ehcache

Copyright 2001-2017, Terracotta, Inc.