S
- The type of the State objects created from this StateDescriptor
.T
- The type of the value of the state object described by this state descriptor.@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 StateBinder
using bind(StateBinder)
.
Subclasses must correctly implement equals(Object)
and hashCode()
.
Modifier and Type | Class and Description |
---|---|
static class |
StateDescriptor.Type
An enumeration of the types of supported states.
|
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(StateBinder stateBinder)
Creates a new
State on the given StateBinder . |
boolean |
equals(Object o) |
T |
getDefaultValue()
Returns the default value.
|
String |
getName()
Returns the name of this
StateDescriptor . |
String |
getQueryableStateName()
Returns the queryable state name.
|
TypeSerializer<T> |
getSerializer()
Returns the
TypeSerializer that can be used to serialize the value in the state. |
abstract StateDescriptor.Type |
getType() |
int |
hashCode() |
void |
initializeSerializerUnlessSet(ExecutionConfig executionConfig)
Initializes the serializer, unless it has been initialized before.
|
boolean |
isQueryable()
Returns whether the state created from this descriptor is queryable.
|
boolean |
isSerializerInitialized()
Checks whether the serializer has been initialized.
|
void |
setQueryable(String queryableStateName)
Sets the name for queries of state created from this descriptor.
|
String |
toString() |
protected final String name
@Nullable protected TypeSerializer<T> serializer
initializeSerializerUnlessSet(ExecutionConfig)
method
is called.protected StateDescriptor(String name, TypeSerializer<T> serializer, @Nullable 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, @Nullable 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, @Nullable 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 void setQueryable(String queryableStateName)
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.
queryableStateName
- State name for queries (unique name per job)IllegalStateException
- If queryable state name already set@Nullable public String getQueryableStateName()
null
if not set.public boolean isQueryable()
true
if state is queryable, false
otherwise.public abstract S bind(StateBinder stateBinder) throws Exception
State
on the given StateBinder
.public boolean isSerializerInitialized()
ExecutionConfig
via
initializeSerializerUnlessSet(ExecutionConfig)
.public void initializeSerializerUnlessSet(ExecutionConfig executionConfig)
executionConfig
- The execution config to use when creating the serializer.public abstract StateDescriptor.Type getType()
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.