Interface JournalReader
- All Superinterfaces:
AutoCloseable,Iterator<JournalRecord>
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longseek(long index) Seek to a record at the given index.longseekToAsqn(long asqn) Seek to a record with the highest ASQN less than or equal to the givenasqn.longseekToAsqn(long asqn, long indexUpperBound) Seek to a record with the highest ASQN less than or equal to the givenasqn, with the restriction that it seeks to a record with index less than or equal to the given indexUpperBound.longSeek to the first index of the journal.longSeek to the last index of the journal.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
seek
long seek(long index) Seek to a record at the given index. if seek(index) return true,Iterator.next()should return a record at index.If the journal is empty, it will return
Journal.getFirstIndex(), but it should not do anything.If the index is less than
Journal.getFirstIndex(),Iterator.next()should return a record at indexJournal.getFirstIndex().If the index is greater than
Journal.getLastIndex(), the read is positioned past the end of the journal, such thatIterator.hasNext()will return false. In this case, the returned index would be{@link Journal#getLastIndex()} + 1.Callers are expected to call
Iterator.hasNext()after a seek, regardless of the result returned.- Parameters:
index- the index to seek to.- Returns:
- the index of the next record to be read
-
seekToFirst
long seekToFirst()Seek to the first index of the journal. The index returned is that of the record which would be returned by callingIterator.next().Equivalent to calling seek(journal.getFirstIndex()).
Callers are expected to call
Iterator.hasNext()after a seek, regardless of the result returned.If the journal is empty, then the index returned is the
Journal.getFirstIndex().- Returns:
- the first index of the journal
-
seekToLast
long seekToLast()Seek to the last index of the journal. The index returned is that of the record which would be returned by callingIterator.next().Equivalent to calling seek(journal.getLastIndex()).
Callers are expected to call
Iterator.hasNext()after a seek, regardless of the result returned.If the journal is empty, then the index returned is the
Journal.getLastIndex(), which may be lower thanJournal.getFirstIndex().- Returns:
- the last index of the journal
-
seekToAsqn
long seekToAsqn(long asqn) Seek to a record with the highest ASQN less than or equal to the givenasqn.If there are no records with a lower or equal ASQN, then the reader will be positioned at the beginning of the record. That is it behaves as if
seekToFirst(). In this case it's possible that the next record has an ASQN of-1, as not all records have an ASQN assigned.Callers are expected to call
Iterator.hasNext()after a seek, regardless of the result returned.The index returned is that of a valid record, or if the journal is empty,
Journal.getFirstIndex().- Parameters:
asqn- application sequence number to seek- Returns:
- the index of the record that will be returned by
Iterator.next()
-
seekToAsqn
long seekToAsqn(long asqn, long indexUpperBound) Seek to a record with the highest ASQN less than or equal to the givenasqn, with the restriction that it seeks to a record with index less than or equal to the given indexUpperBound.Otherwise, the semantics is similar to
seekToAsqn(asqn)- Parameters:
asqn- application sequence number to seekindexUpperBound- the index until which it seeks- Returns:
- the index of the record that will be returned by
Iterator.next()
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-