Interface StreamReplicator.Writer

All Superinterfaces:
AutoCloseable, Closeable, Replicator.Accessor, Replicator.Writer
Enclosing interface:
StreamReplicator

public static interface StreamReplicator.Writer extends Replicator.Writer
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 Type
    Method
    Description
    default int
    write(byte[] messages)
    Write complete messages to the log.
    int
    write(byte[] prefix, byte[] messages, int offset, int length, long highestPosition)
    Write complete or partial messages to the log.
    default int
    write(byte[] messages, int offset, int length)
    Write complete messages to the log.
    default int
    write(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, waitForEndCommit
    Modifier and Type
    Method
    Description
    void
    Install a callback which receives a stream of commit position updates.
    void
     
    long
    Returns the current term commit position, which might be lower than the start position.
    long
    Returns the next log position which will be accessed.
    long
    Returns the fixed term being accessed.
    long
    Returns the current term end position, which is Long.MAX_VALUE if unbounded.
    long
    Returns the position at the start of the term.
    void
    uponCommit(long position, LongConsumer task)
    Invokes the given task when the commit position reaches the requested position.
    long
    waitForCommit(long position, long nanosTimeout)
    Blocks until the commit position reaches the given position.
    default long
    waitForEndCommit(long nanosTimeout)
    Blocks until the commit position reaches the end of the term.
  • Method Details

    • write

      default int write(byte[] messages) throws IOException
      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

      default int write(byte[] messages, int offset, int length) throws IOException
      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

      default int write(byte[] messages, int offset, int length, long highestPosition) throws IOException
      Write complete or partial messages to the log. The highestPosition parameter 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 message
      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