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 thePage
interface. 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 int
EMPTY_PAGE
Indicates an empty page.private boolean
existed
Whether we are initializing from an existing file.private java.nio.channels.FileChannel
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
LOG
Our loggerprotected java.lang.Class<P>
pageclass
The 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 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.java.nio.channels.FileChannel
getFile()
PageHeader
getHeader()
Get the header of this persistent page file.protected Logging
getLogger()
Get the class logger.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(int pageID, P page)
This method is called by the cache if thepage
is 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:
deletePage
in interfacePageFile<P extends ExternalizablePage>
- Overrides:
deletePage
in 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 thepage
is not longer stored in the cache and has to be written to disk.- Specified by:
writePage
in 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:
close
in interfacePageFile<P extends ExternalizablePage>
- Overrides:
close
in 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 inemptyPages
are smaller thannext_page_id
, they are removed from this file's observation stack.- Specified by:
setNextPageID
in interfacePageFile<P extends ExternalizablePage>
- Overrides:
setNextPageID
in 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:AbstractStoringPageFile
Initialize the page file with the given header - return "true" if the file already existed.- Specified by:
initialize
in interfacePageFile<P extends ExternalizablePage>
- Overrides:
initialize
in classAbstractStoringPageFile<P extends ExternalizablePage>
- Parameters:
header
- Header- Returns:
- true when the file already existed.
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractPageFile
Get the class logger.- Specified by:
getLogger
in classAbstractPageFile<P extends ExternalizablePage>
- Returns:
- Logger
-
-