    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class w3c.tools.store.ResourceStoreManager

    java.lang.Object
       |
       +----w3c.tools.store.ResourceStoreManager

public class ResourceStoreManager
extends Object

##

closed
  Is this store shutdown ?
entries
  The loaded resource stores.
lru
  The store entries least recetenly used list.
state
storedir
  Our store directory.
STOREFILE_IDENTIFIER
  The identifier for resource store files.
sweeper
  Our sweeper thread:

##

ResourceStoreManager(File)
  Create a new resource store manager for given store directory.

##

addHolder(Object, ResourceStoreHolder)
  Add the given object as a holder to that store.
checkClosed()
  Check that this resource store manager isn't closed.
checkpoint()
  Checkpoint all modified resource stores, by saving them to disk.
collect()
  Collect enough entries to go back into fixed limits.
createResourceStoreRepository()
  Create a resource store repository name.
getCurrentStoreIdentifier()
getMaxEntries()
loadResourceStore(ResourceStoreHolder, File)
  Load a resource store.
lookupEntry(File, ResourceStoreHolder, boolean)
  Lookup an entry in the store.
markUsed(Object)
  Mark the given store as having been used recently.
pickleProlog(DataOutputStream, ResourceStore)
  Dump a prolog in given stream for that resource store.
pickLRUEntry()
  Pick the least recently used entry, and remove all links to it.
removeHolder(Object, ResourceStoreHolder)
  Remove the given holder from that store.
salvageState()
  Try to salvage the resource store manager state.
shutdown()
  Shutdown this resource store manager.
unholdResourceStore(ResourceStoreHolder, File)
  Unhold the given store.
unpickleProlog(DataInputStream, ResourceStore)
  Read in the prolog from the given input stream.

##

STOREFILE_IDENTIFIER

     public static final int STOREFILE_IDENTIFIER

  The identifier for resource store files. All files that are used as resource store, and whose resource store implementation make use of `pickleProlog` will start with a dump of that integer.

  See Also:
    pickleProlog, unpickleProlog

entries

     protected Hashtable entries

  The loaded resource stores.

closed

     protected boolean closed

  Is this store shutdown ?

storedir

     protected File storedir

  Our store directory.

lru

     protected LRUList lru

  The store entries least recetenly used list.

state

     protected ResourceStoreState state

sweeper

     protected StoreManagerSweeper sweeper

  Our sweeper thread:

##

ResourceStoreManager

     public ResourceStoreManager(File storedir)

  Create a new resource store manager for given store directory. The resource store manager will manage the collection of stores contained in the directory, and keep track of the stores state.

  Parameters:
    storedir - The store directory to manage.

##

getMaxEntries

     protected final int getMaxEntries()

checkClosed

     protected final synchronized void checkClosed()

  Check that this resource store manager isn't closed.

  Throws: RuntimeException
    If the store manager was closed.

lookupEntry

     protected synchronized StoreEntry lookupEntry(File repository,
                                                   ResourceStoreHolder holder,
                                                   boolean create)

  Lookup an entry in the store.

  Parameters:
    repository - The repository of the store to lookup.
    create - Create a new entry if it doesn't exist.

pickLRUEntry

     protected synchronized StoreEntry pickLRUEntry()

  Pick the least recently used entry, and remove all links to it. After this method as run, the least recently used entry for some store will be returned. The store manager will have discarded all its link to it, and the entry shutdown will have to be performed by the caller.

  Returns:
    An StoreEntry instance, to be cleaned up.

collect

     public void collect()

  Collect enough entries to go back into fixed limits.

addHolder

     public synchronized boolean addHolder(Object token,
                                           ResourceStoreHolder holder)

  Add the given object as a holder to that store.

  Parameters:
    token - Token to the store about to be held.
    holder - The store holder.
  Returns:
    A boolean true if the holder was installed.

removeHolder

     public synchronized void removeHolder(Object token,
                                           ResourceStoreHolder holder)

  Remove the given holder from that store.

  Parameters:
    token - Token to the store that was hold.
    holder - The resource store holder to remove.

loadResourceStore

     public ResourceStore loadResourceStore(ResourceStoreHolder holder,
                                            File repository)

  Load a resource store.

  Parameters:
    holder - The holder for the resource store.
    repository - Its associated repository.

createResourceStoreRepository

     public String createResourceStoreRepository()

  Create a resource store repository name. This method will return a new resource store repository key. When used in conjunction with the `loadResourceStore` method that takes a key as a parameter, this allows to caller to abstract itself from the physical location of the repository.

  Returns:
    A fresh resource store key, guaranteed to be uniq.

getCurrentStoreIdentifier

     public int getCurrentStoreIdentifier()

unholdResourceStore

     public void unholdResourceStore(ResourceStoreHolder holder,
                                     File repository)

  Unhold the given store. For some reason, the holder for this store has decided to close it. Remove from ths list of this store holder. When this call is made, the caller is expected to have cleaned-up the store (stabilize it, etc).

  Parameters:
    holder - The holder of the store.
    store - The store this holder doesn't want to hold anymore.

shutdown

     public synchronized void shutdown()

  Shutdown this resource store manager. Go through all entries, and shut them down.

checkpoint

     public void checkpoint()

  Checkpoint all modified resource stores, by saving them to disk.

markUsed

     public void markUsed(Object token)

  Mark the given store as having been used recently.

  Parameters:
    token - The token the resource store manager provided you when it initialized the store.

pickleProlog

     public static void pickleProlog(DataOutputStream out,
                                     ResourceStore store) throws IOException

  Dump a prolog in given stream for that resource store. Using the resource store manager prolog in a resource store implementation is optional. However, it is recommended that whenever possible, you use it to get the benefits of the main method of that class.

  Parameters:
    out - The output stream to dump the prolog to.
    store - The resource store which is being dumped.
  Throws: IOException
    If the prolog couldn't be pickled to the given output stream.
  See Also:
    unpickleProlog

unpickleProlog

     public static void unpickleProlog(DataInputStream in,
                                       ResourceStore store) throws IOException, NotAStoreException, InvalidStoreClassException, StoreClassVersionException

  Read in the prolog from the given input stream. This method checks the consistency between the implementation of the store that wants to read from that stream, and the implementation of the store that has been used to create it.

  Using that method, as well as using the `pickleProlog` method is optional; however, using one makes using the other mandatory.

  Parameters:
    in - The input stream to read the prolog from.
    store - The store that is to be created from the given input stream.
  Throws: IOException
    If the stream couldn't be read.
  Throws: NotAStoreException
    If the given repository wasn't flagged as containing a resource store.
  Throws: InvalidStoreClassException
    If the loading class is not the saving class.
  Throws: StoreClassVersionException
    If the saved store version number doesn't match the loader's class version number.
  See Also:
    pickleProlog

salvageState

     public ResourceStoreState salvageState()

  Try to salvage the resource store manager state. That's pretty easy and robust, it should really work well if no one hacked the store directory.

  Returns:
    A ResourceStoreState instance.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index