Class StateMap<K,N,S>
java.lang.Object
org.apache.flink.runtime.state.heap.StateMap<K,N,S>
- Type Parameters:
K- type of keyN- type of namespaceS- type of state
- All Implemented Interfaces:
Iterable<StateEntry<K,N, S>>
- Direct Known Subclasses:
CopyOnWriteStateMap
Base class for state maps.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancontainsKey(K key, N namespace) Returns whether this map contains the specified key/namespace composite key.abstract SReturns the state for the composite of active key and given namespace.abstract InternalKvState.StateIncrementalVisitor<K,N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) booleanisEmpty()Returns whether thisStateMapis empty.abstract voidMaps the specified key/namespace composite key to the specified value.abstract SputAndGetOld(K key, N namespace, S state) Maps the composite of active key and given namespace to the specified state.voidreleaseSnapshot(StateMapSnapshot<K, N, S, ? extends StateMap<K, N, S>> snapshotToRelease) Releases a snapshot for thisStateMap.abstract voidRemoves the mapping for the composite of active key and given namespace.abstract SremoveAndGetOld(K key, N namespace) Removes the mapping for the composite of active key and given namespace, returning the state that was found under the entry.abstract intsize()Returns the total number of entries in thisStateMap.abstract intsizeOfNamespace(Object namespace) Creates a snapshot of thisStateMap, to be written in checkpointing.abstract <T> voidtransform(K key, N namespace, T value, StateTransformationFunction<S, T> transformation) Applies the givenStateTransformationFunctionto the state (1st input argument), using the given value as second input argument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Constructor Details
-
StateMap
public StateMap()
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returns whether thisStateMapis empty. -
size
public abstract int size()Returns the total number of entries in thisStateMap.- Returns:
- the number of entries in this
StateMap.
-
get
Returns the state for the composite of active key and given namespace.- 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
nullif no mapping for the specified key is found.
-
containsKey
Returns whether this map contains the specified key/namespace composite key.- Parameters:
key- the key in the composite key to search for. Not null.namespace- the namespace in the composite key to search for. Not null.- Returns:
trueif this map contains the specified key/namespace composite key,falseotherwise.
-
put
Maps the specified key/namespace composite key to the specified value. This method should be preferred overputAndGetOld(K, N, S)(key, Namespace, State) when the caller is not interested in the old state.- Parameters:
key- the key. Not null.namespace- the namespace. Not null.state- the state. Can be null.
-
putAndGetOld
Maps the composite of active key and given namespace to the specified state. Returns the previous state that was registered under the composite key.- Parameters:
key- the key. Not null.namespace- the namespace. Not null.state- the state. Can be null.- Returns:
- the state of any previous mapping with the specified key or
nullif there was no such mapping.
-
remove
Removes the mapping for the composite of active key and given namespace. This method should be preferred overremoveAndGetOld(K, N)when the caller is not interested in the old state.- Parameters:
key- the key of the mapping to remove. Not null.namespace- the namespace of the mapping to remove. Not null.
-
removeAndGetOld
Removes the mapping for the composite of active key and given namespace, returning the state that was found under the entry.- Parameters:
key- the key of the mapping to remove. Not null.namespace- the namespace of the mapping to remove. Not null.- Returns:
- the state of the removed mapping or
nullif no mapping for the specified key was found.
-
transform
public abstract <T> void transform(K key, N namespace, T value, StateTransformationFunction<S, T> transformation) throws ExceptionApplies the givenStateTransformationFunctionto the state (1st input argument), using the given value as second input argument. The result ofStateTransformationFunction.apply(Object, Object)is then stored as the new state. This function is basically an optimization for get-update-put pattern.- Parameters:
key- the key. Not null.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.
-
getKeys
-
getStateIncrementalVisitor
public abstract InternalKvState.StateIncrementalVisitor<K,N, getStateIncrementalVisitorS> (int recommendedMaxNumberOfReturnedRecords) -
stateSnapshot
Creates a snapshot of thisStateMap, to be written in checkpointing. Users should callreleaseSnapshot(StateMapSnapshot)after using the returned object.- Returns:
- a snapshot from this
StateMap, for checkpointing.
-
releaseSnapshot
Releases a snapshot for thisStateMap. This method should be called once a snapshot is no more needed.- Parameters:
snapshotToRelease- the snapshot to release, which was previously created by this state map.
-
sizeOfNamespace
-