Interface MessageReplicator.Reader
- All Superinterfaces:
AutoCloseable, Closeable, Replicator.Accessor, Replicator.Reader
- Enclosing interface:
MessageReplicator
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 TypeMethodDescriptionbyte[]Blocks until a log message is available, never reading past a commit position or term.intreadMessage(byte[] buf, int offset, int length) Blocks until a message is available, and then fully or partially copies it into the given buffer.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
-
readMessage
Blocks until a log message is available, never reading past a commit position or term.- Returns:
- complete message or null if the term end has been reached
- Throws:
IllegalStateException- if a partially read message remainsInvalidReadException- if log was deleted (position is too low)IOException
-
readMessage
Blocks until a message is available, and then fully or partially copies it into the given buffer. Messages are partially copied only when the given buffer length is too small. When a message has been fully copied, a positive length is returned. A negative return value indicates the amount of bytes remaining in the message. Compute the ones' complement (~) to determine the actual amount remaining. If the amount remaining is 0 (or -1 when not complemented), then the term end has been reached.- Returns:
- message length if positive, or the amount of bytes remaining in the message (ones' complement), or EOF (-1) if the term end has been reached
- Throws:
InvalidReadException- if log was deleted (position is too low)IOException
-