本文整理汇总了Java中org.apache.flink.api.common.state.StateDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java StateDescriptor类的具体用法?Java StateDescriptor怎么用?Java StateDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StateDescriptor类属于org.apache.flink.api.common.state包,在下文中一共展示了StateDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canRestoreFrom
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
public boolean canRestoreFrom(RegisteredBackendStateMetaInfo<?, ?> other) {
if (this == other) {
return true;
}
if (null == other) {
return false;
}
if (!stateType.equals(StateDescriptor.Type.UNKNOWN)
&& !other.stateType.equals(StateDescriptor.Type.UNKNOWN)
&& !stateType.equals(other.stateType)) {
return false;
}
if (!name.equals(other.getName())) {
return false;
}
return (stateSerializer.canRestoreFrom(other.stateSerializer)) &&
(namespaceSerializer.canRestoreFrom(other.namespaceSerializer)
// we also check if there is just a migration proxy that should be replaced by any real serializer
|| other.namespaceSerializer instanceof MigrationNamespaceSerializerProxy);
}
示例2: readStateMetaInfo
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
@Override
public RegisteredKeyedBackendStateMetaInfo.Snapshot<N, S> readStateMetaInfo(DataInputView in) throws IOException {
RegisteredKeyedBackendStateMetaInfo.Snapshot<N, S> metaInfo =
new RegisteredKeyedBackendStateMetaInfo.Snapshot<>();
metaInfo.setStateType(StateDescriptor.Type.values()[in.readInt()]);
metaInfo.setName(in.readUTF());
metaInfo.setNamespaceSerializer(TypeSerializerSerializationUtil.<N>tryReadSerializer(in, userCodeClassLoader));
metaInfo.setStateSerializer(TypeSerializerSerializationUtil.<S>tryReadSerializer(in, userCodeClassLoader));
// older versions do not contain the configuration snapshot
metaInfo.setNamespaceSerializerConfigSnapshot(null);
metaInfo.setStateSerializerConfigSnapshot(null);
return metaInfo;
}
示例3: getPartitionedState
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
/**
* Creates a partitioned state handle, using the state backend configured for this task.
*
* @throws IllegalStateException Thrown, if the key/value state was already initialized.
* @throws Exception Thrown, if the state backend cannot create the key/value state.
*/
protected <S extends State, N> S getPartitionedState(
N namespace,
TypeSerializer<N> namespaceSerializer,
StateDescriptor<S, ?> stateDescriptor) throws Exception {
/*
TODO: NOTE: This method does a lot of work caching / retrieving states just to update the namespace.
This method should be removed for the sake of namespaces being lazily fetched from the keyed
state backend, or being set on the state directly.
*/
if (keyedStateStore != null) {
return keyedStateBackend.getPartitionedState(namespace, namespaceSerializer, stateDescriptor);
} else {
throw new RuntimeException("Cannot create partitioned state. The keyed state " +
"backend has not been set. This indicates that the operator is not " +
"partitioned/keyed.");
}
}
示例4: AbstractQueryableStateOperator
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
public AbstractQueryableStateOperator(
String registrationName,
StateDescriptor<? extends S, ?> stateDescriptor) {
this.registrationName = Preconditions.checkNotNull(registrationName, "Registration name");
this.stateDescriptor = Preconditions.checkNotNull(stateDescriptor, "State descriptor");
if (stateDescriptor.isQueryable()) {
String name = stateDescriptor.getQueryableStateName();
if (!name.equals(registrationName)) {
throw new IllegalArgumentException("StateDescriptor already marked as " +
"queryable with name '" + name + "', but created operator with name '" +
registrationName + "'.");
} // else: all good, already registered with same name
} else {
stateDescriptor.setQueryable(registrationName);
}
}
示例5: EvictingWindowOperator
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
public EvictingWindowOperator(WindowAssigner<? super IN, W> windowAssigner,
TypeSerializer<W> windowSerializer,
KeySelector<IN, K> keySelector,
TypeSerializer<K> keySerializer,
StateDescriptor<? extends ListState<StreamRecord<IN>>, ?> windowStateDescriptor,
InternalWindowFunction<Iterable<IN>, OUT, K, W> windowFunction,
Trigger<? super IN, ? super W> trigger,
Evictor<? super IN, ? super W> evictor,
long allowedLateness,
OutputTag<IN> lateDataOutputTag) {
super(windowAssigner, windowSerializer, keySelector,
keySerializer, null, windowFunction, trigger, allowedLateness, lateDataOutputTag);
this.evictor = checkNotNull(evictor);
this.evictingWindowStateDescriptor = checkNotNull(windowStateDescriptor);
}
示例6: mergePartitionedState
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
@Override
public <S extends MergingState<?, ?>> void mergePartitionedState(StateDescriptor<S, ?> stateDescriptor) {
if (mergedWindows != null && mergedWindows.size() > 0) {
try {
S rawState = getKeyedStateBackend().getOrCreateKeyedState(windowSerializer, stateDescriptor);
if (rawState instanceof InternalMergingState) {
@SuppressWarnings("unchecked")
InternalMergingState<W, ?, ?> mergingState = (InternalMergingState<W, ?, ?>) rawState;
mergingState.mergeNamespaces(window, mergedWindows);
}
else {
throw new IllegalArgumentException(
"The given state descriptor does not refer to a mergeable state (MergingState)");
}
}
catch (Exception e) {
throw new RuntimeException("Error while merging state.", e);
}
}
}
示例7: validateListStateDescriptorConfigured
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
private void validateListStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
StateDescriptor<?, ?> descr = op.getStateDescriptor();
assertTrue(descr instanceof ListStateDescriptor);
ListStateDescriptor<?> listDescr = (ListStateDescriptor<?>) descr;
// this would be the first statement to fail if state descriptors were not properly initialized
TypeSerializer<?> serializer = listDescr.getSerializer();
assertTrue(serializer instanceof ListSerializer);
TypeSerializer<?> elementSerializer = listDescr.getElementSerializer();
assertTrue(elementSerializer instanceof KryoSerializer);
Kryo kryo = ((KryoSerializer<?>) elementSerializer).getKryo();
assertTrue("serializer registration was not properly passed on",
kryo.getSerializer(File.class) instanceof JavaSerializer);
}
示例8: testValueStateInstantiation
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
@Test
public void testValueStateInstantiation() throws Exception {
final ExecutionConfig config = new ExecutionConfig();
config.registerKryoType(Path.class);
final AtomicReference<Object> descriptorCapture = new AtomicReference<>();
StreamingRuntimeContext context = new StreamingRuntimeContext(
createDescriptorCapturingMockOp(descriptorCapture, config),
createMockEnvironment(),
Collections.<String, Accumulator<?, ?>>emptyMap());
ValueStateDescriptor<TaskInfo> descr = new ValueStateDescriptor<>("name", TaskInfo.class);
context.getState(descr);
StateDescriptor<?, ?> descrIntercepted = (StateDescriptor<?, ?>) descriptorCapture.get();
TypeSerializer<?> serializer = descrIntercepted.getSerializer();
// check that the Path class is really registered, i.e., the execution config was applied
assertTrue(serializer instanceof KryoSerializer);
assertTrue(((KryoSerializer<?>) serializer).getKryo().getRegistration(Path.class).getId() > 0);
}
示例9: mergePartitionedState
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
@Override
public <S extends MergingState<?, ?>> void mergePartitionedState(StateDescriptor<S, ?> stateDescriptor) {
try {
S rawState = stateBackend.getOrCreateKeyedState(windowSerializer, stateDescriptor);
if (rawState instanceof InternalMergingState) {
@SuppressWarnings("unchecked")
InternalMergingState<W, ?, ?> mergingState = (InternalMergingState<W, ?, ?>) rawState;
mergingState.mergeNamespaces(window, mergedWindows);
}
else {
throw new IllegalArgumentException(
"The given state descriptor does not refer to a mergeable state (MergingState)");
}
}
catch (Exception e) {
throw new RuntimeException("Error while merging state.", e);
}
}
示例10: getKvState
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
private static <K, S extends State, V> CompletableFuture<S> getKvState(
final Deadline deadline,
final QueryableStateClient client,
final JobID jobId,
final String queryName,
final K key,
final TypeInformation<K> keyTypeInfo,
final StateDescriptor<S, V> stateDescriptor,
final boolean failForUnknownKeyOrNamespace,
final ScheduledExecutor executor) {
final CompletableFuture<S> resultFuture = new CompletableFuture<>();
getKvStateIgnoringCertainExceptions(
deadline, resultFuture, client, jobId, queryName, key, keyTypeInfo,
stateDescriptor, failForUnknownKeyOrNamespace, executor);
return resultFuture;
}
示例11: getKvStateWithRetries
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
private static <K, S extends State, V> CompletableFuture<S> getKvStateWithRetries(
final QueryableStateClient client,
final JobID jobId,
final String queryName,
final K key,
final TypeInformation<K> keyTypeInfo,
final StateDescriptor<S, V> stateDescriptor,
final Time retryDelay,
final boolean failForUnknownKeyOrNamespace,
final ScheduledExecutor executor) {
return retryWithDelay(
() -> client.getKvState(jobId, queryName, key, VoidNamespace.INSTANCE, keyTypeInfo, VoidNamespaceTypeInfo.INSTANCE, stateDescriptor),
NO_OF_RETRIES,
retryDelay,
executor,
failForUnknownKeyOrNamespace);
}
示例12: tryRegisterStateTable
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
private <N, V> StateTable<K, N, V> tryRegisterStateTable(
TypeSerializer<N> namespaceSerializer, StateDescriptor<?, V> stateDesc) throws StateMigrationException {
return tryRegisterStateTable(
stateDesc.getName(), stateDesc.getType(),
namespaceSerializer, stateDesc.getSerializer());
}
示例13: RegisteredBackendStateMetaInfo
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
public RegisteredBackendStateMetaInfo(
StateDescriptor.Type stateType,
String name,
TypeSerializer<N> namespaceSerializer,
TypeSerializer<S> stateSerializer) {
this.stateType = checkNotNull(stateType);
this.name = checkNotNull(name);
this.namespaceSerializer = checkNotNull(namespaceSerializer);
this.stateSerializer = checkNotNull(stateSerializer);
}
示例14: RegisteredKeyedBackendStateMetaInfo
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
public RegisteredKeyedBackendStateMetaInfo(
StateDescriptor.Type stateType,
String name,
TypeSerializer<N> namespaceSerializer,
TypeSerializer<S> stateSerializer) {
this.stateType = checkNotNull(stateType);
this.name = checkNotNull(name);
this.namespaceSerializer = checkNotNull(namespaceSerializer);
this.stateSerializer = checkNotNull(stateSerializer);
}
示例15: Snapshot
import org.apache.flink.api.common.state.StateDescriptor; //导入依赖的package包/类
private Snapshot(
StateDescriptor.Type stateType,
String name,
TypeSerializer<N> namespaceSerializer,
TypeSerializer<S> stateSerializer,
TypeSerializerConfigSnapshot namespaceSerializerConfigSnapshot,
TypeSerializerConfigSnapshot stateSerializerConfigSnapshot) {
this.stateType = Preconditions.checkNotNull(stateType);
this.name = Preconditions.checkNotNull(name);
this.namespaceSerializer = Preconditions.checkNotNull(namespaceSerializer);
this.stateSerializer = Preconditions.checkNotNull(stateSerializer);
this.namespaceSerializerConfigSnapshot = Preconditions.checkNotNull(namespaceSerializerConfigSnapshot);
this.stateSerializerConfigSnapshot = Preconditions.checkNotNull(stateSerializerConfigSnapshot);
}