com.google.cloud.dataflow.sdk.io.range

## Class ByteKeyRangeTracker

- java.lang.Object
- - com.google.cloud.dataflow.sdk.io.range.ByteKeyRangeTracker

All Implemented Interfaces:
  RangeTracker<ByteKey>

    public final class ByteKeyRangeTracker
    extends Object
    implements RangeTracker<ByteKey>

A `RangeTracker` for `ByteKeys` in `ByteKeyRanges`.

See Also:
  `ByteKey`, `ByteKeyRange`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`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.
`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).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Method Detail

#### of

    public static ByteKeyRangeTracker of(ByteKeyRange range)

Instantiates a new `ByteKeyRangeTracker` with the specified range.

#### isDone

    public boolean isDone()

#### getStartPosition

    public ByteKey getStartPosition()

Description copied from interface: `RangeTracker`
Returns the starting position of the current range, inclusive.

Specified by:
  `getStartPosition` in interface `RangeTracker<ByteKey>`

#### getStopPosition

    public ByteKey getStopPosition()

Description copied from interface: `RangeTracker`
Returns the ending position of the current range, exclusive.

Specified by:
  `getStopPosition` in interface `RangeTracker<ByteKey>`

#### getRange

    public ByteKeyRange getRange()

Returns the current range.

#### tryReturnRecordAt

    public boolean tryReturnRecordAt(boolean isAtSplitPoint,
                                     ByteKey recordStart)

Description copied from interface: `RangeTracker`
Atomically determines whether a record at the given position can be returned and updates internal state. In particular:

- If `isAtSplitPoint` is `true`, and `recordStart` is outside the current range, returns `false`;
- Otherwise, updates the last-consumed position to `recordStart` and returns `true`.

This method MUST be called on all split point records. It may be called on every record.

Specified by:
  `tryReturnRecordAt` in interface `RangeTracker<ByteKey>`

#### trySplitAtPosition

    public boolean trySplitAtPosition(ByteKey splitPosition)

Description copied from interface: `RangeTracker`
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).

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.

Specified by:
  `trySplitAtPosition` in interface `RangeTracker<ByteKey>`

#### getFractionConsumed

    public double getFractionConsumed()

Description copied from interface: `RangeTracker`
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.

Specified by:
  `getFractionConsumed` in interface `RangeTracker<ByteKey>`

#### getSplitPointsConsumed

    public long getSplitPointsConsumed()

#### markDone

    public boolean markDone()

Marks this range tracker as being done. Specifically, this will mark the current split point, if one exists, as being finished.

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();
     }

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`