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

public Class DiskStorageFactory

extends Object
Class Inheritance
Annotations
@IgnoreSizeOf
Imports
java.io.ByteArrayInputStream, .EOFException, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .ObjectInputStream, .ObjectOutputStream, .RandomAccessFile, .Serializable, java.util.ConcurrentModificationException, .List, java.util.concurrent.BlockingQueue, .Callable, .Future, .ScheduledThreadPoolExecutor, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.Lock, net.sf.ehcache.CacheException, .DiskStorePathManager, .Ehcache, .Element, net.sf.ehcache.concurrent.ConcurrencyUtil, net.sf.ehcache.config.CacheConfiguration, .PinningConfiguration, net.sf.ehcache.event.RegisteredEventListeners, net.sf.ehcache.pool.sizeof.annotations.IgnoreSizeOf, net.sf.ehcache.store.disk.ods.FileAllocationTree, .Region, net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream, .PreferredLoaderObjectInputStream, .TimeUtil, org.slf4j.Logger, .LoggerFactory

A mock-up of a on-disk element proxy factory.
Authors
Chris Dennis, Ludovic Orban

Nested and Inner Type Summary

Modifier and TypeClass 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.

public static class
DiskStorageFactory.DiskMarker

DiskMarker instances point to the location of their associated serialized Element instance.

public abstract static class
DiskStorageFactory.DiskSubstitute

Abstract superclass for all disk substitutes.

pack-priv abstract class
DiskStorageFactory.DiskWriteTask

DiskWriteTasks are used to serialize elements to disk and fault in the resultant DiskMarker instance.

pack-priv 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.

pack-priv class
DiskStorageFactory.Placeholder

Placeholder instances are put in place to prevent duplicate write requests while Elements are being written to disk.

Field Summary

Modifier and TypeField and Description
private final FileAllocationTree
private final ClassLoader
private final RandomAccessFile[]
private volatile int
private final boolean
private final BlockingQueue<Runnable>
private final DiskStorePathManager
private final ScheduledThreadPoolExecutor
diskWriter

Executor service used to write elements to disk

private volatile int
private final RegisteredEventListeners
private final File
private final DiskStorageFactory.IndexWriteTask
private final File
private static final Logger
private static final int
private static final int
private final AtomicInteger
private final ElementSubstituteFilter
private volatile boolean
private final long
private static final int
private static final int
SERIALIZATION_CONCURRENCY_DELAY

Path stub used to create unique ehcache directories.

private static final int
protected volatile DiskStore
store

The store bound to this factory.

Constructor Summary

AccessConstructor and Description
public
DiskStorageFactory(Ehcache
cache that fronts this factory
cache
,
RegisteredEventListeners cacheEventNotificationService)

Constructs an disk persistent factory for the given cache and disk path.

Method Summary

Modifier and TypeMethod and Description
private DiskStorageFactory.DiskMarker
alloc(Element element, int size)

private static RandomAccessFile[]
public void
bind(DiskStore
store to bind
store
)

Bind a store instance to this factory.

public boolean

Returns:

true if the disk write queue is full.
bufferFull
()

Return true if the disk write queue is full.

public DiskStorageFactory.DiskSubstitute

Returns:

The substitute element
create
(Element
the element to create a disk substitute for
element
)

Create a disk substitute for an element

public boolean

Returns:

true if object created by this factory
created
(Object
object to check
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(File
the file to delete
f
)

Attempt to delete the corresponding file and log an error on failure.

private boolean
pack-priv int

Returns:

the number of elements actually evicted
evict
(int
the number of elements to evict
count
)

Evict some elements, if possible

public void
expireElements()

Remove elements created by this factory if they have expired.

public Future<Void>

Returns:

a Future
flush
()

Schedule a flush (index write) for this factory.

public void
free(Lock
the lock protecting the DiskSubstitute
lock
,
DiskStorageFactory.DiskSubstitute
DiskSubstitute being freed.
substitute
)

Free any manually managed resources used by this DiskSubstitute.

public void
free(Lock
the lock protecting the DiskSubstitute
lock
,
DiskStorageFactory.DiskSubstitute
DiskSubstitute being freed.
substitute
,
boolean
true if this DiskSubstitute should be freed because of a disk failure
faultFailure
)

Free any manually managed resources used by this DiskSubstitute.

protected void
free(DiskStorageFactory.DiskMarker
marker to be free'd
marker
)

Free the given marker to be used by a subsequent write.

private RandomAccessFile
public File

Returns:

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

Return a reference to the data file backing this factory.

pack-priv int

Returns:

the capacity
getDiskCapacity
()

accessor to the on-disk capacity

private DiskStorageFactory.DiskSubstitute
getDiskEvictionTarget(Object keyHint, int size)

public File

Returns:

the index file
getIndexFile
()

Return the index file for this store.

public int

Returns:

the number of on-disk elements
getOnDiskSize
()

Return the number of on-disk elements

public long

Returns:

this size in bytes of this factory
getOnDiskSizeInBytes
()

Return this size in bytes of this factory

private boolean
private void
protected void
markUsed(DiskStorageFactory.DiskMarker
on-disk marker to mark as used
marker
)

Mark this on-disk marker as used (hooks into the file space allocation structure).

private void
onDiskEvict(int size, Object keyHint)

protected Element

Returns:

deserialized Element
read
(DiskStorageFactory.DiskMarker
marker to read
marker
)

Read the data at the given marker, and return the associated deserialized Element.

public Element

Returns:

the decoded element
retrieve
(DiskStorageFactory.DiskSubstitute
ElementSubstitute to decode
object
)

Decodes the supplied DiskSubstitute.

public Element

Returns:

the decoded element
retrieve
(DiskStorageFactory.DiskSubstitute
ElementSubstitute to decode
object
,
Segment segment)

Decodes the supplied DiskSubstitute, updating statistics.

protected <
return type of the callable
U
>
Future<U>

Returns:

Future representing the return of this call
schedule
(Callable<U>
callable to call
call
)

Schedule to given task on the disk writer executor service.

private MemoryEfficientByteArrayOutputStream
public void
setOnDiskCapacity(int
the maximum on-disk capacity for this factory.
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.

public void
unbind()

Unbinds a store instance from this factory

protected DiskStorageFactory.DiskMarker

Returns:

marker representing the element
write
(Element
to write
element
)

Write the given element to disk, and return the associated marker.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait