Class StateDescriptor<S extends State,T>
- java.lang.Object
-
- org.apache.flink.api.common.state.StateDescriptor<S,T>
-
- Type Parameters:
S- The type of the State objects created from thisStateDescriptor.T- The type of the value of the state object described by this state descriptor.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AggregatingStateDescriptor,ListStateDescriptor,MapStateDescriptor,ReducingStateDescriptor,ValueStateDescriptor
@PublicEvolving public abstract class StateDescriptor<S extends State,T> extends Object implements Serializable
Base class for state descriptors. AStateDescriptoris used for creating partitionedStatein stateful operations.Subclasses must correctly implement
equals(Object)andhashCode().- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStateDescriptor.TypeAn enumeration of the types of supported states.
-
Field Summary
Fields Modifier and Type Field Description protected TdefaultValueDeprecated.To make the semantics more clear, user should manually manage the default value if the contents of the state isnullprotected StringnameName that uniquely identifies state created from this StateDescriptor.
-
Constructor Summary
Constructors Modifier Constructor Description protectedStateDescriptor(String name, Class<T> type, T defaultValue)Create a newStateDescriptorwith the given name and the given type information.protectedStateDescriptor(String name, TypeInformation<T> typeInfo, T defaultValue)Create a newStateDescriptorwith the given name and the given type information.protectedStateDescriptor(String name, TypeSerializer<T> serializer, T defaultValue)Create a newStateDescriptorwith the given name and the given type serializer.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidenableTimeToLive(StateTtlConfig ttlConfig)Configures optional activation of state time-to-live (TTL).booleanequals(Object o)TgetDefaultValue()Returns the default value.StringgetName()Returns the name of thisStateDescriptor.StringgetQueryableStateName()Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.TypeSerializer<T>getSerializer()Returns theTypeSerializerthat can be used to serialize the value in the state.StateTtlConfiggetTtlConfig()abstract StateDescriptor.TypegetType()inthashCode()voidinitializeSerializerUnlessSet(ExecutionConfig executionConfig)Initializes the serializer, unless it has been initialized before.booleanisQueryable()Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.booleanisSerializerInitialized()Checks whether the serializer has been initialized.voidsetQueryable(String queryableStateName)Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.StringtoString()
-
-
-
Field Detail
-
name
protected final String name
Name that uniquely identifies state created from this StateDescriptor.
-
defaultValue
@Nullable @Deprecated protected transient T defaultValue
Deprecated.To make the semantics more clear, user should manually manage the default value if the contents of the state isnullThe default value returned by the state when no other value is bound to a key.
-
-
Constructor Detail
-
StateDescriptor
protected StateDescriptor(String name, TypeSerializer<T> serializer, @Nullable T defaultValue)
Create a newStateDescriptorwith the given name and the given type serializer.- Parameters:
name- The name of theStateDescriptor.serializer- The type serializer for the values in the state.defaultValue- The default value that will be set when requesting state without setting a value before.
-
StateDescriptor
protected StateDescriptor(String name, TypeInformation<T> typeInfo, @Nullable T defaultValue)
Create a newStateDescriptorwith the given name and the given type information.- Parameters:
name- The name of theStateDescriptor.typeInfo- The type information for the values in the state.defaultValue- The default value that will be set when requesting state without setting a value before.
-
StateDescriptor
protected StateDescriptor(String name, Class<T> type, @Nullable T defaultValue)
Create a newStateDescriptorwith the given name and the given type information.If this constructor fails (because it is not possible to describe the type via a class), consider using the
StateDescriptor(String, TypeInformation, Object)constructor.- Parameters:
name- The name of theStateDescriptor.type- The class of the type of values in the state.defaultValue- The default value that will be set when requesting state without setting a value before.
-
-
Method Detail
-
getName
public String getName()
Returns the name of thisStateDescriptor.
-
getDefaultValue
public T getDefaultValue()
Returns the default value.
-
getSerializer
public TypeSerializer<T> getSerializer()
Returns theTypeSerializerthat can be used to serialize the value in the state. Note that the serializer may initialized lazily and is only guaranteed to exist after callinginitializeSerializerUnlessSet(ExecutionConfig).
-
setQueryable
@Deprecated public void setQueryable(String queryableStateName)
Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.Sets the name for queries of state created from this descriptor.If a name is set, the created state will be published for queries during runtime. The name needs to be unique per job. If there is another state instance published under the same name, the job will fail during runtime.
- Parameters:
queryableStateName- State name for queries (unique name per job)- Throws:
IllegalStateException- If queryable state name already set
-
getQueryableStateName
@Nullable @Deprecated public String getQueryableStateName()
Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.Returns the queryable state name.- Returns:
- Queryable state name or
nullif not set.
-
isQueryable
@Deprecated public boolean isQueryable()
Deprecated.The Queryable State feature is deprecated since Flink 1.18, and will be removed in a future Flink major version.Returns whether the state created from this descriptor is queryable.- Returns:
trueif state is queryable,falseotherwise.
-
enableTimeToLive
public void enableTimeToLive(StateTtlConfig ttlConfig)
Configures optional activation of state time-to-live (TTL).State user value will expire, become unavailable and be cleaned up in storage depending on configured
StateTtlConfig.If enabling the TTL configuration, the field
defaultValuewill be invalid.- Parameters:
ttlConfig- configuration of state TTL
-
getTtlConfig
@Nonnull @Internal public StateTtlConfig getTtlConfig()
-
isSerializerInitialized
public boolean isSerializerInitialized()
Checks whether the serializer has been initialized. Serializer initialization is lazy, to allow parametrization of serializers with anExecutionConfigviainitializeSerializerUnlessSet(ExecutionConfig).- Returns:
- True if the serializers have been initialized, false otherwise.
-
initializeSerializerUnlessSet
public void initializeSerializerUnlessSet(ExecutionConfig executionConfig)
Initializes the serializer, unless it has been initialized before.- Parameters:
executionConfig- The execution config to use when creating the serializer.
-
getType
public abstract StateDescriptor.Type getType()
-
-