Interface ValueState<T>
-
- Type Parameters:
T
- Type of the value in the state.
- All Superinterfaces:
State
- All Known Subinterfaces:
InternalValueState<K,N,V>
- All Known Implementing Classes:
AbstractValueState
,ForStValueState
,ValueStateAdaptor
@Experimental public interface ValueState<T> extends State
State
interface for partitioned single-value state. The value can be retrieved or updated.The state is accessed and modified by user functions, and checkpointed consistently by the system as part of the distributed snapshots.
The state is only accessible by functions applied on a
KeyedStream
. The key is automatically supplied by the system, so the function always sees the value mapped to the key of the current element. That way, the system can handle stream and state partitioning consistently together.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StateFuture<Void>
asyncUpdate(T value)
Updates the operator state accessible byasyncValue()
to the given value asynchronously.StateFuture<T>
asyncValue()
Returns the current value for the state asynchronously.void
update(T value)
Updates the operator state accessible byvalue()
to the given value.T
value()
Returns the current value for the state.-
Methods inherited from interface org.apache.flink.api.common.state.v2.State
asyncClear, clear
-
-
-
-
Method Detail
-
asyncValue
StateFuture<T> asyncValue()
Returns the current value for the state asynchronously. When the state is not partitioned the returned value is the same for all inputs in a given operator instance. If state partitioning is applied, the value returned depends on the current operator input, as the operator maintains an independent state for each partition. When no value was previously set usingasyncUpdate(Object)
, the future will returnnull
asynchronously.- Returns:
- The
StateFuture
that will return the value corresponding to the current input.
-
asyncUpdate
StateFuture<Void> asyncUpdate(T value)
Updates the operator state accessible byasyncValue()
to the given value asynchronously. The next timeasyncValue()
is called (for the same state partition) the returned state will represent the updated value. When a partitioned state is updated withnull
, the state for the current key will be removed.- Parameters:
value
- The new value for the state.- Returns:
- The
StateFuture
that will trigger the callback when update finishes.
-
value
T value()
Returns the current value for the state. When the state is not partitioned the returned value is the same for all inputs in a given operator instance. If state partitioning is applied, the value returned depends on the current operator input, as the operator maintains an independent state for each partition.If you didn't specify a default value when creating the ValueStateDescriptor this will return
null
when no value was previously set usingupdate(Object)
.- Returns:
- The state value corresponding to the current input.
-
update
void update(T value)
Updates the operator state accessible byvalue()
to the given value. The next timevalue()
is called (for the same state partition) the returned state will represent the updated value. When a partitioned state is updated withnull
, the state for the current key will be removed and the default value is returned on the next access.- Parameters:
value
- The new value for the state.
-
-