Class StateTable<K,​N,​S>

    • Field Detail

      • keyContext

        protected final InternalKeyContext<K> keyContext
        The key context view on the backend. This provides information, such as the currently active key.
      • keySerializer

        protected final TypeSerializer<K> keySerializer
        The serializer of the key.
      • keyGroupRange

        protected final KeyGroupRange keyGroupRange
        The current key group range.
      • keyGroupedStateMaps

        protected final StateMap<K,​N,​S>[] keyGroupedStateMaps
        Map for holding the actual state objects. The outer array represents the key-groups. All array positions will be initialized with an empty state map.
    • Constructor Detail

      • StateTable

        public StateTable​(InternalKeyContext<K> keyContext,
                          RegisteredKeyValueStateBackendMetaInfo<N,​S> metaInfo,
                          TypeSerializer<K> keySerializer)
        Parameters:
        keyContext - the key context provides the key scope for all put/get/delete operations.
        metaInfo - the meta information, including the type serializer for state copy-on-write.
        keySerializer - the serializer of the key.
    • Method Detail

      • createStateMap

        protected abstract StateMap<K,​N,​S> createStateMap()
      • isEmpty

        public boolean isEmpty()
        Returns whether this StateTable is empty.
        Returns:
        true if this StateTable has no elements, false otherwise.
        See Also:
        size()
      • size

        public int size()
        Returns the total number of entries in this StateTable. This is the sum of both sub-tables.
        Returns:
        the number of entries in this StateTable.
      • get

        public S get​(N namespace)
        Returns the state of the mapping for the composite of active key and given namespace.
        Parameters:
        namespace - the namespace. Not null.
        Returns:
        the states of the mapping with the specified key/namespace composite key, or null if no mapping for the specified key is found.
      • containsKey

        public boolean containsKey​(N namespace)
        Returns whether this table contains a mapping for the composite of active key and given namespace.
        Parameters:
        namespace - the namespace in the composite key to search for. Not null.
        Returns:
        true if this map contains the specified key/namespace composite key, false otherwise.
      • put

        public void put​(N namespace,
                        S state)
        Maps the composite of active key and given namespace to the specified state.
        Parameters:
        namespace - the namespace. Not null.
        state - the state. Can be null.
      • remove

        public void remove​(N namespace)
        Removes the mapping for the composite of active key and given namespace. This method should be preferred over #removeAndGetOld(N) when the caller is not interested in the old state.
        Parameters:
        namespace - the namespace of the mapping to remove. Not null.
      • removeAndGetOld

        public S removeAndGetOld​(N namespace)
        Removes the mapping for the composite of active key and given namespace, returning the state that was found under the entry.
        Parameters:
        namespace - the namespace of the mapping to remove. Not null.
        Returns:
        the state of the removed mapping or null if no mapping for the specified key was found.
      • transform

        public <T> void transform​(N namespace,
                                  T value,
                                  StateTransformationFunction<S,​T> transformation)
                           throws Exception
        Applies the given StateTransformationFunction to the state (1st input argument), using the given value as second input argument. The result of StateTransformationFunction.apply(Object, Object) is then stored as the new state. This function is basically an optimization for get-update-put pattern.
        Parameters:
        namespace - the namespace. Not null.
        value - the value to use in transforming the state. Can be null.
        transformation - the transformation function.
        Throws:
        Exception - if some exception happens in the transformation function.
      • get

        public S get​(K key,
                     N namespace)
        Returns the state for the composite of active key and given namespace. This is typically used by queryable state.
        Parameters:
        key - the key. Not null.
        namespace - the namespace. Not null.
        Returns:
        the state of the mapping with the specified key/namespace composite key, or null if no mapping for the specified key is found.
      • getKeys

        public Stream<K> getKeys​(N namespace)
      • getKeysAndNamespaces

        public Stream<Tuple2<K,​N>> getKeysAndNamespaces()
      • getKeyGroupOffset

        public int getKeyGroupOffset()
      • getNamespaceSerializer

        public TypeSerializer<N> getNamespaceSerializer()
      • put

        public void put​(K key,
                        int keyGroup,
                        N namespace,
                        S state)
      • keyGroupReader

        @Nonnull
        public StateSnapshotKeyGroupReader keyGroupReader​(int readVersion)
        Description copied from interface: StateSnapshotRestore
        This method returns a StateSnapshotKeyGroupReader that can be used to restore the state on a per-key-group basis. This method tries to return a reader for the given version hint.
        Specified by:
        keyGroupReader in interface StateSnapshotRestore
        Parameters:
        readVersion - the required version of the state to read.
        Returns:
        a reader that reads state by key-groups, for the given read version.