Interface MessageReplicator.Reader

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

public static interface MessageReplicator.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 Details

    • readMessage

      byte[] readMessage() throws IOException
      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 remains
      InvalidReadException - if log was deleted (position is too low)
      IOException
    • readMessage

      int readMessage(byte[] buf, int offset, int length) throws IOException
      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