org.w3c.tools.resources.store
Class ResourceStoreManager

java.lang.Object
  extended by org.w3c.tools.resources.store.ResourceStoreManager
All Implemented Interfaces:
ResourceSpace

public class ResourceStoreManager
extends java.lang.Object
implements ResourceSpace


Field Summary
protected  boolean closed
          Is this store shutdown ?
static boolean debug
           
 boolean debugMemory
           
protected  ResourceEventQueue eventQueue
           
protected  java.io.File index
          Our index file.
protected  LRUList lru
          The store entries least recetenly used list.
static java.lang.String ROOT_REP
           
protected  java.io.File root_repository
          Our root repository.
protected  Serializer serializer
           
protected  java.lang.String server_name
          server name;
protected  ResourceStoreState state
           
static java.lang.String STATE_F
           
protected  java.io.File storedir
          Our store directory.
static int SUBDIRS
          Number of sub-levels file system directories in the store directory.
protected  org.w3c.tools.resources.store.StoreManagerSweeper sweeper
          Our sweeper thread:
 
Constructor Summary
ResourceStoreManager(java.lang.String server_name, java.io.File storedir, java.lang.String default_root_class, java.lang.String default_root_name, java.lang.String serializer_class, int max_loaded_store, java.util.Hashtable defs)
          Create a new resource store manager for given store directory.
ResourceStoreManager(java.lang.String server_name, java.io.File storedir, java.lang.String default_root_class, java.lang.String default_root_name, java.lang.String serializer_class, int max_loaded_store, int store_size_limit, java.util.Hashtable defs)
          Create a new resource store manager for given store directory.
 
Method Summary
 void acquireChildren(SpaceEntry sentry)
          Acquire the StoreEntry of the space entry.
 void acquireChildren(SpaceEntry sentry, java.io.File repository, boolean transientFlag)
          acquire children from an external file.
 ResourceReference addResource(SpaceEntry sentry, Resource resource, java.util.Hashtable defs)
          Add this resource to the StoreEntry of the space entry.
protected  void checkClosed()
          Check that this resource store manager isn't closed.
 boolean checkKey(java.lang.Integer key)
          Check that the key is not already in the list of references
protected  void checkMaxLoadedStore()
           
 void checkpoint()
          Checkpoint all modified resource stores, by saving them to disk.
protected  boolean checkSubDirs()
           
 void collect()
          Collect enough entries to go back into fixed limits.
 java.lang.String createResourceStoreRepository()
          Create a resource store repository name.
protected  void decrLoadedStore()
           
 void deleteChildren(SpaceEntry sentry)
          Delete all the children of resource indentified by its space entry.
 void deleteResource(SpaceEntry sentry, Resource resource)
          delete this resource from the StoreEntry (and the repository).
 void displayIndex()
           
 java.util.Enumeration enumerateResourceIdentifiers(SpaceEntry sentry)
          Enumerate the name (ie identifiers) of the space entry children.
 int getCurrentStoreIdentifier()
           
 ResourceEventQueue getEventQueue()
           
 java.lang.String getHTMLStatus()
          Implementation of Status interface Display statistics about usage of the resource store manager
protected  java.io.File getIndexFile()
          Get the index file.
protected  int getMaxLoadedStore()
           
protected  java.io.File getOldIndexFile()
          Get the index file.
protected  java.lang.Integer getRootKey()
          Get The root key.
protected  java.io.File getRootRepository()
          Get the root repository.
protected  int getStoreSizeLimit()
           
protected  void incrLoadedStore()
           
protected  void loadNewEntriesIndex()
           
 ResourceReference loadResource(SpaceEntry sentry, java.lang.String identifier, java.util.Hashtable defs)
          Restore the resource whose name is given.
 ResourceReference loadRootResource(java.lang.String identifier, java.util.Hashtable defs)
          Restore the resource whose name is given from the root NewStoreEntry.
 ResourceReference lookupResource(SpaceEntry sentry, java.lang.String identifier)
          Lookup this resource.
 void markModified(SpaceEntry sentry, Resource resource)
          Mark the given resource as being modified.
 void markUsed(java.lang.Object token)
          Mark the given store as having been used recently.
