O2Plib.db.CSD
Class CSDcache

java.lang.Object
  extended by O2Plib.db.CSD.CSDglb
      extended by O2Plib.db.CSD.CSDcache

public class CSDcache
extends CSDglb

Class CSDcache supports multiple memory and multiple disk caches for supporting a single Composite Samples Database for Open2Dprot programs.

There are nMemCaches memory caches and nDiskCaches disk caches. They all point to chunks of the CSD database. The CSD database can be either filled from a binary random access file (initial design), an XML data file, and from a RDBMS (local or net-based).

The caches allow multiple access to different cross sections of the database to make it easier to do clustering and other methods where there is comparison of Rspot expression from disparate sections of the database.

This file is derived from GELLAB-II C code and MAExplorer code


 This work was produced by Peter Lemkin of the National Cancer
 Institute, an agency of the United States Government.  As a work of
 the United States Government there is no associated copyright.  It is
 offered as open source software under the Mozilla Public License
 (version 1.1) subject to the limitations noted in the accompanying
 LEGAL file. This notice must be included with the code. The Open2Dprot
 Mozilla and Legal files are available on http://Open2Dprot.sourceforge.net/.

Version:
$Date: 2005/12/09 15:04:26 $ $Revision: 1.10 $
Author:
P. Lemkin, NCI-Frederick, Frederick, MD, 21702

Field Summary
 java.io.RandomAccessFile[] diskCacheFD
          [0:nDiskCaches-1] list of disk cache Random Access Files
 long[] diskCacheFilePtr
          [0:nDiskCaches-1] list of disk cache file pointers in CSD database
 byte[][] diskCacheList
          [0:nDiskCaches-1][0:diskCacheSize-1(variable)] list of CSD disk caches
 java.lang.String[] diskCacheName
          [0:nDiskCaches-1] list of disk cache file names
 int[] diskCacheSize
          [0:nDiskCaches-1] list of disk cache list sizes
 long[] diskCacheTimeStamp
          [0:nDiskCaches-1] list of disk cache time stamps
 boolean[] diskCacheValid
          [0:nDiskCaches-1] list of valid disk caches
static int diskTimeStampCtr
          disk cache time stamp for aging cache
 int maxDiskCaches
          maximum number of CSD disk caches
 int maxDiskCachesSize
          maximum number of CSD disk caches
 int maxMemCaches
          maximum number of CSD memory caches
 int maxMemCachesSize
          maximum number of CSD memory caches
 long[] memCacheFilePtr
          [0:nMemCaches-1] list of cache file pointers in CSD database
 byte[][] memCacheList
          [0:nMemCaches-1][0:memCacheSize-1(variable)] list of CSD memory caches
 int[] memCacheSize
          [0:nMemCaches-1] list of memory cache list sizes
 long[] memCacheTimeStamp
          [0:nMemCaches-1] list of memory cache time stamps
 boolean[] memCacheValid
          [0:nMemCaches-1] list of valid memory caches
static int memTimeStampCtr
          memory cache time stamp for aging cache
 int nDiskCaches
          number of CSD disk caches
 int nMemCaches
          number of CSD memory caches
static java.lang.String VERSION
          Version for this module
 
