Class MappedPageArray

java.lang.Object
org.cojen.tupl.io.PageArray
org.cojen.tupl.io.MappedPageArray
All Implemented Interfaces:
Closeable, AutoCloseable, CauseCloseable

public abstract class MappedPageArray extends PageArray
PageArray implementation which accesses a fixed sized file, fully mapped to memory.
  • Method Details

    • isSupported

      public static boolean isSupported()
    • open

      public static MappedPageArray open(int pageSize, long pageCount, File file, EnumSet<OpenOption> options) throws IOException
      Parameters:
      file - file to store pages, or null if anonymous
      Throws:
      UnsupportedOperationException - if not running on a 64-bit platform
      IOException
    • isFullyMapped

      public final boolean isFullyMapped()
      Overrides:
      isFullyMapped in class PageArray
    • isReadOnly

      public final boolean isReadOnly()
      Specified by:
      isReadOnly in class PageArray
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in class PageArray
    • pageCount

      public long pageCount()
      Description copied from class: PageArray
      Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.
      Specified by:
      pageCount in class PageArray
    • truncatePageCount

      public void truncatePageCount(long count)
      Description copied from class: PageArray
      Attempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.
      Specified by:
      truncatePageCount in class PageArray
    • expandPageCount

      public void expandPageCount(long count)
      Description copied from class: PageArray
      Attempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.
      Specified by:
      expandPageCount in class PageArray
    • pageCountLimit

      public long pageCountLimit()
      Description copied from class: PageArray
      Return maximum allowed page count, or -1 if not applicable.
      Overrides:
      pageCountLimit in class PageArray
    • readPage

      public void readPage(long index, byte[] dst, int offset, int length) throws IOException
      Specified by:
      readPage in class PageArray
      Parameters:
      index - zero-based page index to read
      dst - receives read data
      offset - offset into data buffer
      Throws:
      IOException - 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
      Overrides:
      readPage in class PageArray
      Throws:
      IOException
    • readPage

      public void readPage(long index, long dstPtr, int offset, int length) throws IOException
      Overrides:
      readPage in class PageArray
      Parameters:
      index - zero-based page index to read
      dstPtr - receives read data
      offset - offset into data buffer
      Throws:
      IOException - 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
      Overrides:
      readPage in class PageArray
      Throws:
      IOException
    • writePage

      public void writePage(long index, byte[] src, int offset) throws IOException
      Description copied from class: PageArray
      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.
      Specified by:
      writePage in class PageArray
      Parameters:
      index - zero-based page index to write
      src - data to write
      offset - offset into data buffer
      Throws:
      IOException
    • writePage

      public void writePage(long index, byte[] src, int offset, ByteBuffer tail) throws IOException
      Specified by:
      writePage in class PageArray
      Throws:
      IOException
    • writePage

      public void writePage(long index, long srcPtr, int offset) throws IOException
      Description copied from class: PageArray
      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.
      Overrides:
      writePage in class PageArray
      Parameters:
      index - zero-based page index to write
      srcPtr - data to write
      offset - offset into data buffer
      Throws:
      IOException
    • writePage

      public void writePage(long index, long srcPtr, int offset, ByteBuffer tail) throws IOException
      Overrides:
      writePage in class PageArray
      Throws:
      IOException
    • directPagePointer

      public long directPagePointer(long index) throws IOException
      Overrides:
      directPagePointer in class PageArray
      Throws:
      IOException
    • copyPage

      public long copyPage(long srcIndex, long dstIndex) throws IOException
      Overrides:
      copyPage in class PageArray
      Returns:
      direct pointer to destination
      Throws:
      IOException
    • copyPageFromPointer

      public long copyPageFromPointer(long srcPointer, long dstIndex) throws IOException
      Overrides:
      copyPageFromPointer in class PageArray
      Returns:
      direct pointer to destination
      Throws:
      IOException
    • sync

      public void sync(boolean metadata) throws IOException
      Description copied from class: PageArray
      Durably flushes all writes to the underlying device.
      Specified by:
      sync in class PageArray
      Parameters:
      metadata - pass true to flush all file metadata
      Throws:
      IOException
    • syncPage

      public void syncPage(long index) throws IOException
      Description copied from class: PageArray
      Durably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.
      Overrides:
      syncPage in class PageArray
      Throws:
      IOException
    • close

      public final void close(Throwable cause) throws IOException
      Specified by:
      close in interface CauseCloseable
      Specified by:
      close in class PageArray
      Parameters:
      cause - null if close is not caused by a failure
      Throws:
      IOException
    • open

      public MappedPageArray open() throws IOException
      Description copied from class: PageArray
      Attempt to open or reopen the page array.
      Overrides:
      open in class PageArray
      Returns:
      existing or new page array
      Throws:
      IOException