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

Variable Index

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

Constructor Index

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

Method Index

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

Variables

 o 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
 o entries
 protected Hashtable entries
The loaded resource stores.

 o closed
 protected boolean closed
Is this store shutdown ?

 o storedir
 protected File storedir
Our store directory.

 o lru
 protected LRUList lru
The store entries least recetenly used list.

 o state
 protected ResourceStoreState state
 o sweeper
 protected StoreManagerSweeper sweeper
Our sweeper thread:

Constructors

 o 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.

Methods

 o getMaxEntries
 protected final int getMaxEntries()
 o checkClosed
 protected final synchronized void checkClosed()
Check that this resource store manager isn't closed.

Throws: RuntimeException
If the store manager was closed.
 o 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.
 o 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.
 o collect
 public void collect()
Collect enough entries to go back into fixed limits.

 o 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.
 o 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.
 o loadResourceStore
 public ResourceStore loadResourceStore(ResourceStoreHolder holder,
                                        File repository)
Load a resource store.

Parameters:
holder - The holder for the resource store.
repository - Its associated repository.
 o 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.
 o getCurrentStoreIdentifier
 public int getCurrentStoreIdentifier()
 o 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.
 o shutdown
 public synchronized void shutdown()
Shutdown this resource store manager. Go through all entries, and shut them down.

 o checkpoint
 public void checkpoint()
Checkpoint all modified resource stores, by saving them to disk.

 o 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.
 o 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
 o 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
 o 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