public final class ByteKeyRangeTracker extends java.lang.Object implements RangeTracker<ByteKey>
ByteKey
,
ByteKeyRange
Modifier and Type | Method and Description |
---|---|
double |
getFractionConsumed()
Returns the approximate fraction of positions in the source that have been consumed by
successful
RangeTracker.tryReturnRecordAt(boolean, PositionT) calls, or 0.0 if no such calls have happened. |
ByteKeyRange |
getRange()
Returns the current range.
|
long |
getSplitPointsConsumed() |
ByteKey |
getStartPosition()
Returns the starting position of the current range, inclusive.
|
ByteKey |
getStopPosition()
Returns the ending position of the current range, exclusive.
|
boolean |
isDone() |
boolean |
markDone()
Marks this range tracker as being done.
|
static ByteKeyRangeTracker |
of(ByteKeyRange range)
Instantiates a new
ByteKeyRangeTracker with the specified range. |
java.lang.String |
toString() |
boolean |
tryReturnRecordAt(boolean isAtSplitPoint,
ByteKey recordStart)
Atomically determines whether a record at the given position can be returned and updates
internal state.
|
boolean |
trySplitAtPosition(ByteKey splitPosition)
Atomically splits the current range [
RangeTracker.getStartPosition() , RangeTracker.getStopPosition() )
into a "primary" part [RangeTracker.getStartPosition() , splitPosition )
and a "residual" part [splitPosition , RangeTracker.getStopPosition() ), assuming the current
last-consumed position is within [RangeTracker.getStartPosition() , splitPosition)
(i.e., splitPosition has not been consumed yet). |
public static ByteKeyRangeTracker of(ByteKeyRange range)
ByteKeyRangeTracker
with the specified range.public boolean isDone()
public ByteKey getStartPosition()
RangeTracker
getStartPosition
in interface RangeTracker<ByteKey>
public ByteKey getStopPosition()
RangeTracker
getStopPosition
in interface RangeTracker<ByteKey>
public ByteKeyRange getRange()
public boolean tryReturnRecordAt(boolean isAtSplitPoint, ByteKey recordStart)
RangeTracker
isAtSplitPoint
is true
, and recordStart
is outside the current
range, returns false
;
recordStart
and returns
true
.
This method MUST be called on all split point records. It may be called on every record.
tryReturnRecordAt
in interface RangeTracker<ByteKey>
public boolean trySplitAtPosition(ByteKey splitPosition)
RangeTracker
RangeTracker.getStartPosition()
, RangeTracker.getStopPosition()
)
into a "primary" part [RangeTracker.getStartPosition()
, splitPosition
)
and a "residual" part [splitPosition
, RangeTracker.getStopPosition()
), assuming the current
last-consumed position is within [RangeTracker.getStartPosition()
, splitPosition)
(i.e., splitPosition
has not been consumed yet).
Updates the current range to be the primary and returns true
. This means that
all further calls on the current object will interpret their arguments relative to the
primary range.
If the split position has already been consumed, or if no RangeTracker.tryReturnRecordAt(boolean, PositionT)
call
was made yet, returns false
. The second condition is to prevent dynamic splitting
during reader start-up.
trySplitAtPosition
in interface RangeTracker<ByteKey>
public double getFractionConsumed()
RangeTracker
RangeTracker.tryReturnRecordAt(boolean, PositionT)
calls, or 0.0 if no such calls have happened.getFractionConsumed
in interface RangeTracker<ByteKey>
public long getSplitPointsConsumed()
public boolean markDone()
Always returns false, so that it can be used in an implementation of
Source.Reader.start()
or Source.Reader.advance()
as follows:
public boolean start() {
return startImpl() && rangeTracker.tryReturnRecordAt(isAtSplitPoint, position)
|| rangeTracker.markDone();
}
public java.lang.String toString()
toString
in class java.lang.Object