Package org.apache.beam.sdk.transforms
Annotation Interface DoFn.TimerId
Annotation for declaring and dereferencing timers.
To declare a timer, create a field of type TimerSpec
annotated with a DoFn.TimerId
. To use the cell during processing, add a parameter of the type Timer
to your
@ProcessElement
or @OnTimer
method, and annotate it with
DoFn.TimerId
. See the following code for an example:
new DoFn<KV<Key, Foo>, Baz>() {
@TimerId("my-timer-id")
private final TimerSpec myTimer = TimerSpecs.timerForDomain(TimeDomain.EVENT_TIME);
@ProcessElement
public void processElement(
@Element InputT element,
@TimerId("my-timer-id") Timer myTimer) {
myTimer.offset(Duration.standardSeconds(...)).setRelative();
}
@OnTimer("my-timer-id")
public void onMyTimer() {
...
}
}
Timers are subject to the following validity conditions:
- Each timer must have a distinct id.
- Any timer referenced in a parameter must be declared.
- Timer declarations must be final.
- All declared timers must have a corresponding callback annotated with
@OnTimer
.
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
String valueThe timer ID.- Default:
""
-