Interface Watch.Growth.TerminationCondition<InputT,StateT>
-
- All Superinterfaces:
java.io.Serializable
- Enclosing class:
- Watch.Growth<InputT,OutputT,KeyT>
public static interface Watch.Growth.TerminationCondition<InputT,StateT> extends java.io.Serializable
A strategy for determining whether it is time to stop polling the current input regardless of whether its output is complete or not.Some built-in termination conditions are
Watch.Growth.never()
,Watch.Growth.afterTotalOf(org.joda.time.ReadableDuration)
andWatch.Growth.afterTimeSinceNewOutput(org.joda.time.ReadableDuration)
. Conditions can be combined usingWatch.Growth.eitherOf(org.apache.beam.sdk.transforms.Watch.Growth.TerminationCondition<InputT, FirstStateT>, org.apache.beam.sdk.transforms.Watch.Growth.TerminationCondition<InputT, SecondStateT>)
andWatch.Growth.allOf(org.apache.beam.sdk.transforms.Watch.Growth.TerminationCondition<InputT, FirstStateT>, org.apache.beam.sdk.transforms.Watch.Growth.TerminationCondition<InputT, SecondStateT>)
. Users can also develop custom termination conditions, for example, one might imagine a condition that terminates after a given time after the first output appears for the input (unlikeWatch.Growth.afterTotalOf(org.joda.time.ReadableDuration)
which operates relative to when the input itself arrives).A
Watch.Growth.TerminationCondition
is provided toWatch.Growth.withTerminationPerInput(TerminationCondition)
and is used to maintain an independent state of the termination condition for every input, represented asStateT
which must be immutable, non-null, and encodable viagetStateCoder()
.All functions take the wall-clock timestamp as
Instant
for convenience of unit-testing custom termination conditions.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
canStopPolling(org.joda.time.Instant now, StateT state)
Called by theWatch
transform to determine whether the given termination state signals thatWatch
should stop callingWatch.Growth.PollFn
for the current input, regardless of whether the lastWatch.Growth.PollResult
was complete or incomplete.StateT
forNewInput(org.joda.time.Instant now, @Nullable InputT input)
Called by theWatch
transform to create a new independent termination state for a newly arrivedInputT
.Coder<StateT>
getStateCoder()
Used to encode the state of thisWatch.Growth.TerminationCondition
.default StateT
onPollComplete(StateT state)
Called by theWatch
transform to compute a new termination state after every poll completion.default StateT
onSeenNewOutput(org.joda.time.Instant now, StateT state)
Called by theWatch
transform to compute a new termination state, in case after calling theWatch.Growth.PollFn
for the current input, theWatch.Growth.PollResult
included a previously unseenOutputT
.java.lang.String
toString(StateT state)
Creates a human-readable representation of the given state of this condition.
-
-
-
Method Detail
-
getStateCoder
Coder<StateT> getStateCoder()
Used to encode the state of thisWatch.Growth.TerminationCondition
.
-
forNewInput
StateT forNewInput(org.joda.time.Instant now, @Nullable InputT input)
Called by theWatch
transform to create a new independent termination state for a newly arrivedInputT
.
-
onSeenNewOutput
default StateT onSeenNewOutput(org.joda.time.Instant now, StateT state)
Called by theWatch
transform to compute a new termination state, in case after calling theWatch.Growth.PollFn
for the current input, theWatch.Growth.PollResult
included a previously unseenOutputT
.
-
onPollComplete
default StateT onPollComplete(StateT state)
Called by theWatch
transform to compute a new termination state after every poll completion.
-
canStopPolling
boolean canStopPolling(org.joda.time.Instant now, StateT state)
Called by theWatch
transform to determine whether the given termination state signals thatWatch
should stop callingWatch.Growth.PollFn
for the current input, regardless of whether the lastWatch.Growth.PollResult
was complete or incomplete.
-
toString
java.lang.String toString(StateT state)
Creates a human-readable representation of the given state of this condition.
-
-