protected  NewStoreEntry pickLRUEntry()
          Pick the least recently used entry, and remove all links to it.
 void renameResource(SpaceEntry sentry, java.lang.String oldid, java.lang.String newid)
          Rename a resource in this resource space.
 void salvage()
           
 ResourceStoreState salvageState()
          Try to salvage the resource store manager state.
 void saveChildren(SpaceEntry sentry)
          Save all the children of the resource indentified by its spaec entry.
protected  void saveNewEntriesIndex()
           
 void saveResource(SpaceEntry sentry, Resource resource)
          Save this resource to the StoreEntry of the space entry.
 void shutdown()
          Shutdown this resource store manager.
static void updateEntriesIndex(java.io.File oldIndexFile, java.io.File newIndexFile, Serializer serializer)
          update the old index file.
protected  boolean used(java.lang.String rep)
           
protected  void warning(java.lang.String msg)
          Emit the given string as a warning, to whoever it is appropriate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug

SUBDIRS

public static final int SUBDIRS
Number of sub-levels file system directories in the store directory.

See Also:
Constant Field Values

ROOT_REP

public static final java.lang.String ROOT_REP
See Also:
Constant Field Values

STATE_F

public static final java.lang.String STATE_F
See Also:
Constant Field Values

debugMemory

public boolean debugMemory

serializer

protected Serializer serializer

closed

protected boolean closed
Is this store shutdown ?


storedir

protected java.io.File storedir
Our store directory.


index

protected java.io.File index
Our index file.


server_name

protected java.lang.String server_name
server name;


root_repository

protected java.io.File root_repository
Our root repository.


lru

protected LRUList lru
The store entries least recetenly used list.


state

protected ResourceStoreState state

sweeper

protected org.w3c.tools.resources.store.StoreManagerSweeper sweeper
Our sweeper thread:


eventQueue

protected ResourceEventQueue eventQueue
Constructor Detail

ResourceStoreManager

public ResourceStoreManager(java.lang.String server_name,
                            java.io.File storedir,
                            java.lang.String default_root_class,
                            java.lang.String default_root_name,
                            java.lang.String serializer_class,
                            int max_loaded_store,
                            java.util.Hashtable defs)
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.

ResourceStoreManager

public ResourceStoreManager(java.lang.String server_name,
                            java.io.File storedir,
                            java.lang.String default_root_class,
                            java.lang.String default_root_name,
                            java.lang.String serializer_class,
                            int max_loaded_store,
                            int store_size_limit,
                            java.util.Hashtable defs)
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.
Method Detail

getEventQueue

public ResourceEventQueue getEventQueue()
Specified by:
getEventQueue in interface ResourceSpace

getMaxLoadedStore

protected final int getMaxLoadedStore()

getStoreSizeLimit

protected final int getStoreSizeLimit()

incrLoadedStore

protected void incrLoadedStore()

decrLoadedStore

protected void decrLoadedStore()

checkClosed

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

Throws:
java.lang.RuntimeException - If the store manager was closed.

pickLRUEntry

protected NewStoreEntry 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.


createResourceStoreRepository

public java.lang.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()

checkSubDirs

protected boolean checkSubDirs()

getIndexFile

protected java.io.File getIndexFile()
Get the index file.

Returns:
A File instance.

getOldIndexFile

protected java.io.File getOldIndexFile()
Get the index file.

Returns:
A File instance.

getRootRepository

protected java.io.File getRootRepository()
Get the root repository.

Returns:
A File instance.

getRootKey

protected java.lang.Integer getRootKey()
Get The root key.

Returns:
A String instance

warning

protected void warning(java.lang.String msg)
Emit the given string as a warning, to whoever it is appropriate.

Parameters:
msg - The warning message.

saveNewEntriesIndex

protected void saveNewEntriesIndex()

loadNewEntriesIndex

protected void loadNewEntriesIndex()

updateEntriesIndex

public static void updateEntriesIndex(java.io.File oldIndexFile,
                                      java.io.File newIndexFile,
                                      Serializer serializer)
                               throws java.io.IOException
update the old index file. Load it and save it with the serializer.

Parameters:
the - index file (serialized hashtable of StoreEntry)
Throws:
java.io.IOException

shutdown

public void shutdown()
Shutdown this resource store manager. Go through all entries, and shut them down.

Specified by:
shutdown in interface ResourceSpace

checkpoint

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

Specified by:
checkpoint in interface ResourceSpace

markUsed

