Interface Timer
-
@Experimental(TIMERS) public interface Timer
A timer for a specified time domain that can be set to register the desire for further processing at particular time in its specified time domain.See
TimeDomain
for details on the time domains available.In a
DoFn
, aTimer
is specified by aTimerSpec
annotated withDoFn.TimerId
.An implementation of
Timer
is implicitly scoped - it may be scoped to a key and window, or a key, window, and trigger, etc.A timer exists in one of two states: set or unset. A timer can be set only for a single time per scope.
Timer callbacks are not guaranteed to be called immediately according to the local view of the
TimeDomain
, but will be called at some time after the requested time, in timestamp order.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Timer
align(org.joda.time.Duration period)
Aligns the target timestamp used bysetRelative()
to the next boundary ofperiod
.void
clear()
Clears a timer.org.joda.time.Instant
getCurrentRelativeTime()
Returns the current relative time used bysetRelative()
andoffset(org.joda.time.Duration)
.Timer
offset(org.joda.time.Duration offset)
Offsets the target timestamp used bysetRelative()
by the given duration.void
set(org.joda.time.Instant absoluteTime)
Sets or resets the time in the timer'sTimeDomain
at which it should fire.void
setRelative()
Sets the timer relative to the current time, according to any offset and alignment specified.Timer
withNoOutputTimestamp()
Asserts that there is no output timestamp.Timer
withOutputTimestamp(org.joda.time.Instant outputTime)
Sets event time timer's output timestamp.
-
-
-
Method Detail
-
set
void set(org.joda.time.Instant absoluteTime)
Sets or resets the time in the timer'sTimeDomain
at which it should fire. If the timer was already set, resets it to the new requested time.For
TimeDomain.PROCESSING_TIME
, the behavior is be unpredictable, since processing time timers are ignored after a window has expired. Instead, it is recommended to usesetRelative()
.If the
output timestamp
has not been explicitly set then the default output timestamp perTimeDomain
is:TimeDomain.EVENT_TIME
: the firing time of this new timer.TimeDomain.PROCESSING_TIME
: current element's timestamp or current timer's output timestamp.TimeDomain.SYNCHRONIZED_PROCESSING_TIME
: current element's timestamp or current timer's output timestamp.
-
setRelative
void setRelative()
Sets the timer relative to the current time, according to any offset and alignment specified. Usingoffset(Duration)
andalign(Duration)
.If the
output timestamp
has not been explicitly set then the default output timestamp perTimeDomain
is:TimeDomain.EVENT_TIME
: the firing time of this new timer.TimeDomain.PROCESSING_TIME
: current element's timestamp or current timer's output timestamp.TimeDomain.SYNCHRONIZED_PROCESSING_TIME
: current element's timestamp or current timer's output timestamp.
-
clear
void clear()
Clears a timer. Previous set timers will become unset.
-
offset
Timer offset(org.joda.time.Duration offset)
Offsets the target timestamp used bysetRelative()
by the given duration.
-
align
Timer align(org.joda.time.Duration period)
Aligns the target timestamp used bysetRelative()
to the next boundary ofperiod
.
-
withOutputTimestamp
Timer withOutputTimestamp(org.joda.time.Instant outputTime)
Sets event time timer's output timestamp. Output watermark will be held at this timestamp until the timer fires.
-
withNoOutputTimestamp
Timer withNoOutputTimestamp()
Asserts that there is no output timestamp. The output watermark will not be held up, and it is illegal to output messages from this timer using the default output timestamp.
-
getCurrentRelativeTime
org.joda.time.Instant getCurrentRelativeTime()
Returns the current relative time used bysetRelative()
andoffset(org.joda.time.Duration)
. This can be used by a client that self-manages relative timers (e.g. one that stores the current timer time in a state variable.
-
-