Class OffsetRangeTracker

    • Field Detail

      • OFFSET_INFINITY

        public static final long OFFSET_INFINITY
        Offset corresponding to infinity. This can only be used as the upper-bound of a range, and indicates reading all of the records until the end without specifying exactly what the end is.

        Infinite ranges cannot be split because it is impossible to estimate progress within them.

        See Also:
        Constant Field Values
    • Constructor Detail

      • OffsetRangeTracker

        public OffsetRangeTracker​(long startOffset,
                                  long stopOffset)
        Creates an OffsetRangeTracker for the specified range.
    • Method Detail

      • isStarted

        public boolean isStarted()
      • isDone

        public boolean isDone()
      • getStartPosition

        public java.lang.Long getStartPosition()
        Description copied from interface: RangeTracker
        Returns the starting position of the current range, inclusive.
        Specified by:
        getStartPosition in interface RangeTracker<java.lang.Long>
      • getStopPosition

        public java.lang.Long getStopPosition()
        Description copied from interface: RangeTracker
        Returns the ending position of the current range, exclusive.
        Specified by:
        getStopPosition in interface RangeTracker<java.lang.Long>
      • tryReturnRecordAt

        public boolean tryReturnRecordAt​(boolean isAtSplitPoint,
                                         java.lang.Long 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<java.lang.Long>
      • tryReturnRecordAt

        public boolean tryReturnRecordAt​(boolean isAtSplitPoint,
                                         long recordStart)
      • trySplitAtPosition

        public boolean trySplitAtPosition​(long splitOffset)
      • getPositionForFractionConsumed

        public long getPositionForFractionConsumed​(double fraction)
        Returns a position 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.
      • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object