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 TypeMethodDescriptionvoidaddCommitListener(LongConsumer listener) Install a callback which receives a stream of commit position updates.voidclose()longReturns the current term commit position, which might be lower than the start position.longposition()Returns the next log position which will be accessed.longterm()Returns the fixed term being accessed.longReturns the current term end position, which is Long.MAX_VALUE if unbounded.longReturns the position at the start of the term.voiduponCommit(long position, LongConsumer task) Invokes the given task when the commit position reaches the requested position.longwaitForCommit(long position, long nanosTimeout) Blocks until the commit position reaches the given position.default longwaitForEndCommit(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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-