org.apache.storm.streams.processors

## Class UpdateStateByKeyProcessor<K,V,R>

- java.lang.Object
- - org.apache.storm.streams.processors.UpdateStateByKeyProcessor<K,V,R>

- All Implemented Interfaces:
    Serializable, Processor<Pair<K,V>>, StatefulProcessor<K,R>

      public class UpdateStateByKeyProcessor<K,V,R>
      extends Object
      implements StatefulProcessor<K,R>

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ProcessorContext` | `context`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UpdateStateByKeyProcessor(StateUpdater<V,R> stateUpdater)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `execute(Pair<K,V> input)` Execute some operation on the input value.
    `void` | `execute(T input, String streamId)` Executes some operations on the input and possibly emits some results.
    `protected void` | `finish()` This is triggered to signal the end of the current batch of values.
    `void` | `init(ProcessorContext context)` Initializes the processor.
    `void` | `initState(KeyValueState<K,R> keyValueState)` Initialize the state of the processor with the given `KeyValueState`.
    `protected <R> void` | `mayBeForwardAggUpdate(Supplier<R> result)` Forwards the result update to downstream processors.
    `void` | `punctuate(String stream)` Punctuation marks end of a batch which can be used to compute and pass the results of one stage in the pipeline to the next.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### context

          protected ProcessorContext context

  - ### Constructor Detail

    - #### UpdateStateByKeyProcessor

          public UpdateStateByKeyProcessor(StateUpdater<V,R> stateUpdater)

  - ### Method Detail

    - #### initState

          public void initState(KeyValueState<K,R> keyValueState)

      Description copied from interface: `StatefulProcessor`

      Initialize the state of the processor with the given `KeyValueState`.

      Specified by:
        `initState` in interface `StatefulProcessor<K,R>`
      Parameters:
        `keyValueState` - the key-value state

    - #### execute

          protected void execute(Pair<K,V> input)

      Execute some operation on the input value. Sub classes can override this when then don't care about the source stream from where the input is received.
      Parameters:
        `input` - the input

    - #### init

          public void init(ProcessorContext context)

      Initializes the processor. This is typically invoked from the underlying storm bolt’s prepare method.

      Specified by:
        `init` in interface `Processor<T>`
      Parameters:
        `context` - the processor context

    - #### execute

          public void execute(T input,
                              String streamId)

      Executes some operations on the input and possibly emits some results.

      Processors that do not care about the source stream should override `BaseProcessor.execute(Object)` instead.
      Specified by:
        `execute` in interface `Processor<T>`
      Parameters:
        `input` - the input to be processed
        `streamId` - the source stream id from where the input is received

    - #### punctuate

          public void punctuate(String stream)

      Punctuation marks end of a batch which can be used to compute and pass the results of one stage in the pipeline to the next. For e.g. emit the results of an aggregation.

      Specified by:
        `punctuate` in interface `Processor<T>`
      Parameters:
        `stream` - the stream id on which the punctuation arrived

    - #### finish

          protected void finish()

      This is triggered to signal the end of the current batch of values. Sub classes can override this to emit the result of a batch of values, for e.g. to emit the result of an aggregate or join operation on a batch of values. If a processor does per-value operation like filter, map etc, they can choose to ignore this.

    - #### mayBeForwardAggUpdate

          protected final <R> void mayBeForwardAggUpdate(Supplier<R> result)

      Forwards the result update to downstream processors. Processors that operate on a batch of tuples, like aggregation, join etc can use this to emit the partial results on each input if they are operating in non-windowed mode.
      Type Parameters:
        `R` - the result type
      Parameters:
        `result` - the result function

Copyright © 2021 The Apache Software Foundation. All rights reserved.