org.crosswire.jsword.book.sword.state
Class OpenFileStateManager

java.lang.Object
  extended by 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.

Field Summary
private static Map<SwordBookMetaData,Queue<OpenFileState>> metaToStates
           
private static boolean shuttingDown
           
 
Constructor Summary
private OpenFileStateManager()
          prevent instantiation
 
Method Summary
private static void ensureNotShuttingDown()
           
static GenBookBackendState getGenBookBackendState(SwordBookMetaData metadata)
           
private static
<T extends OpenFileState>
T
getInstance(SwordBookMetaData metadata)
           
private static Queue<OpenFileState> getQueueForMeta(SwordBookMetaData metadata)
           
static RawBackendState getRawBackendState(SwordBookMetaData metadata)
           
static RawFileBackendState getRawFileBackendState(SwordBookMetaData metadata)
           
static RawLDBackendState getRawLDBackendState(SwordBookMetaData metadata)
           
static ZLDBackendState getZLDBackendState(SwordBookMetaData metadata)
           
static ZVerseBackendState getZVerseBackendState(SwordBookMetaData metadata, BlockType blockType)
           
static void release(OpenFileState fileState)
           
static 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

metaToStates

private static volatile Map<SwordBookMetaData,Queue<OpenFileState>> metaToStates

shuttingDown

private static volatile boolean shuttingDown
Constructor Detail

OpenFileStateManager

private OpenFileStateManager()
prevent instantiation

Method Detail

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

Copyright ? 2003-2011