org.crosswire.jsword.book.sword.state
Class OpenFileStateManager
java.lang.Object
org.crosswire.jsword.book.sword.state.OpenFileStateManager
public final class OpenFileStateManager
- extends Object
Manages the creation and re-distribution of open file states. This increases
performance as more often than not, the same file state may be used. For
example we may be carrying out a contains() operation followed by a read to
disk for a particular key
Each SwordBookMetaData
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 SwordBookMetaData
, which then gives us a pool of available
file states... We create some more if none are available.
We may want to set a maximum to prevent leaking resources on heavy concurrent
usage. However, at the current time, with single thread access, we are
bounded to having 1 open file per module installed, which should be
acceptable across platforms.
- Author:
- DM Smith, Chris Burrell
- See Also:
for license details.
The copyright to this program is held by it's authors.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
metaToStates
private static volatile Map<SwordBookMetaData,Queue<OpenFileState>> metaToStates
shuttingDown
private static volatile boolean shuttingDown
OpenFileStateManager
private OpenFileStateManager()
- prevent instantiation
getRawBackendState
public static RawBackendState getRawBackendState(SwordBookMetaData metadata)
throws BookException
- Throws:
BookException
getRawFileBackendState
public static RawFileBackendState getRawFileBackendState(SwordBookMetaData metadata)
throws BookException
- Throws:
BookException
getGenBookBackendState
public static GenBookBackendState getGenBookBackendState(SwordBookMetaData metadata)
throws BookException
- Throws:
BookException
getRawLDBackendState
public static RawLDBackendState getRawLDBackendState(SwordBookMetaData metadata)
throws BookException
- Throws:
BookException
getZLDBackendState
public static ZLDBackendState getZLDBackendState(SwordBookMetaData metadata)
throws BookException
- Throws:
BookException
getZVerseBackendState
public static ZVerseBackendState getZVerseBackendState(SwordBookMetaData metadata,
BlockType blockType)
throws BookException
- Throws:
BookException
getInstance
private static <T extends OpenFileState> T getInstance(SwordBookMetaData metadata)
getQueueForMeta
private static Queue<OpenFileState> getQueueForMeta(SwordBookMetaData metadata)
release
public static void release(OpenFileState fileState)
shutDown
public static void shutDown()
- Shuts down all open files
ensureNotShuttingDown
private static void ensureNotShuttingDown()
throws BookException
- Throws:
BookException