All Packages Class Hierarchy This Package Previous Next Index
Class w3c.tools.store.SimpleResourceStore
java.lang.Object
|
+----w3c.tools.store.SimpleResourceStore
- public class SimpleResourceStore
- extends Object
- implements ResourceStore
A very naive resource store.
This resource store keeps all the resources in a file. It loads all
resources (on a per-demand basis), and never unloads them.
-
manager
- Our resource store manager.
-
SimpleResourceStore()
-
-
acceptUnload()
- Can the resource store manager unload that store from memory.
-
addHolder(ResourceStoreHolder)
- Add a holder to that store.
-
addResource(Resource)
- Add a new resource to the resource store.
-
enumerateResourceIdentifiers()
- Enumerate all the resources identifier in this repository.
-
getFileAt(int)
- Get our file, positionned at the given position.
-
getIdentifier()
- Get the identifier for that store.
-
getResourceBytes(ResourceIndex, byte[])
- Get the bytes that are the pickled version of the given resource.
-
getVersion()
- Get the store format version number.
-
hasResource(String)
- Does this store defines this resource.
-
initialize(ResourceStoreManager, Object, File)
- Initialize this simple store with the given file.
-
internalSave(boolean)
- Internal save: save the repository back to disk.
-
loadIndex(Hashtable)
- Restore our whole index from our repository.
-
loadResource(String, Hashtable)
- Load a resource, or get one from the cache.
-
lockResource(ResourceLocker, Resource)
- Lock this resource in memory.
-
lookupResource(String)
- Lookup this resource.
-
main(String[])
-
-
markModified(Resource)
- Mark the given resource as being modified.
-
markUsed()
- Mark the store as having been used recently.
-
pickleResource(Resource, DataOutputStream)
- Pickle the given resource into the given output stream.
-
printIndex()
- Debug - print this resource store index.
-
removeHolder(ResourceStoreHolder)
- Remove a store holder.
-
removeResource(String)
- Remove a resource from this resource store.
-
renameResource(String, String)
- Rename a resource in the store.
-
save()
- Save all our modified resources back to our file.
-
saveResource(Resource)
- Save a given resource.
-
shutdown()
- Shutdown this store.
-
toString()
- Print a simple resource store.
-
unlockResource(ResourceLocker, Resource)
- Unlock this resource from memory.
-
warning(String)
- Emit the given string as a warning, to whoever it is appropriate.
manager
protected ResourceStoreManager manager
- Our resource store manager.
SimpleResourceStore
public SimpleResourceStore()
markUsed
protected final void markUsed()
- Mark the store as having been used recently.
addHolder
public synchronized void addHolder(ResourceStoreHolder holder)
- Add a holder to that store.
- Parameters:
- holder - The holder to add.
removeHolder
public synchronized void removeHolder(ResourceStoreHolder holder)
- Remove a store holder.
- Parameters:
- holder - The holder to remove.
getIdentifier
public String getIdentifier()
- Get the identifier for that store.
We use the repository as an identifier, which is safe here.
- Returns:
- The absolute path of the repository.
warning
protected void warning(String msg)
- Emit the given string as a warning, to whoever it is appropriate.
- Parameters:
- msg - The warning message.
getFileAt
protected RandomAccessFile getFileAt(int pos) throws IOException
- Get our file, positionned at the given position.
We won't keep our repository file always open (too much of these
resource stroe would burn our available file descriptors).
- Parameters:
- at - The position at wich you want the stream.
loadIndex
protected synchronized void loadIndex(Hashtable target) throws IOException
- Restore our whole index from our repository.
printIndex
protected void printIndex()
- Debug - print this resource store index.
getResourceBytes
protected synchronized byte[] getResourceBytes(ResourceIndex index,
byte into[]) throws IOException
- 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.
pickleResource
protected int pickleResource(Resource resource,
DataOutputStream out) throws IOException
- Pickle the given resource into the given output stream.
- Parameters:
- resource - The resource to pickle.
- out - The data output stream to pickle to.
- Returns:
- The size of the pickled version of the resource.
getVersion
public int getVersion()
- Get the store format version number.
- Returns:
- An ineteger version number, guaranteed to change whenever the
format used by the store changes.
loadResource
public Resource loadResource(String identifier,
Hashtable defs) throws InvalidResourceException
- Load a resource, or get one from the cache.
- Parameters:
- identifier - The resource identifier.
- Returns:
- A Resource instance, or null if the resource
doesn't exist in that store.
- Throws: InvalidResourceException
- If the resource couldn't be
restored from its pickled format.
internalSave
protected synchronized void internalSave(boolean unload) throws IOException
- Internal save: save the repository back to disk.
- Parameters:
- unload - Should we unload any existing resources ?
lookupResource
public Resource lookupResource(String identifier)
- Lookup this resource.
- Parameters:
- identifier - The resource identifier.
- Returns:
- A Resource instance, or null if either the
resource doesn't exist, or it isn't loaded yet.
saveResource
public void saveResource(Resource resource)
- Save a given resource.
If the resource has been modified, we save all our resources.
- Parameters:
- resource - The resource to be save right now.
lockResource
public synchronized boolean lockResource(ResourceLocker locker,
Resource resource)
- Lock this resource in memory.
- Parameters:
- locker - The object willing to acuiqre the lock.
- identifier - The resource to lock.
- Returns:
- A boolean true if the locking succeeds.
unlockResource
public synchronized void unlockResource(ResourceLocker locker,
Resource resource)
- Unlock this resource from memory.
- Parameters:
- lcoker - The object willing to relinquish the lock.
- identifier - The resource to unlock.
addResource
public synchronized void addResource(Resource resource)
- Add a new resource to the resource store.
- Parameters:
- resource - The resource to add.
removeResource
public synchronized void removeResource(String identifier)
- Remove a resource from this resource store.
- Parameters:
- identifier - The identifier of the resource to be removed.
renameResource
public synchronized void renameResource(String oldid,
String newid)
- Rename a resource in the store.
- Parameters:
- oldid - The old resource identifier.
- newid - The new resource identifier.
markModified
public synchronized void markModified(Resource resource)
- Mark the given resource as being modified.
- Parameters:
- identifier - The identifier of the modified resource.
acceptUnload
public synchronized boolean acceptUnload()
- Can the resource store manager unload that store from memory.
We check all the loaded resource, to see if they are willing to be
unloaded; we do unload straight all the resources that accept (to
reduce memory usage), and return false only if one
of our resource refuse to be unloaded.
shutdown
public synchronized void shutdown()
- Shutdown this store.
save
public synchronized void save()
- Save all our modified resources back to our file.
enumerateResourceIdentifiers
public Enumeration enumerateResourceIdentifiers()
- Enumerate all the resources identifier in this repository.
hasResource
public boolean hasResource(String identifier)
- Does this store defines this resource.
- Parameters:
- identifier - The resource we are looking for.
- Returns:
- A boolean true if found.
toString
public String toString()
- Print a simple resource store.
- Overrides:
- toString in class Object
initialize
public void initialize(ResourceStoreManager manager,
Object token,
File repository)
- Initialize this simple store with the given file.
- Parameters:
- manager - The resource store manager that loaded use.
- token - Our identification token from the above resource store
manager (this is an opaque object).
- file - The repository file.
main
public static void main(String args[]) throws Exception
All Packages Class Hierarchy This Package Previous Next Index