Top Description Fields Constructors Methods
net.sf.ehcache.terracotta

pack-priv Class RotatingSnapshotFile

extends Object
Class Inheritance
Imports
java.io.EOFException, .File, .FileInputStream, .FileOutputStream, .IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Collections, .HashSet, .Set, java.util.concurrent.locks.Lock, .ReadWriteLock, .ReentrantReadWriteLock, net.sf.ehcache.DiskStorePathManager, net.sf.ehcache.util.PreferredLoaderObjectInputStream, org.slf4j.Logger, .LoggerFactory

A file will rotate on every write, so to never loose older values in case of a JVM crash
Author
Alex Snaps

Field Summary

Modifier and TypeField and Description
private final String
private final ClassLoader
private final DiskStorePathManager
private static final Logger
private final Lock
private volatile boolean
private static final String
private static final String
private static final String
private final Lock

Constructor Summary

AccessConstructor and Description
pack-priv
RotatingSnapshotFile(final DiskStorePathManager diskStorePathManager, final String
use as base name of the files
cacheName
,
final ClassLoader classLoader)

Constructor

Method Summary

Modifier and TypeMethod and Description
private void
private void
cleanUp(final File inProgress)

private void
pack-priv File

Returns:

the file to read from
currentSnapshotFile
()

Creates a File representing the uncorrupted file on disk

pack-priv File

Returns:

the File to write to
newSnapshotFile
()

Creates a File representing the one to write new entries to

pack-priv <
the type of the each element
T
>
Set<T>

Returns:

the Set of all entries in the latest uncorrupted file on disk
readAll
()

Reads all the keys from the file on disk, doing cleanup if required of previously unterminated file written to

private boolean
pack-priv void
setShutdownOnThreadInterrupted(final boolean
true, if shutdown needs to happen in the middle of a write
shutdownOnThreadInterrupted
)

Whether to shutdown as soon as the writer Thread is interrupted, or to let all keys be written to disk first

pack-priv void
snapshotNowOrWaitForCurrentToFinish(final Set<E>
the latest current local set
localKeys
)

Calling this method will result in writing all keys to be written to disk or wait for the one in progress to finish

private void
swapForOldWithNewSnapshot(final File inProgress)

pack-priv File

Returns:

the File representing the previous successful snapshot (temp file to be deleted)
tempSnapshotFile
()

Creates a File representing the old uncorrupted file, when the new one has successfully been written to disk

pack-priv void
writeAll(final Iterable<T>
the iterable of entries to write to disk
localKeys
)

Writes all values of the iterable to a new file and does the necessary clean up when done

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheNameback to summary
private final String cacheName
classLoaderback to summary
private final ClassLoader classLoader
diskStorePathManagerback to summary
private final DiskStorePathManager diskStorePathManager
LOGback to summary
private static final Logger LOG
readLockback to summary
private final Lock readLock
shutdownOnThreadInterruptedback to summary
private volatile boolean shutdownOnThreadInterrupted
SUFFIX_MOVEback to summary
private static final String SUFFIX_MOVE
SUFFIX_OKback to summary
private static final String SUFFIX_OK
SUFFIX_PROGRESSback to summary
private static final String SUFFIX_PROGRESS
writeLockback to summary
private final Lock writeLock

Constructor Detail

RotatingSnapshotFileback to summary
pack-priv RotatingSnapshotFile(final DiskStorePathManager diskStorePathManager, final String cacheName, final ClassLoader classLoader)

Constructor

Parameters
cacheName:String

use as base name of the files

Method Detail

cleanUpback to summary
private void cleanUp()
cleanUpback to summary
private void cleanUp(final File inProgress)
closeAndDeleteAssociatedFileOnFailureback to summary
private void closeAndDeleteAssociatedFileOnFailure(final FileInputStream fis, final File associatedFile)
currentSnapshotFileback to summary
pack-priv File currentSnapshotFile()

Creates a File representing the uncorrupted file on disk

Returns:File

the file to read from

newSnapshotFileback to summary
pack-priv File newSnapshotFile()

Creates a File representing the one to write new entries to

Returns:File

the File to write to

readAllback to summary
pack-priv <T> Set<T> readAll() throws IOException

Reads all the keys from the file on disk, doing cleanup if required of previously unterminated file written to

Parameters
<T>
the type of the each element
Returns:Set<T>

the Set of all entries in the latest uncorrupted file on disk

Exceptions
IOException:
If the underlying FileInputStream does throw
requiresCleanUpback to summary
private boolean requiresCleanUp()
setShutdownOnThreadInterruptedback to summary
pack-priv void setShutdownOnThreadInterrupted(final boolean shutdownOnThreadInterrupted)

Whether to shutdown as soon as the writer Thread is interrupted, or to let all keys be written to disk first

Parameters
shutdownOnThreadInterrupted:boolean

true, if shutdown needs to happen in the middle of a write

snapshotNowOrWaitForCurrentToFinishback to summary
pack-priv void snapshotNowOrWaitForCurrentToFinish(final Set<E> localKeys) throws IOException

Calling this method will result in writing all keys to be written to disk or wait for the one in progress to finish

Parameters
localKeys:Set<E>

the latest current local set

Exceptions
IOException:
On exception being thrown while doing the snapshot
swapForOldWithNewSnapshotback to summary
private void swapForOldWithNewSnapshot(final File inProgress)
tempSnapshotFileback to summary
pack-priv File tempSnapshotFile()

Creates a File representing the old uncorrupted file, when the new one has successfully been written to disk

Returns:File

the File representing the previous successful snapshot (temp file to be deleted)

writeAllback to summary
pack-priv void writeAll(final Iterable<T> localKeys) throws IOException

Writes all values of the iterable to a new file and does the necessary clean up when done

Parameters
localKeys:Iterable<T>

the iterable of entries to write to disk

Exceptions
IOException:
If the underlying OutputStream do throw