Package elki.persistent
Class PersistentPageFile<P extends ExternalizablePage>
- java.lang.Object
-
- elki.persistent.AbstractPageFile<P>
-
- elki.persistent.AbstractStoringPageFile<P>
-
- elki.persistent.PersistentPageFile<P>
-
- Type Parameters:
P- Page type
- All Implemented Interfaces:
PageFile<P>
public class PersistentPageFile<P extends ExternalizablePage> extends AbstractStoringPageFile<P>
A PersistentPageFile stores objects persistently that implement thePageinterface. For convenience each page is represented by a single file. All pages are stored in a specified directory.- Since:
- 0.1
- Author:
- Elke Achtert
-
-
Field Summary
Fields Modifier and Type Field Description private static intEMPTY_PAGEIndicates an empty page.private booleanexistedWhether we are initializing from an existing file.private java.nio.channels.FileChannelfileThe file storing the pages.private static intFILLED_PAGEIndicates a filled page.protected PageHeaderheaderThe header of this page file.private static LoggingLOGOur loggerprotected java.lang.Class<P>pageclassThe type of pages we use.-
Fields inherited from class elki.persistent.AbstractStoringPageFile
emptyPages, nextPageID, pageSize
-
-
Constructor Summary
Constructors Constructor Description PersistentPageFile(int pageSize, java.nio.file.Path filename, java.lang.Class<P> pageclass)Creates a new PersistentPageFile from an existing file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private PbyteArrayToPage(byte[] array)Reconstruct a serialized object from the specified byte array.voidclear()Clears this PageFile.voidclose()Closes this file.voiddeletePage(int pageID)Deletes the node with the specified id from this file.java.nio.channels.FileChannelgetFile()PageHeadergetHeader()Get the header of this persistent page file.protected LogginggetLogger()Get the class logger.booleaninitialize(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.PreadPage(int pageID)Reads the page with the given id from this file.voidsetNextPageID(int next_page_id)Set the next page id to the given value.voidwritePage(int pageID, P page)This method is called by the cache if thepageis not longer stored in the cache and has to be written to disk.-
Methods inherited from class elki.persistent.AbstractStoringPageFile
getNextPageID, getPageSize, logStatistics, setPageID
-
Methods inherited from class elki.persistent.AbstractPageFile
countRead, countWrite, writePage
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
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 java.nio.channels.FileChannel file
The file storing the pages.
-
header
protected PageHeader header
The header of this page file.
-
pageclass
protected final java.lang.Class<P extends ExternalizablePage> 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, java.nio.file.Path filename, java.lang.Class<P> pageclass)Creates a new PersistentPageFile from an existing file.- Parameters:
pageSize- the page sizepageclass- 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:
deletePagein interfacePageFile<P extends ExternalizablePage>- Overrides:
deletePagein classAbstractStoringPageFile<P extends ExternalizablePage>- Parameters:
pageID- the id of the node to be deleted
-
writePage
public void writePage(int pageID, P page)This method is called by the cache if thepageis not longer stored in the cache and has to be written to disk.- Specified by:
writePagein classAbstractPageFile<P extends ExternalizablePage>- Parameters:
page- the page which has to be written to diskpageID- Page id
-
close
public void close()
Closes this file.- Specified by:
closein interfacePageFile<P extends ExternalizablePage>- Overrides:
closein classAbstractPageFile<P extends ExternalizablePage>
-
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 java.nio.channels.FileChannel 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
-
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 inemptyPagesare smaller thannext_page_id, they are removed from this file's observation stack.- Specified by:
setNextPageIDin interfacePageFile<P extends ExternalizablePage>- Overrides:
setNextPageIDin classAbstractStoringPageFile<P extends ExternalizablePage>- 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:AbstractStoringPageFileInitialize the page file with the given header - return "true" if the file already existed.- Specified by:
initializein interfacePageFile<P extends ExternalizablePage>- Overrides:
initializein classAbstractStoringPageFile<P extends ExternalizablePage>- Parameters:
header- Header- Returns:
- true when the file already existed.
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractPageFileGet the class logger.- Specified by:
getLoggerin classAbstractPageFile<P extends ExternalizablePage>- Returns:
- Logger
-
-