public interface PageCursor extends AutoCloseable
PagedFile.io(long, int),
and is used to scan through pages and process them in a consistent and safe fashion.
A page must be processed in the following manner:
try ( PageCursor cursor = pagedFile.io( pageId, pf_flags ) )
{
// Use 'if' for processing a single page,
// use 'while' for scanning through pages:
if ( cursor.next() )
{
do
{
processPage( cursor );
} while ( cursor.shouldRetry() );
// Any finalising, non-repeatable post-processing
// goes here.
}
}
catch ( IOException e )
{
// handle the error, somehow
}
There are a couple of things to this pattern that are worth noting:
next(long) method, to navigate the
pages you need in a non-linear fashion.| Modifier and Type | Field and Description |
|---|---|
static long |
UNBOUND_PAGE_ID |
static int |
UNBOUND_PAGE_SIZE |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Relinquishes all resources associated with this cursor, including the
cursor itself.
|
byte |
getByte()
Get the signed byte at the current page offset, and then increment the offset by one.
|
byte |
getByte(int offset)
Get the signed byte at the given offset into the page.
|
void |
getBytes(byte[] data)
Fill the given array with bytes from the page, beginning at the current offset into the page,
and then increment the current offset by the length of the array.
|
File |
getCurrentFile()
Get the file the cursor is currently bound to, or
null if next() has not yet been called on this
cursor, or returned false. |
long |
getCurrentPageId()
Get the file page id that the cursor is currently positioned at, or
UNBOUND_PAGE_ID if next() has not yet been called on this cursor, or returned false.
|
int |
getCurrentPageSize()
Get the file page size of the page that the cursor is currently positioned at,
or UNBOUND_PAGE_SIZE if next() has not yet been called on this cursor, or returned false.
|
int |
getInt()
Get the signed int at the current page offset, and then increment the offset by one.
|
int |
getInt(int offset)
Get the signed int at the given offset into the page.
|
long |
getLong()
Get the signed long at the current page offset, and then increment the offset by one.
|
long |
getLong(int offset)
Get the signed long at the given offset into the page.
|
int |
getOffset()
Get the current offset into the page, which is the location on the page where the next interaction would take
place through the read and write methods that do not take a specific offset as an argument.
|
short |
getShort()
Get the signed short at the current page offset, and then increment the offset by one.
|
short |
getShort(int offset)
Get the signed short at the given offset into the page.
|
long |
getUnsignedInt()
Get the unsigned int at the current page offset, and then increment the offset by one.
|
long |
getUnsignedInt(int offset)
Get the unsigned int at the given offset into the page.
|
boolean |
next()
Moves the cursor to the next page, if any, and returns true when it is
ready to be processed.
|
boolean |
next(long pageId)
Moves the cursor to the page specified by the given pageId, if any,
and returns true when it is ready to be processed.
|
void |
putByte(byte value)
Set the signed byte at the current offset into the page, and then increment the offset by one.
|
void |
putByte(int offset,
byte value)
Set the signed byte at the given offset into the page.
|
void |
putBytes(byte[] data)
Write out all the bytes of the given array into the page, beginning at the current offset into the page,
and then increment the current offset by the length of the array.
|
void |
putInt(int value)
Set the signed int at the current offset into the page, and then increment the offset by one.
|
void |
putInt(int offset,
int value)
Set the signed int at the given offset into the page.
|
void |
putLong(int offset,
long value)
Set the signed long at the given offset into the page.
|
void |
putLong(long value)
Set the signed long at the current offset into the page, and then increment the offset by one.
|
void |
putShort(int offset,
short value)
Set the signed short at the given offset into the page.
|
void |
putShort(short value)
Set the signed short at the current offset into the page, and then increment the offset by one.
|
void |
rewind()
Rewinds the cursor to its initial condition, as if freshly returned from
an equivalent io() call.
|
void |
setOffset(int offset)
Set the current offset into the page, for interacting with the page through the read and write methods that do
not take a specific offset as an argument.
|
boolean |
shouldRetry()
Returns true if the page has entered an inconsistent state since the
last call to next() or shouldRetry().
|
static final long UNBOUND_PAGE_ID
static final int UNBOUND_PAGE_SIZE
byte getByte()
IndexOutOfBoundsException - if the current offset is not within the page bounds.byte getByte(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void putByte(byte value)
IndexOutOfBoundsException - if the current offset is not within the page bounds.void putByte(int offset,
byte value)
IndexOutOfBoundsException - if the given offset is not within the page bounds.long getLong()
IndexOutOfBoundsException - if the current offset is not within the page bounds.long getLong(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void putLong(long value)
IndexOutOfBoundsException - if the current offset is not within the page bounds.void putLong(int offset,
long value)
IndexOutOfBoundsException - if the given offset is not within the page bounds.int getInt()
IndexOutOfBoundsException - if the current offset is not within the page bounds.int getInt(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void putInt(int value)
IndexOutOfBoundsException - if the current offset is not within the page bounds.void putInt(int offset,
int value)
IndexOutOfBoundsException - if the given offset is not within the page bounds.long getUnsignedInt()
IndexOutOfBoundsException - if the current offset is not within the page bounds.long getUnsignedInt(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void getBytes(byte[] data)
IndexOutOfBoundsException - if the current offset plus the length of the array reaches beyond the end of the page.void putBytes(byte[] data)
IndexOutOfBoundsException - if the current offset plus the length of the array reaches beyond the end of the page.short getShort()
IndexOutOfBoundsException - if the current offset is not within the page bounds.short getShort(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void putShort(short value)
IndexOutOfBoundsException - if the current offset is not within the page bounds.void putShort(int offset,
short value)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void setOffset(int offset)
int getOffset()
long getCurrentPageId()
int getCurrentPageSize()
File getCurrentFile()
null if next() has not yet been called on this
cursor, or returned false.
A call to rewind() will make the cursor unbound as well, until next() is called.void rewind()
throws IOException
IOExceptionboolean next()
throws IOException
IOExceptionboolean next(long pageId)
throws IOException
IOExceptionvoid close()
close in interface AutoCloseableAutoCloseable.close()boolean shouldRetry()
throws IOException
IOException - If the page was evicted while doing IO, the cursor will have
to do a page fault to get the page back.
This may throw an IOException.Copyright © 2002–2015 The Neo4j Graph Database Project. All rights reserved.