class RotatingSnapshotFile
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
cacheName |
private DiskStorePathManager |
diskStorePathManager |
private static org.slf4j.Logger |
LOG |
private java.util.concurrent.locks.Lock |
readLock |
private boolean |
shutdownOnThreadInterrupted |
private static java.lang.String |
SUFFIX_MOVE |
private static java.lang.String |
SUFFIX_OK |
private static java.lang.String |
SUFFIX_PROGRESS |
private java.util.concurrent.locks.Lock |
writeLock |
Constructor and Description |
---|
RotatingSnapshotFile(DiskStorePathManager diskStorePathManager,
java.lang.String cacheName)
Constructor
|
Modifier and Type | Method and Description |
---|---|
private void |
cleanUp() |
private void |
cleanUp(java.io.File inProgress) |
private void |
closeAndDeleteAssociatedFileOnFailure(java.io.FileInputStream fis,
java.io.File associatedFile) |
(package private) java.io.File |
currentSnapshotFile()
Creates a File representing the uncorrupted file on disk
|
(package private) java.io.File |
newSnapshotFile()
Creates a File representing the one to write new entries to
|
(package private) <T> java.util.Set<T> |
readAll()
Reads all the keys from the file on disk, doing cleanup if required of previously unterminated file written to
|
private boolean |
requiresCleanUp() |
(package private) void |
setShutdownOnThreadInterrupted(boolean shutdownOnThreadInterrupted)
Whether to shutdown as soon as the writer Thread is interrupted, or to let all keys be written to disk first
|
(package private) void |
snapshotNowOrWaitForCurrentToFinish(java.util.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(java.io.File inProgress) |
(package private) java.io.File |
tempSnapshotFile()
Creates a File representing the old uncorrupted file, when the new one has successfully been written to disk
|
(package private) void |
writeAll(java.lang.Iterable localKeys)
Writes all values of the iterable to a new file and does the necessary clean up when done
|
private static final org.slf4j.Logger LOG
private static final java.lang.String SUFFIX_OK
private static final java.lang.String SUFFIX_PROGRESS
private static final java.lang.String SUFFIX_MOVE
private volatile boolean shutdownOnThreadInterrupted
private final java.lang.String cacheName
private final java.util.concurrent.locks.Lock readLock
private final java.util.concurrent.locks.Lock writeLock
private final DiskStorePathManager diskStorePathManager
RotatingSnapshotFile(DiskStorePathManager diskStorePathManager, java.lang.String cacheName)
cacheName
- use as base name of the filesvoid writeAll(java.lang.Iterable localKeys) throws java.io.IOException
localKeys
- the iterable of entries to write to diskjava.io.IOException
- If the underlying OutputStream do throw<T> java.util.Set<T> readAll() throws java.io.IOException
T
- the type of the each elementjava.io.IOException
- If the underlying FileInputStream does throwprivate void cleanUp()
private void cleanUp(java.io.File inProgress)
private boolean requiresCleanUp()
private void swapForOldWithNewSnapshot(java.io.File inProgress)
java.io.File currentSnapshotFile()
java.io.File newSnapshotFile()
java.io.File tempSnapshotFile()
void setShutdownOnThreadInterrupted(boolean shutdownOnThreadInterrupted)
shutdownOnThreadInterrupted
- true, if shutdown needs to happen in the middle of a writeprivate void closeAndDeleteAssociatedFileOnFailure(java.io.FileInputStream fis, java.io.File associatedFile)
void snapshotNowOrWaitForCurrentToFinish(java.util.Set localKeys) throws java.io.IOException
localKeys
- the latest current local setjava.io.IOException
- On exception being thrown while doing the snapshot