Interface MessageReplicator.Writer
- All Superinterfaces:
AutoCloseable, Closeable, Replicator.Accessor, Replicator.Writer
- Enclosing interface:
MessageReplicator
Interface called by the group leader for proposing messages. When consensus has been
reached, the messages are committed and become available for all members to read.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault intwriteMessage(byte[] message) Write a single message to the log.default intwriteMessage(byte[] message, int offset, int length) Write a single message to the log.intwriteMessage(byte[] message, int offset, int length, boolean finished) Write a single message to the log, as part of an atomic batch.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
-
writeMessage
Write a single message to the log. Equivalent to:writeMessage(message, 0, message.length, true)- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-
writeMessage
Write a single message to the log. Equivalent to:writeMessage(message, offset, length, true)- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-
writeMessage
Write a single message to the log, as part of an atomic batch. When read back, all messages in the batch are still separate from each other. Pass false to the finished parameter for all messages in the batch except the last one. To work correctly, no other threads should be granted access to the writer in the middle of a batch.- Parameters:
finished- pass true for the last message in the batch- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-