Interface MessageReplicator
- All Superinterfaces:
AutoCloseable
,Closeable
,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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Interface called by any group member for reading committed messages.static interface
Interface called by the group leader for proposing messages.Nested classes/interfaces inherited from interface org.cojen.tupl.repl.Replicator
Replicator.Accessor
-
Method Summary
Modifier and TypeMethodDescriptionnewReader
(long position, boolean follow) Returns a new reader which accesses data starting from the given position.Returns a new writer for the leader to write into, or else returns null if the local member isn't the leader.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.static MessageReplicator
open
(ReplicatorConfig config) Open a MessageReplicator instance, creating it if necessary.Methods inherited from interface org.cojen.tupl.repl.Replicator
commitPosition, compact, connect, encoding, failover, isReadable, localAddress, localMemberId, localRole, requestSnapshot, restore, snapshotRequestAcceptor, socketAcceptor, start, sync, syncCommit
-
Method Details
-
open
Open a MessageReplicator instance, creating it if necessary. Be sure to call thestart
method too.- Throws:
IllegalArgumentException
- if misconfiguredIOException
-
newReader
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 interfaceReplicator
- Parameters:
position
- position to start reading from, known to have been committedfollow
- 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
MessageReplicator.Writer 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 interfaceReplicator
- Returns:
- writer or null if not the leader
- Throws:
IllegalStateException
- if an existing writer for the current term already exists
-
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 interfaceReplicator
- 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
-