Fields inherited from class O2Plib.db.CSD.CSDglb
allSetSamples, AP, batchDir, BF_IS_LMS_SPOT, BF_ISVALIDSPOT, cacheDir, cdbIsOpenFlag, condListDB, CONSOLE_FLAG, CP, CSD_DBTYPE_CACHE, CSD_DBTYPE_RDBMS, CSD_DBTYPE_TAB_DELIM, CSD_DBTYPE_UNKNOWN, CSD_DBTYPE_XML, csdAcc, csdCache, csdCacheFile, csdDatabaseFile, csdFormatMode, csdIO, csdLMS, csdName, csdRdbmsFile, csdSizes, csdTabDelimFile, csdTotals, CSDversion, csdXMLfile, dataFiltersListDB, dateCreation, dateLastSession, dbRsample, dbSample, dbSamplesListDB, dbSPFlistsDB, dBugLMsetNbr, dBugPspotNbr, dBugRspotNbr, dBugSampleNbr, EP, epSetSamples, exprListsDB, GS, LM, MAX_NODE_SAFTY_FACTOR, mrl, nbrTimesInitialized, nCondListDB, nDataFiltersDB, needToSaveCSDdataFlag, NEVER, nExprListsDB, nOclDB, nodeSaftyFactor, normListDB, nRmapsDB, nRspotListsDB, nSamplesDB, nSPFfilesUsedDB, nSPFlistsDB, oclListDB, oclNameDB, PP, ppxDir, projDir, rdbmsDir, rMapsListDB, RSAMPLE, rspotListsDB, SAMPLE, sampleNamesDB, sampleNamesUsedDB, SP, tmpDir, US, useInternalDTDflag, wrkAnotation, wrkCalib, wrkERspot, wrkExpr, wrkSetSamples, xmlDir, xSetSamples, ySetSamples
 
Constructor Summary
CSDcache()
          CSDcache() - Constructor for new CSDcache.
CSDcache(int maxMemCachesSize, int maxMemCaches, int maxDiskCachesSize, int maxDiskCaches)
          CSDcache() - Constructor for new CSD.
 
Method Summary
 boolean createNewEmptyCGLdbFile(java.lang.String fileName, long maxFileSize)
          createNewEmptyCGLdbFile() - Create a zeroed CSD cache database file called fileName.
 int findFreeDiskCache(int desiredSize)
          findFreeDiskCache() - find first free disk cache.
 int findFreeMemCache(int desiredSize)
          findFreeMemCache() - find first free memory cache.If no cache is free, then pick the oldest one and flush it to the CSD database if valid and reuse that cache.
 boolean flushAllCachesToCSDdbFile()
          flushAllCachesToCSDdbFile() - flush the cache (memory and disk) to the CSD database file.
 boolean flushAllMemCacheToDiskCache()
          flushAllMemCacheToDiskCache() - flush the memory cache to the disk cache.
 boolean flushMemCacheToDiskCache(int memCacheNbr)
          flushMemCacheToDiskCache() - flush the memory cache to the disk cache.
 boolean getMemCacheFromDiskCache(int memCacheNbr, int diskCacheNbr)
          getMemCacheFromDiskCache() - get the memory cache from the disk cache up to the maximum memory cache size if needed.
 void initCacheLists()
          initCacheLists() - init cache lists.
 
Methods inherited from class O2Plib.db.CSD.CSDglb
initGlb
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Version for this module

See Also:
Constant Field Values

memTimeStampCtr

public static int memTimeStampCtr
memory cache time stamp for aging cache


diskTimeStampCtr

public static int diskTimeStampCtr
disk cache time stamp for aging cache


maxMemCachesSize

public int maxMemCachesSize
maximum number of CSD memory caches


maxMemCaches

public int maxMemCaches
maximum number of CSD memory caches


memCacheList

public byte[][] memCacheList
[0:nMemCaches-1][0:memCacheSize-1(variable)] list of CSD memory caches


memCacheSize

public int[] memCacheSize
[0:nMemCaches-1] list of memory cache list sizes


memCacheValid

public boolean[] memCacheValid
[0:nMemCaches-1] list of valid memory caches


memCacheTimeStamp

public long[] memCacheTimeStamp
[0:nMemCaches-1] list of memory cache time stamps


memCacheFilePtr

public long[] memCacheFilePtr
[0:nMemCaches-1] list of cache file pointers in CSD database


nMemCaches

public int nMemCaches
number of CSD memory caches


maxDiskCachesSize

public int maxDiskCachesSize
maximum number of CSD disk caches


maxDiskCaches

public int maxDiskCaches
maximum number of CSD disk caches


