public abstract class RestrictionTracker<RestrictionT,PositionT>
extends java.lang.Object
DoFn
.Modifier and Type | Class and Description |
---|---|
static interface |
RestrictionTracker.ClaimObserver<PositionT>
Internal interface allowing a runner to observe the calls to
tryClaim(PositionT) . |
Constructor and Description |
---|
RestrictionTracker() |
Modifier and Type | Method and Description |
---|---|
abstract void |
checkDone()
Called by the runner after
DoFn.ProcessElement returns. |
abstract RestrictionT |
checkpoint()
Signals that the current
DoFn.ProcessElement call should terminate as soon as possible:
after this method returns, the tracker MUST refuse all future claim calls, and checkDone() MUST succeed. |
abstract RestrictionT |
currentRestriction()
Returns a restriction accurately describing the full range of work the current
DoFn.ProcessElement call will do, including already completed work. |
void |
setClaimObserver(RestrictionTracker.ClaimObserver<PositionT> claimObserver)
Sets a
RestrictionTracker.ClaimObserver to be invoked on every call to tryClaim(PositionT) . |
boolean |
tryClaim(PositionT position)
Attempts to claim the block of work in the current restriction identified by the given
position.
|
protected abstract boolean |
tryClaimImpl(PositionT position)
Tracker-specific implementation of
tryClaim(PositionT) . |
@Internal public void setClaimObserver(RestrictionTracker.ClaimObserver<PositionT> claimObserver)
RestrictionTracker.ClaimObserver
to be invoked on every call to tryClaim(PositionT)
. Internal:
intended only for runner authors.public final boolean tryClaim(PositionT position)
If this succeeds, the DoFn MUST execute the entire block of work. If this fails:
DoFn.ProcessElement
MUST return DoFn.ProcessContinuation#stop
without
performing any additional work or emitting output (note that emitting output or
performing work from DoFn.ProcessElement
is also not allowed before the first
call to this method).
checkDone()
MUST succeed.
Under the hood, calls tryClaimImpl(PositionT)
and notifies RestrictionTracker.ClaimObserver
of the
result.
@Internal protected abstract boolean tryClaimImpl(PositionT position)
tryClaim(PositionT)
.public abstract RestrictionT currentRestriction()
DoFn.ProcessElement
call will do, including already completed work.public abstract RestrictionT checkpoint()
DoFn.ProcessElement
call should terminate as soon as possible:
after this method returns, the tracker MUST refuse all future claim calls, and checkDone()
MUST succeed.
Modifies currentRestriction()
. Returns a restriction representing the rest of the
work: the old value of currentRestriction()
is equivalent to the new value and the
return value of this method combined.
Must be called at most once on a given object. Must not be called before the first
successful tryClaim(PositionT)
call.
public abstract void checkDone() throws java.lang.IllegalStateException
DoFn.ProcessElement
returns.
Must throw an exception with an informative error message, if there is still any unclaimed work remaining in the restriction.
java.lang.IllegalStateException