edu.ucsb.adl.middleware
Class ReportCache

java.lang.Object
  |
  +--edu.ucsb.adl.middleware.ReportCache

public final class ReportCache
extends java.lang.Object

Caches reports for a metadata view for a collection. The cache is implemented as a Berkeley DB database. The database may reside in a dedicated directory (or "environment" in Berkeley DB parlance) or it may share a directory with other databases.

Note: it is possible for two middleware instances running in the same JVM to share a cache (i.e., an instance of this class), specifically, when the two middleware instances specify the same cache directory and cache reports for two like-named collections. This behavior may or may not be desirable, depending on whether the two collections are really the same collection, or are distinct collections that just happen to have the same name.

Version:
$Header: /export/home/gjanee/middleware/edu/ucsb/adl/middleware/RCS/ReportCache.java,v 1.1 2006/06/23 20:42:38 gjanee Exp $

$Log: ReportCache.java,v $ Revision 1.1 2006/06/23 20:42:38 gjanee Initial revision

Author:
Greg Janée
Alexandria Digital Library

Method Summary
static edu.ucsb.adl.middleware.ReportCache createCache(java.lang.String cacheDirectory, java.lang.String databaseName)
          Creates a ReportCache.
 void destroy()
          Decrements the reference count.
 void empty()
          Empties the cache.
 java.lang.String get(java.lang.String holding)
          Retrieves the cached report for a holding.
 void put(java.lang.String holding, java.lang.String report)
          Inserts the report for a holding in the cache.
 void sync()
          Syncs the cache with persistent disk storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createCache

public static edu.ucsb.adl.middleware.ReportCache createCache(java.lang.String cacheDirectory,
                                                              java.lang.String databaseName)
                                                       throws InternalErrorException
Creates a ReportCache. If the Berkeley DB database for the cache does not exist, it is created. (The Berkeley DB environment, i.e., cache directory, must already exist, but the database itself will be created if necessary.) If a cache object already exists for the cache directory and database name, the extant cache's reference count is incremented and it is returned instead.

Parameters:
cacheDirectory - The cache's directory, which must already exist. The pathname must be absolute.
databaseName - The database name, e.g., "adl_catalog:adl:bucket".
Returns:
A ReportCache.
Throws:
InternalErrorException - If any error is encountered.

get

public java.lang.String get(java.lang.String holding)
                     throws InternalErrorException
Retrieves the cached report for a holding. This method is threadsafe.

Parameters:
holding - The holding identifier, e.g., "1001652".
Returns:
The report, or null if the report is not in the cache.
Throws:
InternalErrorException - If any error occurs.

put

public void put(java.lang.String holding,
                java.lang.String report)
         throws InternalErrorException
Inserts the report for a holding in the cache. If a report already exists, it is overwritten. This method is threadsafe.

Parameters:
holding - The holding identifier, e.g., "1001652".
report - The metadata report.
Throws:
InternalErrorException - If any error occurs.

empty

public void empty()
           throws InternalErrorException
Empties the cache. This method is threadsafe.

Throws:
InternalErrorException - If any error occurs. Regrettably, an exception unavoidably leaves the cache in an unusable state.

sync

public void sync()
          throws InternalErrorException
Syncs the cache with persistent disk storage. This method is threadsafe.

Throws:
InternalErrorException - If any error occurs.

destroy

public void destroy()
Decrements the reference count. When the reference count drops to zero, all resources held by the cache are freed.