java.lang.Object
org.cojen.tupl.io.PageArray
- All Implemented Interfaces:
Closeable,AutoCloseable,CauseCloseable
- Direct Known Subclasses:
FilePageArray,JoinedPageArray,MappedPageArray,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 TypeMethodDescriptionvoidclose()abstract voidlongcopyPage(long srcIndex, long dstIndex) longcopyPageFromPointer(long srcPointer, long dstIndex) longdirectPagePointer(long index) intReturns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.longdirtyPage(long index) Indicate that the contents of the given page will be modified.byte[]evictPage(long index, byte[] buf) Same as writePage, except that the given buffer might be altered and a replacement might be returned.longevictPage(long index, long bufPtr) Same as writePage, except that the given buffer might be altered and a replacement might be returned.abstract voidexpandPageCount(long count) Attempt to expand the total count of pages.final booleanabstract booleanisEmpty()booleanabstract booleanopen()Attempt to open or reopen the page array.abstract longReturns the total count of pages in the array, or Long.MAX_VALUE if not applicable.longReturn maximum allowed page count, or -1 if not applicable.final intpageSize()Returns the fixed size of all pages in the array, in bytes.voidreadPage(long index, byte[] dst) abstract voidreadPage(long index, byte[] dst, int offset, int length) voidreadPage(long index, byte[] dst, int offset, int length, ByteBuffer tail) voidreadPage(long index, long dstPtr) voidreadPage(long index, long dstPtr, int offset, int length) voidreadPage(long index, long dstPtr, int offset, int length, ByteBuffer tail) abstract voidsync(boolean metadata) Durably flushes all writes to the underlying device.voidsyncPage(long index) Durably flushes the page at the given index, but implementation might flush more pages.abstract voidtruncatePageCount(long count) Attempt to truncate the total count of pages.voidwritePage(long index, byte[] src) Writes a page, which is lazily flushed.abstract voidwritePage(long index, byte[] src, int offset) Writes a page, which is lazily flushed.abstract voidwritePage(long index, byte[] src, int offset, ByteBuffer tail) voidwritePage(long index, long srcPtr) Writes a page, which is lazily flushed.voidwritePage(long index, long srcPtr, int offset) Writes a page, which is lazily flushed.voidwritePage(long index, long srcPtr, int offset, ByteBuffer tail)
-
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 readdst- 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 readdst- receives read dataoffset- offset into data buffer- Throws:
IndexOutOfBoundsException- if index is negativeIOException- if index is greater than or equal to page count
-
readPage
public void readPage(long index, byte[] dst, int offset, int length, ByteBuffer tail) throws IOException - Throws:
IOException
-
readPage
- Parameters:
index- zero-based page index to readdstPtr- 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 readdstPtr- receives read dataoffset- offset into data buffer- Throws:
IndexOutOfBoundsException- if index is negativeIOException- if index is greater than or equal to page count
-
readPage
public void readPage(long index, long dstPtr, int offset, int length, ByteBuffer tail) throws IOException - Throws:
IOException
-
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 writesrc- 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 writesrc- data to writeoffset- offset into data buffer- Throws:
IndexOutOfBoundsException- if index is negativeIOException
-
writePage
public abstract void writePage(long index, byte[] src, int offset, ByteBuffer tail) throws IOException - Throws:
IOException
-
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 writesrcPtr- 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 writesrcPtr- data to writeoffset- offset into data buffer- Throws:
IndexOutOfBoundsException- if index is negativeIOException
-
writePage
- Throws:
IOException
-
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 writebuf- 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
-
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 writebufPtr- 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
-
directPagePointer
- 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
-
copyPageFromPointer
- 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
close
- Specified by:
closein interfaceCauseCloseable- Parameters:
cause- null if close is not caused by a failure- Throws:
IOException
-
open
Attempt to open or reopen the page array.- Returns:
- existing or new page array
- Throws:
IOException
-