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
public abstract class StateMap<K,N,S> extends Object implements Iterable<StateEntry<K,N,S>>
Base class for state maps.
-
-
Constructor Summary
Constructors Constructor Description StateMap()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancontainsKey(K key, N namespace)Returns whether this map contains the specified key/namespace composite key.abstract Sget(K key, N namespace)Returns the state for the composite of active key and given namespace.abstract Stream<K>getKeys(N namespace)abstract InternalKvState.StateIncrementalVisitor<K,N,S>getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords)booleanisEmpty()Returns whether thisStateMapis empty.abstract voidput(K key, N namespace, S state)Maps 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 voidremove(K key, N namespace)Removes 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)abstract StateMapSnapshot<K,N,S,? extends StateMap<K,N,S>>stateSnapshot()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, wait
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
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
public abstract S get(K key, N namespace)
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
public abstract boolean containsKey(K key, N namespace)
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
public abstract void put(K key, N namespace, S state)
Maps the specified key/namespace composite key to the specified value. This method should be preferred over#putAndGetOld(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
public abstract S putAndGetOld(K key, N namespace, S state)
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
public abstract void remove(K key, N namespace)
Removes the mapping for the composite of active key and given namespace. This method should be preferred over#removeAndGetOld(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
public abstract S removeAndGetOld(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.- 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 Exception
Applies 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.
-
getStateIncrementalVisitor
public abstract InternalKvState.StateIncrementalVisitor<K,N,S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords)
-
stateSnapshot
@Nonnull public abstract StateMapSnapshot<K,N,S,? extends StateMap<K,N,S>> 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
public void releaseSnapshot(StateMapSnapshot<K,N,S,? extends StateMap<K,N,S>> snapshotToRelease)
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
@VisibleForTesting public abstract int sizeOfNamespace(Object namespace)
-
-