Interface StreamReplicator.Writer
- All Superinterfaces:
AutoCloseable, Closeable, Replicator.Accessor, Replicator.Writer
- Enclosing interface:
StreamReplicator
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 intwrite(byte[] messages) Write complete messages to the log.intwrite(byte[] prefix, byte[] messages, int offset, int length, long highestPosition) Write complete or partial messages to the log.default intwrite(byte[] messages, int offset, int length) Write complete messages to the log.default intwrite(byte[] messages, int offset, int length, long highestPosition) Write complete or partial messages to the log.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
-
write
Write complete messages to the log. Equivalent to:write(messages, 0, messages.length,position() +messages.length)- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-
write
Write complete messages to the log. Equivalent to:write(messages, offset, length,position() +length)- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-
write
Write complete or partial messages to the log. ThehighestPositionparameter defines the new absolute log position which can become the commit position. The provided highest position is permitted to exceed the current log size, in anticipation of future writes which will fill in the gap. Until the gap is filled in, the highest position won't be applied. In addition, the highest position can only ever advance. Passing in a smaller value for the highest position won't actually change it. If all of the provided messages are partial, simply pass zero as the highest position. To update the highest position without actually writing anything, pass a length of zero.- Parameters:
highestPosition- highest position (exclusive) which can become the commit position- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-
write
int write(byte[] prefix, byte[] messages, int offset, int length, long highestPosition) throws IOException Write complete or partial messages to the log.- Parameters:
prefix- optional prefix message to fully write, which advances the log position just like any other messagehighestPosition- highest position (exclusive) which can become the commit position- Returns:
- 1 if successful, -1 if fully deactivated, or 0 if should write any remaining messages and then close the writer
- Throws:
IOException
-