@Experimental(value=TIMERS) public interface Timer
See TimeDomain
for details on the time domains available.
In a DoFn
, a Timer
is specified by a TimerSpec
annotated with DoFn.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.
Modifier and Type | Method and Description |
---|---|
Timer |
align(Duration period)
Aligns the target timestamp used by
setRelative() to the next boundary of period . |
void |
clear()
Clears a timer.
|
Instant |
getCurrentRelativeTime()
Returns the current relative time used by
setRelative() and offset(org.joda.time.Duration) . |
Timer |
offset(Duration offset)
Offsets the target timestamp used by
setRelative() by the given duration. |
void |
set(Instant absoluteTime)
Sets or resets the time in the timer's
TimeDomain 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(Instant outputTime)
Sets event time timer's output timestamp.
|
void set(Instant absoluteTime)
TimeDomain
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 use setRelative()
.
If the output timestamp
has not been explicitly set then the
default output timestamp per TimeDomain
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.
void setRelative()
offset(Duration)
and align(Duration)
.
If the output timestamp
has not been explicitly set then the
default output timestamp per TimeDomain
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.
void clear()
Timer offset(Duration offset)
setRelative()
by the given duration.Timer align(Duration period)
setRelative()
to the next boundary of period
.Timer withOutputTimestamp(Instant outputTime)
Timer withNoOutputTimestamp()
Instant getCurrentRelativeTime()
setRelative()
and offset(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.