Interface Replicator.Accessor
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Subinterfaces:
MessageReplicator.Reader
,MessageReplicator.Writer
,Replicator.Reader
,Replicator.Writer
,StreamReplicator.Reader
,StreamReplicator.Writer
- Enclosing interface:
Replicator
Direct interface for accessing replication data, for a given term.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommitListener
(LongConsumer listener) Install a callback which receives a stream of commit position updates.void
close()
long
Returns the current term commit position, which might be lower than the start position.long
position()
Returns the next log position which will be accessed.long
term()
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
-
term
long term()Returns the fixed term being accessed. -
termStartPosition
long termStartPosition()Returns the position at the start of the term. -
termEndPosition
long termEndPosition()Returns the current term end position, which is Long.MAX_VALUE if unbounded. The end position is always permitted to retreat, but never lower than the commit position. -
position
long position()Returns the next log position which will be accessed. -
commitPosition
long commitPosition()Returns the current term commit position, which might be lower than the start position. -
addCommitListener
Install a callback which receives a stream of commit position updates. Each update is guaranteed to be higher than the previous one. When the received position is -1, the term has ended, and no further updates are received. The listener implementation should avoid prolonged blocking of the calling thread, or else the replicator can stall.- Throws:
NullPointerException
- if listener is null
-
uponCommit
Invokes the given task when the commit position reaches the requested position. The current commit position is passed to the task, which is -1 if the term ended before the position could be reached. If the task can be run when this method is called, then the current thread invokes it immediately. -
waitForCommit
Blocks until the commit position reaches the given position.- Parameters:
nanosTimeout
- relative nanosecond time to wait; infinite if <0- Returns:
- current commit position, or -1 if deactivated before the position could be reached, or -2 if timed out
- Throws:
InterruptedIOException
-
waitForEndCommit
Blocks until the commit position reaches the end of the term.- Parameters:
nanosTimeout
- relative nanosecond time to wait; infinite if <0- Returns:
- current commit position, or -1 if closed before the position could be reached, or -2 if timed out
- Throws:
InterruptedIOException
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-