Interface MessageReplicator

All Superinterfaces:
AutoCloseable, Closeable, Replicator

public interface MessageReplicator extends Replicator
Message-oriented replication interface, which is a bit easier to use than StreamReplicator. Although this replicator has slightly higher overhead, control message passing is handled automatically. Replicas are still required to be reading in order for control messages to be processed, however.
See Also:
  • Method Details

    • open

      static MessageReplicator open(ReplicatorConfig config) throws IOException
      Open a MessageReplicator instance, creating it if necessary. Be sure to call the start method too.
      Throws:
      IllegalArgumentException - if misconfigured
      IOException
    • newReader

      MessageReplicator.Reader newReader(long position, boolean follow)
      Returns a new reader which accesses data starting from the given position. The reader returns EOF whenever the end of a term is reached. At the end of a term, try to obtain a new writer to determine if the local member has become the leader.

      When passing true for the follow parameter, a reader is always provided at the requested position. When passing false for the follow parameter, null is returned if the current member is the leader for the given position.

      Note: Reader instances are not expected to be thread-safe.

      Specified by:
      newReader in interface Replicator
      Parameters:
      position - position to start reading from, known to have been committed
      follow - pass true to obtain an active reader, even if local member is the leader
      Returns:
      reader or possibly null when follow is false
      Throws:
      InvalidReadException - if position is lower than the start position
    • newWriter

      Returns a new writer for the leader to write into, or else returns null if the local member isn't the leader. The writer stops accepting messages when the term has ended, and possibly another leader has been elected.

      Note: Writer instances are not expected to be thread-safe.

      Specified by:
      newWriter in interface Replicator
      Returns:
      writer or null if not the leader
      Throws:
      IllegalStateException - if an existing writer for the current term already exists
    • newWriter

      MessageReplicator.Writer newWriter(long position)
      Returns a new writer for the leader to write into, or else returns null if the local member isn't the leader. The writer stops accepting messages when the term has ended, and possibly another leader has been elected.

      Note: Writer instances are not expected to be thread-safe.

      Specified by:
      newWriter in interface Replicator
      Parameters:
      position - expected position to start writing from as leader; method returns null if the given position is lower
      Returns:
      writer or null if not the leader
      Throws:
      IllegalStateException - if an existing writer for the current term already exists