|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.jsword.book.sword.state.OpenFileStateManager
public final class OpenFileStateManager
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.
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.
Field Summary | |
---|---|
private static org.slf4j.Logger |
LOGGER
|
private static OpenFileStateManager |
manager
|
private Map<SwordBookMetaData,Queue<OpenFileState>> |
metaToStates
|
private ScheduledFuture<?> |
monitoringThread
|
private boolean |
shuttingDown
|
Constructor Summary | |
---|---|
private |
OpenFileStateManager(int cleanupIntervalSeconds,
int maxExpiry)
prevent instantiation |
Method Summary | ||
---|---|---|
private void |
ensureNotShuttingDown()
|
|
GenBookBackendState |
getGenBookBackendState(SwordBookMetaData metadata)
|
|
private
|
getInstance(SwordBookMetaData metadata)
|
|
private Queue<OpenFileState> |
getQueueForMeta(SwordBookMetaData metadata)
|
|
RawBackendState |
getRawBackendState(SwordBookMetaData metadata)
|
|
RawFileBackendState |
getRawFileBackendState(SwordBookMetaData metadata)
|
|
RawLDBackendState |
getRawLDBackendState(SwordBookMetaData metadata)
|
|
ZLDBackendState |
getZLDBackendState(SwordBookMetaData metadata)
|
|
ZVerseBackendState |
getZVerseBackendState(SwordBookMetaData 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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final ScheduledFuture<?> monitoringThread
private final Map<SwordBookMetaData,Queue<OpenFileState>> metaToStates
private volatile boolean shuttingDown
private static volatile OpenFileStateManager manager
private static final org.slf4j.Logger LOGGER
Constructor Detail |
---|
private OpenFileStateManager(int cleanupIntervalSeconds, int maxExpiry)
Method Detail |
---|
public static void init(int cleanupIntervalSeconds, int maxExpiry)
cleanupIntervalSeconds
- seconds before cleanupmaxExpiry
- public static OpenFileStateManager instance()
public RawBackendState getRawBackendState(SwordBookMetaData metadata) throws BookException
BookException
public RawFileBackendState getRawFileBackendState(SwordBookMetaData metadata) throws BookException
BookException
public GenBookBackendState getGenBookBackendState(SwordBookMetaData metadata) throws BookException
BookException
public RawLDBackendState getRawLDBackendState(SwordBookMetaData metadata) throws BookException
BookException
public ZLDBackendState getZLDBackendState(SwordBookMetaData metadata) throws BookException
BookException
public ZVerseBackendState getZVerseBackendState(SwordBookMetaData metadata, BlockType blockType) throws BookException
BookException
private <T extends OpenFileState> T getInstance(SwordBookMetaData metadata)
private Queue<OpenFileState> getQueueForMeta(SwordBookMetaData metadata)
public void release(OpenFileState fileState)
public void shutDown()
private void ensureNotShuttingDown() throws BookException
BookException
|
Copyright ยจ 2003-2015 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |