Interface StreamReplicator.Reader
- All Superinterfaces:
AutoCloseable, Closeable, Replicator.Accessor, Replicator.Reader
- Enclosing interface:
StreamReplicator
Interface called by any group member for reading committed messages. Readers don't track
which messages are applied — applications are responsible for tracking the highest
applied position. When an application restarts, it must open the reader at an appropriate
position.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault intread(byte[] buf) Blocks until log messages are available, never reading past a commit position or term.intread(byte[] buf, int offset, int length) Blocks until log messages are available, never reading past a commit position or term.default voidreadFully(byte[] buf, int offset, int length) Blocks until the buffer is fully read with messages, never reading past a commit position or term.inttryRead(byte[] buf, int offset, int length) Reads whatever log data is available, never higher than a commit position, never higher than a term, and never blocking.Methods inherited from interface Replicator.Accessor
addCommitListener, close, commitPosition, position, term, termEndPosition, termStartPosition, uponCommit, waitForCommit, waitForEndCommitModifier and TypeMethodDescriptionvoidaddCommitListener(LongConsumer listener) Install a callback which receives a stream of commit position updates.voidclose()longReturns the current term commit position, which might be lower than the start position.longposition()Returns the next log position which will be accessed.longterm()Returns the fixed term being accessed.longReturns the current term end position, which is Long.MAX_VALUE if unbounded.longReturns the position at the start of the term.voiduponCommit(long position, LongConsumer task) Invokes the given task when the commit position reaches the requested position.longwaitForCommit(long position, long nanosTimeout) Blocks until the commit position reaches the given position.default longwaitForEndCommit(long nanosTimeout) Blocks until the commit position reaches the end of the term.
-
Method Details
-
read
Blocks until log messages are available, never reading past a commit position or term.- Returns:
- amount of bytes read, or EOF (-1) if the term end has been reached
- Throws:
InvalidReadException- if log was deleted (position is too low)IOException
-
read
Blocks until log messages are available, never reading past a commit position or term.- Returns:
- amount of bytes read, or EOF (-1) if the term end has been reached
- Throws:
InvalidReadException- if log was deleted (position is too low)IOException
-
readFully
Blocks until the buffer is fully read with messages, never reading past a commit position or term.- Throws:
InvalidReadException- if log was deleted (position is too low)EOFException- if the term end has been reached too soonIOException
-
tryRead
Reads whatever log data is available, never higher than a commit position, never higher than a term, and never blocking.- Returns:
- amount of bytes read, or EOF (-1) if the term end has been reached
- Throws:
InvalidReadException- if log data was deleted (position is too low)IOException
-