Annotation Type DoFn.StateId


  • @Documented
    @Retention(RUNTIME)
    @Target({FIELD,PARAMETER})
    @Experimental(STATE)
    public static @interface DoFn.StateId
    Annotation for declaring and dereferencing state cells.

    To declare a state cell, create a field of type StateSpec annotated with a DoFn.StateId. To use the cell during processing, add a parameter of the appropriate State subclass to your @ProcessElement or @OnTimer method, and annotate it with DoFn.StateId. See the following code for an example:

    new DoFn<KV<Key, Foo>, Baz>() {
    
      @StateId("my-state-id")
      private final StateSpec<ValueState<MyState>> myStateSpec =
           StateSpecs.value(new MyStateCoder());
    
      @ProcessElement
       public void processElement(
           @Element InputT element,
          @StateId("my-state-id") ValueState<MyState> myState) {
         myState.read();
         myState.write(...);
       }
     }
     

    State is subject to the following validity conditions:

    • Each state ID must be declared at most once.
    • Any state referenced in a parameter must be declared with the same state type.
    • State declarations must be final.
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String value
      The state ID.
    • Element Detail

      • value

        java.lang.String value
        The state ID.