S
- The type of the State objects created from this StateDescriptor
.@PublicEvolving public abstract class StateDescriptor<S extends State,T> extends Object implements Serializable
StateDescriptor
is used for creating partitioned
State
in stateful operations. This contains the name and can create an actual state
object given a StateBackend
using bind(StateBackend)
.
Subclasses must correctly implement equals(Object)
and hashCode()
.
Modifier and Type | Field and Description |
---|---|
protected T |
defaultValue
The default value returned by the state when no other value is bound to a key
|
protected String |
name
Name that uniquely identifies state created from this StateDescriptor.
|
protected TypeSerializer<T> |
serializer
The serializer for the type.
|
Modifier | Constructor and Description |
---|---|
protected |
StateDescriptor(String name,
Class<T> type,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type information. |
protected |
StateDescriptor(String name,
TypeInformation<T> typeInfo,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type information. |
protected |
StateDescriptor(String name,
TypeSerializer<T> serializer,
T defaultValue)
Create a new
StateDescriptor with the given name and the given type serializer. |
Modifier and Type | Method and Description |
---|---|
abstract S |
bind(StateBackend stateBackend)
Creates a new
State on the given StateBackend . |
abstract boolean |
equals(Object o) |
T |
getDefaultValue()
Returns the default value.
|
String |
getName()
Returns the name of this
StateDescriptor . |
TypeSerializer<T> |
getSerializer()
Returns the
TypeSerializer that can be used to serialize the value in the state. |
abstract int |
hashCode() |
void |
initializeSerializerUnlessSet(ExecutionConfig executionConfig)
Initializes the serializer, unless it has been initialized before.
|
boolean |
isSerializerInitialized()
Checks whether the serializer has been initialized.
|
String |
toString() |
protected final String name
protected TypeSerializer<T> serializer
protected transient T defaultValue
protected StateDescriptor(String name, TypeSerializer<T> serializer, T defaultValue)
StateDescriptor
with the given name and the given type serializer.name
- The name of the StateDescriptor
.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.protected StateDescriptor(String name, TypeInformation<T> typeInfo, T defaultValue)
StateDescriptor
with the given name and the given type information.name
- The name of the StateDescriptor
.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.protected StateDescriptor(String name, Class<T> type, T defaultValue)
StateDescriptor
with 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.
name
- The name of the StateDescriptor
.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.public String getName()
StateDescriptor
.public T getDefaultValue()
public TypeSerializer<T> getSerializer()
TypeSerializer
that can be used to serialize the value in the state.
Note that the serializer may initialized lazily and is only guaranteed to exist after
calling initializeSerializerUnlessSet(ExecutionConfig)
.public abstract S bind(StateBackend stateBackend) throws Exception
State
on the given StateBackend
.public boolean isSerializerInitialized()
ExecutionConfig
via
initializeSerializerUnlessSet(ExecutionConfig)
.public void initializeSerializerUnlessSet(ExecutionConfig executionConfig)
executionConfig
- The execution config to use when creating the serializer.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.