Class PageArray
java.lang.Object
org.cojen.tupl.io.PageArray
- All Implemented Interfaces:
Closeable
,AutoCloseable
,CauseCloseable
- Direct Known Subclasses:
FilePageArray
,MappedPageArray
,SpilloverPageArray
,StripedPageArray
Defines a persistent, array of fixed sized pages. Each page is uniquely
identified by a 64-bit index, starting at zero.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
abstract void
long
copyPage
(long srcIndex, long dstIndex) long
copyPageFromAddress
(long srcAddr, long dstIndex) long
directPageAddress
(long index) int
Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.long
dirtyPage
(long index) Indicate that the contents of the given page will be modified.long
evictPage
(long index, long bufAddr) Same as writePage, except that the given buffer might be altered and a replacement might be returned.abstract void
expandPageCount
(long count) Attempt to expand the total count of pages.abstract boolean
isClosed()
final boolean
abstract boolean
isEmpty()
boolean
abstract boolean
abstract long
Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.long
Return maximum allowed page count, or -1 if not applicable.final int
pageSize()
Returns the fixed size of all pages in the array, in bytes.void
readPage
(long index, long dstAddr) abstract void
readPage
(long index, long dstAddr, int offset, int length) abstract void
sync
(boolean metadata) Durably flushes all writes to the underlying device.void
syncPage
(long index) Durably flushes the page at the given index, but implementation might flush more pages.abstract void
truncatePageCount
(long count) Attempt to truncate the total count of pages.void
writePage
(long index, long srcAddr) Writes a page, which is lazily flushed.abstract void
writePage
(long index, long srcAddr, int offset) Writes a page, which is lazily flushed.
-
Constructor Details
-
PageArray
protected PageArray(int pageSize)
-
-
Method Details
-
isDirectIO
public final boolean isDirectIO() -
pageSize
public final int pageSize()Returns the fixed size of all pages in the array, in bytes. -
directPageSize
public int directPageSize()Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O. -
isFullyMapped
public boolean isFullyMapped() -
isReadOnly
public abstract boolean isReadOnly() -
isEmpty
- Throws:
IOException
-
pageCount
Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.- Throws:
IOException
-
truncatePageCount
Attempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.- Throws:
IllegalArgumentException
- if count is negativeIOException
-
expandPageCount
Attempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.- Throws:
IllegalArgumentException
- if count is negativeIOException
-
pageCountLimit
Return maximum allowed page count, or -1 if not applicable.- Throws:
IOException
-
readPage
- Parameters:
index
- zero-based page index to readdstAddr
- receives read data- Throws:
IndexOutOfBoundsException
- if index is negativeIOException
- if index is greater than or equal to page count
-
readPage
- Parameters:
index
- zero-based page index to readdstAddr
- receives read dataoffset
- offset into data buffer- Throws:
IndexOutOfBoundsException
- if index is negativeIOException
- if index is greater than or equal to page count
-
writePage
Writes a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.- Parameters:
index
- zero-based page index to writesrcAddr
- data to write- Throws:
IndexOutOfBoundsException
- if index is negativeIOException
-
writePage
Writes a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.- Parameters:
index
- zero-based page index to writesrcAddr
- data to writeoffset
- offset into data buffer- Throws:
IndexOutOfBoundsException
- if index is negativeIOException
-
evictPage
Same as writePage, except that the given buffer might be altered and a replacement might be returned. Caller must not alter the original buffer if a replacement was provided, and the contents of the replacement are undefined.- Parameters:
index
- zero-based page index to writebufAddr
- data to write; implementation might alter the contents- Returns:
- replacement buffer, or same instance if replacement was not performed
- Throws:
IndexOutOfBoundsException
- if index is negativeIOException
-
directPageAddress
- Throws:
IOException
-
dirtyPage
Indicate that the contents of the given page will be modified. Permits the implementation to make a copy of the existing page contents, if it supports snapshotting.- Returns:
- direct pointer to destination
- Throws:
IOException
-
copyPage
- Returns:
- direct pointer to destination
- Throws:
IOException
-
copyPageFromAddress
- Returns:
- direct pointer to destination
- Throws:
IOException
-
sync
Durably flushes all writes to the underlying device.- Parameters:
metadata
- pass true to flush all file metadata- Throws:
IOException
-
syncPage
Durably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
close
- Specified by:
close
in interfaceCauseCloseable
- Parameters:
cause
- null if close is not caused by a failure- Throws:
IOException
-
isClosed
public abstract boolean isClosed()
-