public final class OpenFileStateManager extends Object
BookMetaData
has a corresponding a file state which is
different to another. Furthermore, concurrent accesses cannot share this file
state as the OpenFileState
records where in the file it is, for
reading several verses together for example. As a result, we want to key a
lookup by BookMetaData
, which then gives us a pool of available
file states... We create some more if none are available.
In order to prevent memory leaks (OpenFileStates might be quite heavy as they do some internal caching of file data..
In order to avoid many file references piling up in memory, we implement a background cleaning thread which will clean
up redundant keys every so often.The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
LOGGER |
private static OpenFileStateManager |
manager |
private Map<BookMetaData,Queue<OpenFileState>> |
metaToStates |
private ScheduledFuture<?> |
monitoringThread |
private boolean |
shuttingDown |
Modifier | Constructor and Description |
---|---|
private |
OpenFileStateManager(int cleanupIntervalSeconds,
int maxExpiry)
prevent instantiation
|
Modifier and Type | Method and Description |
---|---|
private void |
ensureNotShuttingDown() |
GenBookBackendState |
getGenBookBackendState(BookMetaData metadata) |
private <T extends OpenFileState> |
getInstance(BookMetaData metadata) |
private Queue<OpenFileState> |
getQueueForMeta(BookMetaData metadata) |
RawBackendState |
getRawBackendState(BookMetaData metadata) |
RawFileBackendState |
getRawFileBackendState(BookMetaData metadata) |
RawLDBackendState |
getRawLDBackendState(BookMetaData metadata) |
ZLDBackendState |
getZLDBackendState(BookMetaData metadata) |
ZVerseBackendState |
getZVerseBackendState(BookMetaData metadata,
BlockType blockType) |
static void |
init(int cleanupIntervalSeconds,
int maxExpiry)
Allow the caller to initialize with their own settings.
|
static OpenFileStateManager |
instance()
Singleton instance method to return the one and only Open File State Manager
|
void |
release(OpenFileState fileState) |
void |
shutDown()
Shuts down all open files
|
private final ScheduledFuture<?> monitoringThread
private final Map<BookMetaData,Queue<OpenFileState>> metaToStates
private volatile boolean shuttingDown
private static volatile OpenFileStateManager manager
private static final org.slf4j.Logger LOGGER
private OpenFileStateManager(int cleanupIntervalSeconds, int maxExpiry)
public static void init(int cleanupIntervalSeconds, int maxExpiry)
cleanupIntervalSeconds
- seconds before cleanupmaxExpiry
- public static OpenFileStateManager instance()
public RawBackendState getRawBackendState(BookMetaData metadata) throws BookException
BookException
public RawFileBackendState getRawFileBackendState(BookMetaData metadata) throws BookException
BookException
public GenBookBackendState getGenBookBackendState(BookMetaData metadata) throws BookException
BookException
public RawLDBackendState getRawLDBackendState(BookMetaData metadata) throws BookException
BookException
public ZLDBackendState getZLDBackendState(BookMetaData metadata) throws BookException
BookException
public ZVerseBackendState getZVerseBackendState(BookMetaData metadata, BlockType blockType) throws BookException
BookException
private <T extends OpenFileState> T getInstance(BookMetaData metadata)
private Queue<OpenFileState> getQueueForMeta(BookMetaData metadata)
public void release(OpenFileState fileState)
public void shutDown()
private void ensureNotShuttingDown() throws BookException
BookException