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.int
readMessage
(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 org.cojen.tupl.repl.Replicator.Accessor
addCommitListener, close, commitPosition, position, term, termEndPosition, termStartPosition, uponCommit, waitForCommit, waitForEndCommit
-
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
-