com.sun.electric.database.geometry.btree
Class CachingPageStorageWrapper

java.lang.Object
  extended by com.sun.electric.database.geometry.btree.PageStorage
      extended by com.sun.electric.database.geometry.btree.CachingPageStorage
          extended by com.sun.electric.database.geometry.btree.CachingPageStorageWrapper

public class CachingPageStorageWrapper
extends CachingPageStorage

A wrapper around PageStorage that makes it a CachingPageStorage. This class is thread-safe; overlapped read/write and write/write pairs may produce undefined data, but are otherwise safe.


Nested Class Summary
 class CachingPageStorageWrapper.CachedPageImpl
          A page which is currently in the cache.
 
Nested classes/interfaces inherited from class com.sun.electric.database.geometry.btree.CachingPageStorage
CachingPageStorage.CachedPage
 
Constructor Summary
CachingPageStorageWrapper(PageStorage ps, int cacheSize, boolean asyncFlush)
          An evicted page will be freed from memory (garbage collected) if the user of this class has not retained a reference to it; otherwise it simply no longer counts towards the maximum cache size.
 
Method Summary
 void close()
          close the PageStorage; invocation of any other methods after close() has undefined results
 int createPage()
          creates a new page with undefined contents; returns its pageid
 void fsync()
          ensure that the all pages are written to nonvolatile storage
 void fsync(int pageid)
          ensure that the designated page is written to nonvolatile storage
 int getNumPages()
          returns the number of pages; all pageids strictly less than this are valid
 CachingPageStorage.CachedPage getPage(int pageid, boolean readBytes)
          Creates space in the cache for pageid, but only actually reads the bytes if readBytes is true.
 void readPage(int pageid, byte[] buf, int ofs)
          reads a page
 void setCacheSize(int cacheSize)
          Sets the cache size, evicting pages if necessary.
 void writePage(int pageid, byte[] buf, int ofs)
          Write a page through the cache to nonvolatile storage
 
Methods inherited from class com.sun.electric.database.geometry.btree.PageStorage
getPageSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingPageStorageWrapper

public CachingPageStorageWrapper(PageStorage ps,
                                 int cacheSize,
                                 boolean asyncFlush)
An evicted page will be freed from memory (garbage collected) if the user of this class has not retained a reference to it; otherwise it simply no longer counts towards the maximum cache size. For this reason, applications should avoid holding a reference to a CachedPage for a long time. A CachingPageStorageWrapper with a limit of zero is useful! All of its pages are always in the evicted state and it will act as a "buffer manager" for classes that do not want to manage their own byte[] pools.

Parameters:
cacheSize - the maximum number of non-evicted PAGES in the cache. Note that the total number of pages (evicted and non-evicted) may exceed this number; this class simply ensures that once a page is evicted its reference to the page is weak. If the client application still holds a reference to that page it will not be garbage collected.
asyncFlush - if true, a background thread will make a best-effort attempt to flush dirty pages even before a flush() is explicitly requested.
Method Detail

createPage

public int createPage()
Description copied from class: PageStorage
creates a new page with undefined contents; returns its pageid

Specified by:
createPage in class PageStorage

getNumPages

public int getNumPages()
Description copied from class: PageStorage
returns the number of pages; all pageids strictly less than this are valid

Specified by:
getNumPages in class PageStorage

getPage

public CachingPageStorage.CachedPage getPage(int pageid,
                                             boolean readBytes)
Creates space in the cache for pageid, but only actually reads the bytes if readBytes is true. If the page was not already in the cache and readBytes is false, subsequent calls to setDirty()/flush() will overwrite data previously on the page.

Specified by:
getPage in class CachingPageStorage

writePage

public void writePage(int pageid,
                      byte[] buf,
                      int ofs)
Description copied from class: CachingPageStorage
Write a page through the cache to nonvolatile storage

Specified by:
writePage in class CachingPageStorage

readPage

public void readPage(int pageid,
                     byte[] buf,
                     int ofs)
Description copied from class: PageStorage
reads a page

Specified by:
readPage in class PageStorage

setCacheSize

public void setCacheSize(int cacheSize)
Sets the cache size, evicting pages if necessary.


fsync

public void fsync(int pageid)
Description copied from class: PageStorage
ensure that the designated page is written to nonvolatile storage

Specified by:
fsync in class PageStorage

fsync

public void fsync()
Description copied from class: PageStorage
ensure that the all pages are written to nonvolatile storage

Specified by:
fsync in class PageStorage

close

public void close()
Description copied from class: PageStorage
close the PageStorage; invocation of any other methods after close() has undefined results

Specified by:
close in class PageStorage