public class OffsetRangeTracker extends Object implements RangeTracker<Long>
RangeTracker for non-negative positions of type long.| Modifier and Type | Field and Description |
|---|---|
static long |
OFFSET_INFINITY
Offset corresponding to infinity.
|
| Constructor and Description |
|---|
OffsetRangeTracker(long startOffset,
long stopOffset)
Creates an
OffsetRangeTracker for the specified range. |
| 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. |
long |
getPositionForFractionConsumed(double fraction)
Returns a position
P such that the range [start, P) represents approximately
the given fraction of the range [start, end). |
Long |
getStartPosition()
Returns the starting position of the current range, inclusive.
|
Long |
getStopPosition()
Returns the ending position of the current range, exclusive.
|
String |
toString() |
boolean |
tryReturnRecordAt(boolean isAtSplitPoint,
long recordStart) |
boolean |
tryReturnRecordAt(boolean isAtSplitPoint,
Long recordStart)
Atomically determines whether a record at the given position can be returned and updates
internal state.
|
boolean |
trySplitAtPosition(long splitOffset) |
boolean |
trySplitAtPosition(Long splitOffset)
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 final long OFFSET_INFINITY
Infinite ranges cannot be split because it is impossible to estimate progress within them.
public OffsetRangeTracker(long startOffset,
long stopOffset)
OffsetRangeTracker for the specified range.public Long getStartPosition()
RangeTrackergetStartPosition in interface RangeTracker<Long>public Long getStopPosition()
RangeTrackergetStopPosition in interface RangeTracker<Long>public boolean tryReturnRecordAt(boolean isAtSplitPoint,
Long recordStart)
RangeTrackerisAtSplitPoint 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<Long>public boolean tryReturnRecordAt(boolean isAtSplitPoint,
long recordStart)
public boolean trySplitAtPosition(Long splitOffset)
RangeTrackerRangeTracker.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<Long>public boolean trySplitAtPosition(long splitOffset)
public long getPositionForFractionConsumed(double fraction)
P such that the range [start, P) represents approximately
the given fraction of the range [start, end). Assumes that the density of records
in the range is approximately uniform.public double getFractionConsumed()
RangeTrackerRangeTracker.tryReturnRecordAt(boolean, PositionT) calls, or 0.0 if no such calls have happened.getFractionConsumed in interface RangeTracker<Long>