Package com.apple.foundationdb.record
Class RecordCursorIterator<T>
- java.lang.Object
-
- com.apple.foundationdb.record.RecordCursorIterator<T>
-
- Type Parameters:
T
- the type of elements of the cursor
- All Implemented Interfaces:
AsyncIterator<T>
,AutoCloseable
,Iterator<T>
@API(STABLE) public class RecordCursorIterator<T> extends Object implements AsyncIterator<T>, AutoCloseable
An asynchronous iterator that wraps aRecordCursor
and presents an iterator-style interface for advancing the cursor. This addsgetContinuation()
andgetNoNextReason()
methods to theAsyncIterator
interface so that cursors can be resumed and so that their reason for stopping can be inspected.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
void
close()
byte[]
getContinuation()
Get a byte string that can be used to continue a query after the last record returned.RecordCursor.NoNextReason
getNoNextReason()
Get the reason that the cursor has reached the end and returnedfalse
forhasNext()
.boolean
hasNext()
Synchronously check whether there are more records available from the cursor.T
next()
Return the next value.CompletableFuture<Boolean>
onHasNext()
Asynchronously check whether there are more records available from the cursor.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
onHasNext
@Nonnull public CompletableFuture<Boolean> onHasNext()
Asynchronously check whether there are more records available from the cursor.- Specified by:
onHasNext
in interfaceAsyncIterator<T>
- Returns:
- a future that when complete will hold
true
ifnext()
would return a record. - See Also:
AsyncIterator.onHasNext()
-
hasNext
public boolean hasNext()
Synchronously check whether there are more records available from the cursor.
-
next
@Nullable public T next()
Return the next value. May only be called after the future fromonHasNext()
has completed totrue
(or equivalently afterhasNext()
has returnedtrue
).
-
getContinuation
@Nullable public byte[] getContinuation()
Get a byte string that can be used to continue a query after the last record returned. Returnsnull
if the underlying source is completely exhausted, independent of any limit passed to the cursor creator. Since such creators generally acceptnull
to mean no continuation, that is, start from the beginning, one must check fornull
fromgetContinuation()
to keep from starting over. Result is not always defined if called before theonHasNext()
has been called, before the returned future has completed, or after it has completed totrue
but beforenext()
has been called. That is, a continuation is only guaranteed when called "between" records from awhile (hasNext) next
loop or after its end. If configured to do so, anIllegalContinuationAccessChecker
will be used to throw an exception if a continuation is accessed at the wrong time.- Returns:
- opaque byte array denoting where the cursor should pick up. This can be passed back into a new cursor of the same type, with all other parameters remaining the same.
-
getNoNextReason
@Nonnull public RecordCursor.NoNextReason getNoNextReason()
Get the reason that the cursor has reached the end and returnedfalse
forhasNext()
. IfhasNext
was not called or returnedtrue
last time, the result is undefined and may be an exception.- Returns:
- the reason that the cursor stopped
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
cancel
public void cancel()
- Specified by:
cancel
in interfaceAsyncIterator<T>
-
-