Interface StreamReplicator.Reader

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

public static interface StreamReplicator.Reader extends Replicator.Reader
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 Type
    Method
    Description
    default int
    read(byte[] buf)
    Blocks until log messages are available, never reading past a commit position or term.
    int
    read(byte[] buf, int offset, int length)
    Blocks until log messages are available, never reading past a commit position or term.
    default void
    readFully(byte[] buf, int offset, int length)
    Blocks until the buffer is fully read with messages, never reading past a commit position or term.
    int
    tryRead(byte[] buf, int offset, int length)
    Reads whatever log data is available, never higher than a commit position, never higher than a term, and never blocking.

    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

    • read

      default int read(byte[] buf) throws IOException
      Blocks until log messages are available, never reading past a commit position or term.
      Returns:
      amount of bytes read, or EOF (-1) if the term end has been reached
      Throws:
      InvalidReadException - if log was deleted (position is too low)
      IOException
    • read

      int read(byte[] buf, int offset, int length) throws IOException
      Blocks until log messages are available, never reading past a commit position or term.
      Returns:
      amount of bytes read, or EOF (-1) if the term end has been reached
      Throws:
      InvalidReadException - if log was deleted (position is too low)
      IOException
    • readFully

      default void readFully(byte[] buf, int offset, int length) throws IOException
      Blocks until the buffer is fully read with messages, never reading past a commit position or term.
      Throws:
      InvalidReadException - if log was deleted (position is too low)
      EOFException - if the term end has been reached too soon
      IOException
    • tryRead

      int tryRead(byte[] buf, int offset, int length) throws IOException
      Reads whatever log data is available, never higher than a commit position, never higher than a term, and never blocking.
      Returns:
      amount of bytes read, or EOF (-1) if the term end has been reached
      Throws:
      InvalidReadException - if log data was deleted (position is too low)
      IOException