Class DefaultStateManager

  • All Implemented Interfaces:
    org.apache.flink.datastream.api.context.StateManager

    public class DefaultStateManager
    extends Object
    implements org.apache.flink.datastream.api.context.StateManager
    The default implementation of StateManager. This class supports eagerly set and reset the current key.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.flink.streaming.api.operators.StreamingRuntimeContext operatorContext  
      protected org.apache.flink.api.common.state.OperatorStateStore operatorStateStore  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultStateManager​(Supplier<Object> currentKeySupplier, BiConsumer<Runnable,​Object> processorWithKey, org.apache.flink.streaming.api.operators.StreamingRuntimeContext operatorContext, org.apache.flink.api.common.state.OperatorStateStore operatorStateStore)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void executeInKeyContext​(Runnable runnable, Object key)
      This method should be used to run a block of code with a specific key context.
      <K> K getCurrentKey()  
      <IN,​ACC,​OUT>
      org.apache.flink.api.common.state.v2.AggregatingState<IN,​OUT>
      getState​(org.apache.flink.api.common.state.AggregatingStateDeclaration<IN,​ACC,​OUT> stateDeclaration)  
      <K,​V>
      org.apache.flink.api.common.state.BroadcastState<K,​V>
      getState​(org.apache.flink.api.common.state.BroadcastStateDeclaration<K,​V> stateDeclaration)  
      <T> org.apache.flink.api.common.state.v2.ListState<T> getState​(org.apache.flink.api.common.state.ListStateDeclaration<T> stateDeclaration)  
      <K,​V>
      org.apache.flink.api.common.state.v2.MapState<K,​V>
      getState​(org.apache.flink.api.common.state.MapStateDeclaration<K,​V> stateDeclaration)  
      <T> org.apache.flink.api.common.state.v2.ReducingState<T> getState​(org.apache.flink.api.common.state.ReducingStateDeclaration<T> stateDeclaration)  
      <T> org.apache.flink.api.common.state.v2.ValueState<T> getState​(org.apache.flink.api.common.state.ValueStateDeclaration<T> stateDeclaration)  
      <IN,​ACC,​OUT>
      Optional<org.apache.flink.api.common.state.v2.AggregatingState<IN,​OUT>>
      getStateOptional​(org.apache.flink.api.common.state.AggregatingStateDeclaration<IN,​ACC,​OUT> stateDeclaration)  
      <K,​V>
      Optional<org.apache.flink.api.common.state.BroadcastState<K,​V>>
      getStateOptional​(org.apache.flink.api.common.state.BroadcastStateDeclaration<K,​V> stateDeclaration)  
      <T> Optional<org.apache.flink.api.common.state.v2.ListState<T>> getStateOptional​(org.apache.flink.api.common.state.ListStateDeclaration<T> stateDeclaration)  
      <K,​V>
      Optional<org.apache.flink.api.common.state.v2.MapState<K,​V>>
      getStateOptional​(org.apache.flink.api.common.state.MapStateDeclaration<K,​V> stateDeclaration)  
      <T> Optional<org.apache.flink.api.common.state.v2.ReducingState<T>> getStateOptional​(org.apache.flink.api.common.state.ReducingStateDeclaration<T> stateDeclaration)  
      <T> Optional<org.apache.flink.api.common.state.v2.ValueState<T>> getStateOptional​(org.apache.flink.api.common.state.ValueStateDeclaration<T> stateDeclaration)  
    • Field Detail

      • operatorContext

        protected final org.apache.flink.streaming.api.operators.StreamingRuntimeContext operatorContext
      • operatorStateStore

        protected final org.apache.flink.api.common.state.OperatorStateStore operatorStateStore
    • Constructor Detail

      • DefaultStateManager

        public DefaultStateManager​(Supplier<Object> currentKeySupplier,
                                   BiConsumer<Runnable,​Object> processorWithKey,
                                   org.apache.flink.streaming.api.operators.StreamingRuntimeContext operatorContext,
                                   org.apache.flink.api.common.state.OperatorStateStore operatorStateStore)
    • Method Detail

      • getCurrentKey

        public <K> K getCurrentKey()
        Specified by:
        getCurrentKey in interface org.apache.flink.datastream.api.context.StateManager
      • getStateOptional

        public <T> Optional<org.apache.flink.api.common.state.v2.ValueState<T>> getStateOptional​(org.apache.flink.api.common.state.ValueStateDeclaration<T> stateDeclaration)
                                                                                          throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <T> org.apache.flink.api.common.state.v2.ValueState<T> getState​(org.apache.flink.api.common.state.ValueStateDeclaration<T> stateDeclaration)
                                                                        throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getStateOptional

        public <T> Optional<org.apache.flink.api.common.state.v2.ListState<T>> getStateOptional​(org.apache.flink.api.common.state.ListStateDeclaration<T> stateDeclaration)
                                                                                         throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <T> org.apache.flink.api.common.state.v2.ListState<T> getState​(org.apache.flink.api.common.state.ListStateDeclaration<T> stateDeclaration)
                                                                       throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getStateOptional

        public <K,​V> Optional<org.apache.flink.api.common.state.v2.MapState<K,​V>> getStateOptional​(org.apache.flink.api.common.state.MapStateDeclaration<K,​V> stateDeclaration)
                                                                                                        throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <K,​V> org.apache.flink.api.common.state.v2.MapState<K,​V> getState​(org.apache.flink.api.common.state.MapStateDeclaration<K,​V> stateDeclaration)
                                                                                      throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getStateOptional

        public <T> Optional<org.apache.flink.api.common.state.v2.ReducingState<T>> getStateOptional​(org.apache.flink.api.common.state.ReducingStateDeclaration<T> stateDeclaration)
                                                                                             throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <T> org.apache.flink.api.common.state.v2.ReducingState<T> getState​(org.apache.flink.api.common.state.ReducingStateDeclaration<T> stateDeclaration)
                                                                           throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getStateOptional

        public <IN,​ACC,​OUT> Optional<org.apache.flink.api.common.state.v2.AggregatingState<IN,​OUT>> getStateOptional​(org.apache.flink.api.common.state.AggregatingStateDeclaration<IN,​ACC,​OUT> stateDeclaration)
                                                                                                                                throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <IN,​ACC,​OUT> org.apache.flink.api.common.state.v2.AggregatingState<IN,​OUT> getState​(org.apache.flink.api.common.state.AggregatingStateDeclaration<IN,​ACC,​OUT> stateDeclaration)
                                                                                                              throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getStateOptional

        public <K,​V> Optional<org.apache.flink.api.common.state.BroadcastState<K,​V>> getStateOptional​(org.apache.flink.api.common.state.BroadcastStateDeclaration<K,​V> stateDeclaration)
                                                                                                           throws Exception
        Specified by:
        getStateOptional in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • getState

        public <K,​V> org.apache.flink.api.common.state.BroadcastState<K,​V> getState​(org.apache.flink.api.common.state.BroadcastStateDeclaration<K,​V> stateDeclaration)
                                                                                         throws Exception
        Specified by:
        getState in interface org.apache.flink.datastream.api.context.StateManager
        Throws:
        Exception
      • executeInKeyContext

        public void executeInKeyContext​(Runnable runnable,
                                        Object key)
        This method should be used to run a block of code with a specific key context. The original key must be reset after the block is executed.