gov.nist.nlpir.irf.proxy
Class HandlesByOid

java.lang.Object
  |
  +--gov.nist.nlpir.irf.proxy.HandlesByOid
Direct Known Subclasses:
AnySizeHandlesByOid, OneSizeHandlesByOid

public abstract class HandlesByOid
extends java.lang.Object
implements java.io.Serializable

The HandlesByOid table is responsible for keeping track of the handle of each persistent object by its object identifier (Oid). Oids are assigned by IRF and handles may vary according to the persistence mechanism used.

This class is abstract. Thus, there may be several implementations, matching different families of handles. If all handles have the same size when they're written to disk, then the OneSizeHandlesByOid class can be used to get an actual instance of HandlesByOid. If they can be different, then AnySizeHandlesByOid will work, as it uses a more generic mechanism to match Handles to Oids.

Version:
$Revision: 1.6 $
Author:
This software was produced by NIST, an agency of the U.S. government, and by statute is not subject to copyright in the United States. Recipients of this software assume all responsibilities associated with its operation, modification and maintenance.
See Also:
Oid, Handle, Serialized Form

Field Summary
protected static java.lang.String fileSeparator
          Local copy of System file separator
private static long handlesByOidAdds
          Statistics on handlesByOid table and cache.
private static HashingCache handlesByOidCache
          Cache for handles by Oid
protected static BufferedRandomAccessFile handlesByOidDataFile
          The file used to keep track of handles by Oid.
private static java.lang.String handlesByOidDataFileLocation
          Used to find the file associating Handles to Oids.
private static long handlesByOidGets
           
private static long handlesByOidGetsFromCache
           
private static long handlesByOidRemoves
           
private static long handlesByOidUpdates
           
private static int maxHandlesByOidCacheEntries
          Initial size of the cache used to match handles to Oids.
(package private) static long serialVersionUID
          serial version universal id - put here so Java does not insert one which may change due to revisions and make it impossible to deserialize earlier versions of serialized objects
 
Constructor Summary
HandlesByOid()
           
 
Method Summary
 void addHandleByOid(Oid oid, Handle handle)
          Adds a handle to the table of handles by Oid
 Handle getHandleByOid(Oid oid)
          Gets a handle from the table of handles by Oid
 java.lang.String getHandlesByOidDataFileLocation()
          Gets the location of the handlesByOidDataFile;
abstract  long getHandlesByOidSize()
          Gets the size of the table
 int getMaxHandlesByOidCacheEntries()
          Returns the maximum number of entries in the cache
 java.lang.String getStatistics()
          Returns a String that contains statistics about this table and the cache it embeds.
 void openHandlesByOid(java.lang.String directory)
          Opens the handles-by-oid files
protected abstract  Handle readHandleForOid(Oid oid)
          Reads the handle from the disk.
 void replaceHandleByOid(Oid oid, Handle newHandle)
          Replaces the entry in table of handles by Oid for the specified Oid with a new one using the same Oid the new handle passed.
 void setHandlesByOidDataFileLocation(java.lang.String location)
          Sets the location of the handlesByOidDataFile
 void setMaxHandlesByOidCacheEntries(int maxHandlesByOidCacheEntries)
          Changes the size of the cache used to match Handles to Oids
 void shutdown()
          Makes sure modifications to cache entries are reflected in their persistent analogues.
protected abstract  void writeHandleForOid(Oid oid, Handle handle)
          Associates the given Handle to the given Oid in the file pointed by handlesByOidDataFile.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
serial version universal id - put here so Java does not insert one which may change due to revisions and make it impossible to deserialize earlier versions of serialized objects

handlesByOidDataFile

protected static BufferedRandomAccessFile handlesByOidDataFile
The file used to keep track of handles by Oid.

handlesByOidDataFileLocation

private static java.lang.String handlesByOidDataFileLocation
Used to find the file associating Handles to Oids.

maxHandlesByOidCacheEntries

private static int maxHandlesByOidCacheEntries
Initial size of the cache used to match handles to Oids.

handlesByOidCache

private static HashingCache handlesByOidCache
Cache for handles by Oid

fileSeparator

protected static final java.lang.String fileSeparator
Local copy of System file separator

handlesByOidAdds

private static transient long handlesByOidAdds
Statistics on handlesByOid table and cache.

handlesByOidRemoves

private static transient long handlesByOidRemoves

handlesByOidUpdates

private static transient long handlesByOidUpdates

handlesByOidGets

private static transient long handlesByOidGets

handlesByOidGetsFromCache

private static transient long handlesByOidGetsFromCache
Constructor Detail

HandlesByOid

public HandlesByOid()
Method Detail

openHandlesByOid

public void openHandlesByOid(java.lang.String directory)
Opens the handles-by-oid files
Parameters:
directory - directory in which to open the files

setHandlesByOidDataFileLocation

public final void setHandlesByOidDataFileLocation(java.lang.String location)
Sets the location of the handlesByOidDataFile
Parameters:
location - location of the handlesByOidDataFile

getMaxHandlesByOidCacheEntries

public final int getMaxHandlesByOidCacheEntries()
Returns the maximum number of entries in the cache
Returns:
the maximum number of entries in the cache

getHandlesByOidDataFileLocation

public final java.lang.String getHandlesByOidDataFileLocation()
Gets the location of the handlesByOidDataFile;
Returns:
the location of the handlesByOidDataFile

getStatistics

public java.lang.String getStatistics()
Returns a String that contains statistics about this table and the cache it embeds.

addHandleByOid

public void addHandleByOid(Oid oid,
                           Handle handle)
Adds a handle to the table of handles by Oid
Parameters:
handle - handle to be saved
Oid - object identified to be associated with the handle

writeHandleForOid

protected abstract void writeHandleForOid(Oid oid,
                                          Handle handle)
Associates the given Handle to the given Oid in the file pointed by handlesByOidDataFile. It will allow this matching to live even after shutdown. For the cache mechanism, see the class below:
Parameters:
oid - Oid for which a handle is to be written
handle - Handle to be associated with the specified Oid
See Also:
HashingCache

replaceHandleByOid

public void replaceHandleByOid(Oid oid,
                               Handle newHandle)
Replaces the entry in table of handles by Oid for the specified Oid with a new one using the same Oid the new handle passed. If no entry to replace exists, write an error message, but add the new entry and continue.
Parameters:
Oid - for desired handle
newHandle - the new handle to replace the existing one

getHandleByOid

public Handle getHandleByOid(Oid oid)
Gets a handle from the table of handles by Oid
Parameters:
Oid - for desired object/handle
Returns:
the handle associated with the specified Oid

readHandleForOid

protected abstract Handle readHandleForOid(Oid oid)
Reads the handle from the disk. This method is gonna specify the way files are used for storing Handles (index, no index, ...)

getHandlesByOidSize

public abstract long getHandlesByOidSize()
Gets the size of the table
Returns:
the number of keys (Oids) in the table

setMaxHandlesByOidCacheEntries

public void setMaxHandlesByOidCacheEntries(int maxHandlesByOidCacheEntries)
Changes the size of the cache used to match Handles to Oids
Parameters:
maxHandlesByOidCacheEntries - maximum number of entries allowed in handles by Oid cache

shutdown

public void shutdown()
Makes sure modifications to cache entries are reflected in their persistent analogues.