de.lmu.ifi.dbs.elki.persistent
Class PersistentPageFile<P extends Page>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.persistent.AbstractPageFile<P>
      extended by de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile<P>
          extended by de.lmu.ifi.dbs.elki.persistent.PersistentPageFile<P>
Type Parameters:
P - Page type
All Implemented Interfaces:
PageFile<P>, PageFileStatistics

public class PersistentPageFile<P extends Page>
extends AbstractStoringPageFile<P>

A PersistentPageFile stores objects persistently that implement the Page interface. For convenience each page is represented by a single file. All pages are stored in a specified directory.


Field Summary
private static int EMPTY_PAGE
          Indicates an empty page.
private  boolean existed
          Whether we are initializing from an existing file.
private  RandomAccessFile file
          The file storing the pages.
private static int FILLED_PAGE
          Indicates a filled page.
protected  PageHeader header
          The header of this page file.
private static Logging logger
          Our logger
protected  Class<P> pageclass
          The type of pages we use.
 
Fields inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile
emptyPages, nextPageID, pageSize
 
Fields inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractPageFile
readAccess, writeAccess
 
Constructor Summary
PersistentPageFile(int pageSize, String fileName, Class<P> pageclass)
          Creates a new PersistentPageFile from an existing file.
 
Method Summary
private  P byteArrayToPage(byte[] array)
          Reconstruct a serialized object from the specified byte array.
 void clear()
          Clears this PageFile.
 void close()
          Closes this file.
 void deletePage(int pageID)
          Deletes the node with the specified id from this file.
 RandomAccessFile getFile()
           
 PageHeader getHeader()
          Get the header of this persistent page file.
 void increaseReadAccess()
          Increases the readAccess counter by one.
 void increaseWriteAccess()
          Increases the writeAccess counter by one.
 boolean initialize(PageHeader header)
          Initialize the page file with the given header - return "true" if the file already existed.
private  byte[] pageToByteArray(P page)
          Serializes an object into a byte array.
 P readPage(int pageID)
          Reads the page with the given id from this file.
 void setNextPageID(int next_page_id)
          Set the next page id to the given value.
 void writePage(Integer pageID, P page)
          This method is called by the cache if the page is not longer stored in the cache and has to be written to disk.
 
Methods inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile
getInnerStatistics, getNextPageID, getPageSize, setPageID
 
Methods inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractPageFile
getReadOperations, getWriteOperations, resetPageAccess, writePage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Logging logger
Our logger


EMPTY_PAGE

private static final int EMPTY_PAGE
Indicates an empty page.

See Also:
Constant Field Values

FILLED_PAGE

private static final int FILLED_PAGE
Indicates a filled page.

See Also:
Constant Field Values

file

private final RandomAccessFile file
The file storing the pages.


header

protected PageHeader header
The header of this page file.


pageclass

protected final Class<P extends Page> pageclass
The type of pages we use.


existed

private boolean existed
Whether we are initializing from an existing file.

Constructor Detail

PersistentPageFile

public PersistentPageFile(int pageSize,
                          String fileName,
                          Class<P> pageclass)
Creates a new PersistentPageFile from an existing file.

Parameters:
pageSize - the page size
pageclass - the class of pages to be used
Method Detail

readPage

public P readPage(int pageID)
Reads the page with the given id from this file.

Parameters:
pageID - the id of the page to be returned
Returns:
the page with the given pageId

deletePage

public void deletePage(int pageID)
Deletes the node with the specified id from this file.

Specified by:
deletePage in interface PageFile<P extends Page>
Overrides:
deletePage in class AbstractStoringPageFile<P extends Page>
Parameters:
pageID - the id of the node to be deleted

writePage

public void writePage(Integer pageID,
                      P page)
This method is called by the cache if the page is not longer stored in the cache and has to be written to disk.

Specified by:
writePage in class AbstractPageFile<P extends Page>
Parameters:
page - the page which has to be written to disk
pageID - Page id

close

public void close()
Closes this file.

Specified by:
close in interface PageFile<P extends Page>
Overrides:
close in class AbstractPageFile<P extends Page>

clear

public void clear()
Clears this PageFile.


byteArrayToPage

private P byteArrayToPage(byte[] array)
Reconstruct a serialized object from the specified byte array.

Parameters:
array - the byte array from which the object should be reconstructed
Returns:
a serialized object from the specified byte array

pageToByteArray

private byte[] pageToByteArray(P page)
Serializes an object into a byte array.

Parameters:
page - the object to be serialized
Returns:
the byte array

getFile

public RandomAccessFile getFile()
Returns:
the random access file storing the pages.

getHeader

public PageHeader getHeader()
Get the header of this persistent page file.

Returns:
the header used by this page file

increaseReadAccess

public void increaseReadAccess()
Increases the readAccess counter by one.


increaseWriteAccess

public void increaseWriteAccess()
Increases the writeAccess counter by one.


setNextPageID

public void setNextPageID(int next_page_id)
Set the next page id to the given value. If this means that any page ids stored in emptyPages are smaller than next_page_id, they are removed from this file's observation stack.

Specified by:
setNextPageID in interface PageFile<P extends Page>
Overrides:
setNextPageID in class AbstractStoringPageFile<P extends Page>
Parameters:
next_page_id - the id of the next page to be inserted (if there are no more empty pages to be filled)

initialize

public boolean initialize(PageHeader header)
Description copied from class: AbstractStoringPageFile
Initialize the page file with the given header - return "true" if the file already existed.

Specified by:
initialize in interface PageFile<P extends Page>
Overrides:
initialize in class AbstractStoringPageFile<P extends Page>
Parameters:
header - Header
Returns:
true when the file already existed.

Release 0.4.0 (2011-09-20_1324)