org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class FileCache

java.lang.Object
  extended by org.netbeans.mdr.persistence.btreeimpl.btreestorage.FileCache

public class FileCache
extends java.lang.Object

FileCache provides transactional cached access to a set of files. Changes to these files are accumulated both in memory and on disk until a commit is requested, at which time they are flushed to disk. If the program exits for any reason without comitting, any changes which were written to disk are rolled back to the last commit point the next time the FileCache is opened.


Nested Class Summary
static interface FileCache.NotifyOnCommit
          An object which needs to be notified before the cache commits (for instance, to write any changes to the cache before the cache is flushed to disk) implements this interface, and calls addNotifier on the cache.
 
Constructor Summary
FileCache(int pgSize, int numBufs, java.lang.String[] names, java.lang.String logName)
          Create the cache and open the files.
 
Method Summary
 void abort()
          close all files without comitting
 void addNotifier(FileCache.NotifyOnCommit notified)
          Add to the list of objects to be notified before commit
 void close()
          commit all changes and close all cached files
 void commit()
          commit all changes
 void dumpCache(java.io.PrintStream strm)
          for debugging
 CachedPage getPage(int fileidx, int pageNum)
          Get the single page at the desired offset into the file This implicitly pins that pages.
 CachedPage[] getPages(int fileidx, int first, int size)
          Get the pages which contain the desired bytes from the file This implicitly pins these pages.
 void setWritable(CachedPage page)
          Make the specified page writable.
 void setWritable(CachedPage[] pages)
          Make the specified pages writable.
 void showStats(java.io.PrintStream strm)
          Show caching statistics
 void showStats(java.io.PrintWriter strm)
          Show caching statistics
 void unpin(CachedPage page)
          unpin a page.
 void unpin(CachedPage[] pages)
          unpin a set of pages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCache

public FileCache(int pgSize,
                 int numBufs,
                 java.lang.String[] names,
                 java.lang.String logName)
          throws StorageException
Create the cache and open the files. The files are assumed already to exist and have valid, identical file headers.

Parameters:
pgSize - the cache's page size
numBufs - the number of page buffers to create
names - the files to access via the cache
logName - the name of the log file
Throws:
StorageException - I/O error opening or reading the files
BadParameterException - if the file do not have identical file headers, or the log file exists but is not consistent with the files
ConsistencyException - if the log file exists and is corrupted
Method Detail

abort

public void abort()
           throws StorageException
close all files without comitting

Throws:
StorageException - I/O error closing the files

close

public void close()
           throws StorageException
commit all changes and close all cached files

Throws:
StorageException - I/O error closing the files

commit

public void commit()
            throws StorageException
commit all changes

Throws:
StorageException - I/O error writing the files

unpin

public void unpin(CachedPage[] pages)
           throws StorageException
unpin a set of pages. Until unpinned the same number of times that they have been pinned, pages cannot be released from the cache.

Parameters:
pages - the pages to unpin
Throws:
BadParameterException - if the page is not pinned
StorageException

unpin

public void unpin(CachedPage page)
           throws StorageException
unpin a page. Until unpinned the same number of times it has been pinned, a page cannot be released from the cache.

Parameters:
page - the page to unpin
Throws:
BadParameterException - if any of the pages are not pinned
StorageException

getPages

public CachedPage[] getPages(int fileidx,
                             int first,
                             int size)
                      throws StorageException
Get the pages which contain the desired bytes from the file This implicitly pins these pages. Note that these pages may extend past the current EOF; that is, this routine may extend the file.

Parameters:
fileidx - the index of the file containing the page.
first - the number of the first page to get
length - the number of pages to get
Returns:
the array of pages requested.
Throws:
StorageException - I/O error reading the pages

getPage

public CachedPage getPage(int fileidx,
                          int pageNum)
                   throws StorageException
Get the single page at the desired offset into the file This implicitly pins that pages. Note that this may may exist past the current EOF; that is, this routine may extend the file.

Parameters:
fileidx - the index of the file containing the page.
pageNum - the page number to get
Returns:
the page requested
Throws:
StorageException - I/O error reading the page

setWritable

public void setWritable(CachedPage page)
                 throws StorageException
Make the specified page writable. If it was not writable previously, this causes it to be logged. This must be called before the page is modified. If the cache is not currently in a transaction, this implicitly begins one.

Parameters:
page - The page to be made writable.
Throws:
StorageException - I/O error logging the page

setWritable

public void setWritable(CachedPage[] pages)
                 throws StorageException
Make the specified pages writable. If any were not writable previously, this causes them to be logged. This be called before the pages are modified.

Parameters:
pages - The pages to be made writable.
Throws:
StorageException - I/O error logging the pages

dumpCache

public void dumpCache(java.io.PrintStream strm)
for debugging


showStats

public void showStats(java.io.PrintStream strm)
Show caching statistics


showStats

public void showStats(java.io.PrintWriter strm)
Show caching statistics


addNotifier

public void addNotifier(FileCache.NotifyOnCommit notified)
Add to the list of objects to be notified before commit

Parameters:
notified - the obect to add to the list


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.