public void markUsed(java.lang.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.

used

protected boolean used(java.lang.String rep)

salvage

public void salvage()

displayIndex

public void displayIndex()

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.

loadRootResource

public ResourceReference loadRootResource(java.lang.String identifier,
                                          java.util.Hashtable defs)
Restore the resource whose name is given from the root NewStoreEntry.

Specified by:
loadRootResource in interface ResourceSpace
Parameters:
identifier - The identifier of the resource to restore.
defs - Default attribute values.

checkKey

public boolean checkKey(java.lang.Integer key)
Check that the key is not already in the list of references

Returns:
a boolean, true if the key is not there, false if it is

lookupResource

public ResourceReference lookupResource(SpaceEntry sentry,
                                        java.lang.String identifier)
Lookup this resource.

Specified by:
lookupResource in interface ResourceSpace
Parameters:
sentry - The resource space entry.
identifier - The resource identifier.
Returns:
A Resource instance, or null if either the resource doesn't exist, or it isn't loaded yet.

loadResource

public ResourceReference loadResource(SpaceEntry sentry,
                                      java.lang.String identifier,
                                      java.util.Hashtable defs)
Restore the resource whose name is given.

Specified by:
loadResource in interface ResourceSpace
Parameters:
sentry - The resource space entry.
identifier - The identifier of the resource to restore.
defs - Default attribute values.

addResource

public ResourceReference addResource(SpaceEntry sentry,
                                     Resource resource,
                                     java.util.Hashtable defs)
Add this resource to the StoreEntry of the space entry.

Specified by:
addResource in interface ResourceSpace
Parameters:
sentry - The resource space entry.
resource - The resource to add.
defs - Default attribute values.

saveResource

public void saveResource(SpaceEntry sentry,
                         Resource resource)
Save this resource to the StoreEntry of the space entry.

Specified by:
saveResource in interface ResourceSpace
Parameters:
sentry - The resource space entry
resource - The resource to save.

markModified

public void markModified(SpaceEntry sentry,
                         Resource resource)
Mark the given resource as being modified.

Specified by:
markModified in interface ResourceSpace
Parameters:
sentry - The resource space entry.
resource - The resource to mark as modified.

renameResource

public void renameResource(SpaceEntry sentry,
                           java.lang.String oldid,
                           java.lang.String newid)
Rename a resource in this resource space.

Specified by:
renameResource in interface ResourceSpace
Parameters:
sentry - The resource space entry.
oldid - The old resorce identifier.
newid - The new resorce identifier.

deleteResource

public void deleteResource(SpaceEntry sentry,
                           Resource resource)
delete this resource from the StoreEntry (and the repository).

Specified by:
deleteResource in interface ResourceSpace
Parameters:
sentry - The resource space entry
resource - The resource to delete.

deleteChildren

public void deleteChildren(SpaceEntry sentry)
Delete all the children of resource indentified by its space entry.

Specified by:
deleteChildren in interface ResourceSpace
Parameters:
sentry - The resource space entry

saveChildren

public void saveChildren(SpaceEntry sentry)
Save all the children of the resource indentified by its spaec entry.

Specified by:
saveChildren in interface ResourceSpace
Parameters:
sentry - The resource space entry

checkMaxLoadedStore

protected void checkMaxLoadedStore()

acquireChildren

public void acquireChildren(SpaceEntry sentry,
                            java.io.File repository,
                            boolean transientFlag)
acquire children from an external file.

Specified by:
acquireChildren in interface ResourceSpace
Parameters:
sentry - The resource space entry.
repository - The file used to store children.

acquireChildren

public void acquireChildren(SpaceEntry sentry)
Acquire the StoreEntry of the space entry.

Specified by:
acquireChildren in interface ResourceSpace
Parameters:
sentry - The resource space entry.

getHTMLStatus

public java.lang.String getHTMLStatus()
Implementation of Status interface Display statistics about usage of the resource store manager


enumerateResourceIdentifiers

public java.util.Enumeration enumerateResourceIdentifiers(SpaceEntry sentry)
Enumerate the name (ie identifiers) of the space entry children.

Specified by:
enumerateResourceIdentifiers in interface ResourceSpace
Parameters:
sentry - The space entry.
all - Should all resources be listed.
Returns:
An enumeration, providing one element per child, which is the name of the child, as a String.