Annotation Interface DoFn.TimerId

Enclosing class:
DoFn<InputT extends @Nullable Object,OutputT extends @Nullable Object>

@Documented @Retention(RUNTIME) @Target({FIELD,PARAMETER}) public static @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
    Modifier and Type
    Optional Element
    Description
    The timer ID.
  • Element Details

    • value

      String value
      The timer ID.
      Default:
      ""