org.w3c.tools.jdbm
Class jdbmResourceStore

java.lang.Object
  |
  +--org.w3c.tools.jdbm.jdbmResourceStore

public class jdbmResourceStore
extends java.lang.Object
implements ResourceStore


Field Summary
static int LOADED_LIMIT
           
static int LOADED_THRESOLD
           
 
Constructor Summary
jdbmResourceStore()
           
 
Method Summary
 boolean acceptUnload()
          Can this resource store be unloaded now ? This method gets called by the ResourceStoreManager before calling the shutdown method, when possible.
 void addResource(Resource resource)
          Add this resource to this resource store.
protected  void dbmError(java.lang.Exception ex, java.lang.String msg)
          A jdbm error has occured, this is potentially serious.
 java.util.Enumeration enumerateResourceIdentifiers()
          Enumerate all the resources saved in this store.
 java.lang.String getIdentifier()
          Get the identifier for that store.
 int getLoadedCount()
           
protected  byte[] getResourceBytes(java.lang.String identifier)
          Get the bytes that are the pickled version of the given resource.
 int getVersion()
          Get the version of that resource store.
 boolean hasResource(java.lang.String identifier)
          Check for the existence of a resource in this store.
 void initialize(ResourceStoreManager manager, java.lang.Object token, java.io.File repository)
          This resource store is being built, initialize it with the given arg.
 void listLRU(java.io.PrintStream out, java.lang.String msg)
           
 Resource loadResource(java.lang.String identifier)
           
 Resource loadResource(java.lang.String identifier, java.util.Hashtable defs)
          Restore the resource whose name is given.
 Resource lookupResource(java.lang.String identifier)
          Get this resource, but only if already loaded.
static void main(java.lang.String[] args)
          Dump all resources.
 void markModified(Resource resource)
          Mark this resource as modified.
 void removeResource(java.lang.String identifier)
          Remove this resource from the repository.
 void renameResource(java.lang.String oldid, java.lang.String newid)
          Rename a given resource.
protected  void reorganize()
           
 void runStoreSweeper()
           
 void save()
          Save this store.
protected  void saveResource(org.w3c.tools.jdbm.jdbmResource entry)
           
 void saveResource(Resource resource)
          Stabilize the resource having the given identifier.
 void setPersist(Resource resource)
           
 void shutdown()
          Shutdown this store.
protected  void startReorganize()
           
 void unloadResource()
          Unload one selected resource from the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOADED_LIMIT

public static final int LOADED_LIMIT

LOADED_THRESOLD

public static final int LOADED_THRESOLD
Constructor Detail

jdbmResourceStore

public jdbmResourceStore()
Method Detail

reorganize

protected void reorganize()

startReorganize

protected final void startReorganize()

getIdentifier

public java.lang.String getIdentifier()
Get the identifier for that store. We use the repository as an identifier, which is safe here.
Specified by:
getIdentifier in interface ResourceStore
Returns:
The absolute path of the repository.

getVersion

public int getVersion()
Description copied from interface: ResourceStore
Get the version of that resource store. Version numbers are used to distinguish between pickling format. A resource store implementator has the duty of bumping the returned number whenever it's archiving format changes. Resource stores that relies on some external archiving mechanisms (such as a database), may return a constant.
Specified by:
getVersion in interface ResourceStore
Tags copied from interface: ResourceStore
Returns:
An integer version number.

setPersist

public void setPersist(Resource resource)

listLRU

public void listLRU(java.io.PrintStream out,
                    java.lang.String msg)

runStoreSweeper

public void runStoreSweeper()

getLoadedCount

public final int getLoadedCount()

unloadResource

public void unloadResource()
Unload one selected resource from the store.

dbmError

protected void dbmError(java.lang.Exception ex,
                        java.lang.String msg)
A jdbm error has occured, this is potentially serious.
Parameters:
ex - The dbm exception.
msg - An informative description of the error.

getResourceBytes

protected byte[] getResourceBytes(java.lang.String identifier)
Get the bytes that are the pickled version of the given resource. This opens the file for each resource, it could of course be optimized for the cases were all the resources are to be loaded at once.
Parameters:
identifier - The resource identifier.
Returns:
The length, in the instance buffer, of the bytes that makes this resource.

saveResource

protected void saveResource(org.w3c.tools.jdbm.jdbmResource entry)

loadResource

public Resource loadResource(java.lang.String identifier,
                             java.util.Hashtable defs)
                      throws InvalidResourceException
Restore the resource whose name is given.
Specified by:
loadResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to restore.
defs - Default attribute values. If the resource needs to be restored from its pickled version, this Hashtable provides a set of default values for some of the attributes.
Returns:
A Resource instance, or null.

loadResource

public Resource loadResource(java.lang.String identifier)
                      throws InvalidResourceException

renameResource

public void renameResource(java.lang.String oldid,
                           java.lang.String newid)
Description copied from interface: ResourceStore
Rename a given resource.
Specified by:
renameResource in interface ResourceStore
Tags copied from interface: ResourceStore
Parameters:
oldid - The olde resource identifier.
newid - The new resource identifier.

lookupResource

public Resource lookupResource(java.lang.String identifier)
Get this resource, but only if already loaded. The resource store may (recommended) maintain a cache of the resource it loads from its store. If the resource having this identifier has already been loaded, return it, otherwise, return null.
Specified by:
lookupResource in interface ResourceStore
Parameters:
identifier - The resource identifier.
Returns:
A Resource instance, or null.

saveResource

public void saveResource(Resource resource)
Stabilize the resource having the given identifier.
Specified by:
saveResource in interface ResourceStore
Parameters:
identifier - The resource identifier.
Throws:
UnknownResourceException - If the resource is unknown.

addResource

public void addResource(Resource resource)
Add this resource to this resource store.
Specified by:
addResource in interface ResourceStore
Parameters:
resource - The resource to be added.

removeResource

public void removeResource(java.lang.String identifier)
Remove this resource from the repository.
Specified by:
removeResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to be removed.

markModified

public void markModified(Resource resource)
Mark this resource as modified.
Specified by:
markModified in interface ResourceStore
Parameters:
identifier - The identifier of the modified resource.

acceptUnload

public boolean acceptUnload()
Description copied from interface: ResourceStore
Can this resource store be unloaded now ? This method gets called by the ResourceStoreManager before calling the shutdown method, when possible. An implementation of that method is responsible for checking the acceptUnload method of all its loaded resource before returning true, meaning that the resource store can be unloaded.
Specified by:
acceptUnload in interface ResourceStore
Tags copied from interface: ResourceStore
Returns:
A boolean true if the resource store can be unloaded.

shutdown

public void shutdown()
Shutdown this store.
Specified by:
shutdown in interface ResourceStore

save

public void save()
Save this store.
Specified by:
save in interface ResourceStore

enumerateResourceIdentifiers

public java.util.Enumeration enumerateResourceIdentifiers()
Enumerate all the resources saved in this store.
Specified by:
enumerateResourceIdentifiers in interface ResourceStore
Returns:
An enumeration of Strings, giving the identifier for all the resources that this store knows about.

hasResource

public boolean hasResource(java.lang.String identifier)
Check for the existence of a resource in this store.
Specified by:
hasResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to check.
Returns:
A boolean true if the resource exists in this store, false otherwise.

initialize

public void initialize(ResourceStoreManager manager,
                       java.lang.Object token,
                       java.io.File repository)
This resource store is being built, initialize it with the given arg.
Specified by:
initialize in interface ResourceStore
Parameters:
repository - A file, giving the location of the associated repository.

main

public static void main(java.lang.String[] args)
Dump all resources.