diskCacheList

public byte[][] diskCacheList
[0:nDiskCaches-1][0:diskCacheSize-1(variable)] list of CSD disk caches


diskCacheSize

public int[] diskCacheSize
[0:nDiskCaches-1] list of disk cache list sizes


diskCacheName

public java.lang.String[] diskCacheName
[0:nDiskCaches-1] list of disk cache file names


diskCacheFD

public java.io.RandomAccessFile[] diskCacheFD
[0:nDiskCaches-1] list of disk cache Random Access Files


diskCacheValid

public boolean[] diskCacheValid
[0:nDiskCaches-1] list of valid disk caches


diskCacheTimeStamp

public long[] diskCacheTimeStamp
[0:nDiskCaches-1] list of disk cache time stamps


diskCacheFilePtr

public long[] diskCacheFilePtr
[0:nDiskCaches-1] list of disk cache file pointers in CSD database


nDiskCaches

public int nDiskCaches
number of CSD disk caches

Constructor Detail

CSDcache

public CSDcache()
CSDcache() - Constructor for new CSDcache.


CSDcache

public CSDcache(int maxMemCachesSize,
                int maxMemCaches,
                int maxDiskCachesSize,
                int maxDiskCaches)
CSDcache() - Constructor for new CSD. Note: caches are allocated as needed.

Parameters:
maxMemCachesSize - is max size of memory caches
maxMemCaches - is max # of memory caches
maxDiskCachesSize - is max size of disk caches
maxDiskCaches - is max # of disk caches
Method Detail

initCacheLists

public void initCacheLists()
initCacheLists() - init cache lists. There are no caches created until they are needed.


flushAllMemCacheToDiskCache

public boolean flushAllMemCacheToDiskCache()
flushAllMemCacheToDiskCache() - flush the memory cache to the disk cache. [TODO]

Returns:
true if succeed whether neede to flush it or not.

flushMemCacheToDiskCache

public boolean flushMemCacheToDiskCache(int memCacheNbr)
flushMemCacheToDiskCache() - flush the memory cache to the disk cache. [TODO]

Returns:
true if succeed whether neede to flush it or not.

getMemCacheFromDiskCache

public boolean getMemCacheFromDiskCache(int memCacheNbr,
                                        int diskCacheNbr)
getMemCacheFromDiskCache() - get the memory cache from the disk cache up to the maximum memory cache size if needed. [TODO]

Returns:
true if succeed whether need to flush it or not.

flushAllCachesToCSDdbFile

public boolean flushAllCachesToCSDdbFile()
flushAllCachesToCSDdbFile() - flush the cache (memory and disk) to the CSD database file. First flush memory caches to the CSD file. Then load disk caches to the memory cache and flush those as well. [TODO]

Returns:
true if succeed whether neede to flush it or not.

findFreeMemCache

public int findFreeMemCache(int desiredSize)
findFreeMemCache() - find first free memory cache.If no cache is free, then pick the oldest one and flush it to the CSD database if valid and reuse that cache.

Parameters:
desiredSize - if not null, else use maxMemCachesSize
Returns:
cache number if found, -1 if not

findFreeDiskCache

public int findFreeDiskCache(int desiredSize)
findFreeDiskCache() - find first free disk cache. If no cache is free, then pick the oldest one and flush CSD database if valid and reuse that cache.

Parameters:
desiredSize - if not null, else use maxMemCachesSize
forceFindFlag - to flush a buffer if not used.
Returns:
cache number if found, -1 if not

createNewEmptyCGLdbFile

public boolean createNewEmptyCGLdbFile(java.lang.String fileName,
                                       long maxFileSize)
createNewEmptyCGLdbFile() - Create a zeroed CSD cache database file called fileName. The zeroed file has a '.cache' extension. Close after creating it, since it will be reopened when it is first used for I/O.

Parameters:
fileName - of the database file
maxFileSize - of the file to create
Returns:
true if succeed