|Modifier and Type||Method and Description|
Gets the serializer that recognizes the current serialization schema of the state.
Gets the serializer that recognizes the previous serialization schema of the state.
For restored state, register a new serializer that potentially has a new serialization schema.
public static <T> StateSerializerProvider<T> fromRestoredState(TypeSerializerSnapshot<T> stateSerializerSnapshot)
StateSerializerProviderfor restored state from the previous serializer's snapshot.
Once a new serializer is registered for the state, it should be provided via
T- the type of the state.
stateSerializerSnapshot- the previous serializer's snapshot.
StateSerializerProviderfor restored state.
public static <T> StateSerializerProvider<T> fromNewState(TypeSerializer<T> registeredStateSerializer)
StateSerializerProviderfor new state from the registered state serializer.
T- the type of the state.
registeredStateSerializer- the new state's registered serializer.
StateSerializerProviderfor new state.
@Nonnull public abstract TypeSerializer<T> currentSchemaSerializer()
If this provider was created from a restored state's serializer snapshot, while a
new serializer (with a new schema) was not registered for the state (i.e., because
the state was never accessed after it was restored), then the schema of state remains
identical. Therefore, in this case, it is guaranteed that the serializer returned by
this method is the same as the one returned by
If this provider was created from new state, then this always returns the serializer that the new state was registered with.
@Nonnull public abstract TypeSerializer<T> previousSchemaSerializer()
This method can only be used if this provider was created from a restored state's serializer snapshot. If this provider was created from new state, then this method is irrelevant, since there doesn't exist any previous version of the state schema.
@Nonnull public abstract TypeSerializerSchemaCompatibility<T> registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer)
Users are allowed to register serializers for state only once. Therefore, this method is irrelevant if this provider was created from new state, since a state serializer had been registered already.
For the case where this provider was created from restored state, then this method should be called at most once. The new serializer will be checked for its schema compatibility with the previous serializer's schema, and returned to the caller. The caller is responsible for checking the result and react appropriately to it, as follows:
TypeSerializerSchemaCompatibility.isCompatibleAsIs(): nothing needs to be done.
currentSchemaSerializer()now returns the newly registered serializer.
TypeSerializerSchemaCompatibility.isCompatibleAfterMigration()()}: state needs to be migrated before the serializer returned by
currentSchemaSerializer()can be used. The migration should be performed by reading the state with
previousSchemaSerializer(), and then writing it again with
TypeSerializerSchemaCompatibility.isIncompatible(): the registered serializer is incompatible.
currentSchemaSerializer()can no longer return a serializer for the state, and therefore this provider shouldn't be used anymore.
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.