org.apache.flink.runtime.state.StateInitializationContextImpl Java Examples

The following examples show how to use org.apache.flink.runtime.state.StateInitializationContextImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamOperatorStateHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
public void initializeOperatorState(CheckpointedStreamOperator streamOperator) throws Exception {
	CloseableIterable<KeyGroupStatePartitionStreamProvider> keyedStateInputs = context.rawKeyedStateInputs();
	CloseableIterable<StatePartitionStreamProvider> operatorStateInputs = context.rawOperatorStateInputs();

	try {
		StateInitializationContext initializationContext = new StateInitializationContextImpl(
			context.isRestored(), // information whether we restore or start for the first time
			operatorStateBackend, // access to operator state backend
			keyedStateStore, // access to keyed state backend
			keyedStateInputs, // access to keyed state stream
			operatorStateInputs); // access to operator state stream

		streamOperator.initializeState(initializationContext);
	} finally {
		closeFromRegistry(operatorStateInputs, closeableRegistry);
		closeFromRegistry(keyedStateInputs, closeableRegistry);
	}
}
 
Example #2
Source File: SourceOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private StateInitializationContext getStateContext() throws Exception {
	// Create a mock split.
	byte[] serializedSplitWithVersion = SimpleVersionedSerialization
			.writeVersionAndSerialize(new MockSourceSplitSerializer(), MOCK_SPLIT);

	// Crate the state context.
	OperatorStateStore operatorStateStore = createOperatorStateStore();
	StateInitializationContext stateContext = new StateInitializationContextImpl(
			false,
			operatorStateStore,
			null,
			null,
			null);

	// Update the context.
	stateContext.getOperatorStateStore()
				.getListState(SourceOperator.SPLITS_STATE_DESC)
				.update(Collections.singletonList(serializedSplitWithVersion));

	return stateContext;
}
 
Example #3
Source File: SourceOperatorEventTimeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> SourceOperator<T, MockSourceSplit> createTestOperator(
		SourceReader<T, MockSourceSplit> reader,
		WatermarkStrategy<T> watermarkStrategy,
		ProcessingTimeService timeService) throws Exception {

	final OperatorStateStore operatorStateStore =
			new MemoryStateBackend().createOperatorStateBackend(
					new MockEnvironmentBuilder().build(),
					"test-operator",
					Collections.emptyList(),
					new CloseableRegistry());

	final StateInitializationContext stateContext = new StateInitializationContextImpl(
		false, operatorStateStore, null, null, null);

	final SourceOperator<T, MockSourceSplit> sourceOperator =
			new TestingSourceOperator<>(reader, watermarkStrategy, timeService);
	sourceOperator.initializeState(stateContext);
	sourceOperator.open();

	return sourceOperator;
}
 
Example #4
Source File: AbstractStreamOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public final void initializeState() throws Exception {

	final TypeSerializer<?> keySerializer = config.getStateKeySerializer(getUserCodeClassloader());

	final StreamTask<?, ?> containingTask =
		Preconditions.checkNotNull(getContainingTask());
	final CloseableRegistry streamTaskCloseableRegistry =
		Preconditions.checkNotNull(containingTask.getCancelables());
	final StreamTaskStateInitializer streamTaskStateManager =
		Preconditions.checkNotNull(containingTask.createStreamTaskStateInitializer());

	final StreamOperatorStateContext context =
		streamTaskStateManager.streamOperatorStateContext(
			getOperatorID(),
			getClass().getSimpleName(),
			this,
			keySerializer,
			streamTaskCloseableRegistry,
			metrics);

	this.operatorStateBackend = context.operatorStateBackend();
	this.keyedStateBackend = context.keyedStateBackend();

	if (keyedStateBackend != null) {
		this.keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, getExecutionConfig());
	}

	timeServiceManager = context.internalTimerServiceManager();

	CloseableIterable<KeyGroupStatePartitionStreamProvider> keyedStateInputs = context.rawKeyedStateInputs();
	CloseableIterable<StatePartitionStreamProvider> operatorStateInputs = context.rawOperatorStateInputs();

	try {
		StateInitializationContext initializationContext = new StateInitializationContextImpl(
			context.isRestored(), // information whether we restore or start for the first time
			operatorStateBackend, // access to operator state backend
			keyedStateStore, // access to keyed state backend
			keyedStateInputs, // access to keyed state stream
			operatorStateInputs); // access to operator state stream

		initializeState(initializationContext);
	} finally {
		closeFromRegistry(operatorStateInputs, streamTaskCloseableRegistry);
		closeFromRegistry(keyedStateInputs, streamTaskCloseableRegistry);
	}
}
 
Example #5
Source File: AbstractStreamOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public final void initializeState() throws Exception {

	final TypeSerializer<?> keySerializer = config.getStateKeySerializer(getUserCodeClassloader());

	final StreamTask<?, ?> containingTask =
		Preconditions.checkNotNull(getContainingTask());
	final CloseableRegistry streamTaskCloseableRegistry =
		Preconditions.checkNotNull(containingTask.getCancelables());
	final StreamTaskStateInitializer streamTaskStateManager =
		Preconditions.checkNotNull(containingTask.createStreamTaskStateInitializer());

	final StreamOperatorStateContext context =
		streamTaskStateManager.streamOperatorStateContext(
			getOperatorID(),
			getClass().getSimpleName(),
			this,
			keySerializer,
			streamTaskCloseableRegistry,
			metrics);

	this.operatorStateBackend = context.operatorStateBackend();
	this.keyedStateBackend = context.keyedStateBackend();

	if (keyedStateBackend != null) {
		this.keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, getExecutionConfig());
	}

	timeServiceManager = context.internalTimerServiceManager();

	CloseableIterable<KeyGroupStatePartitionStreamProvider> keyedStateInputs = context.rawKeyedStateInputs();
	CloseableIterable<StatePartitionStreamProvider> operatorStateInputs = context.rawOperatorStateInputs();

	try {
		StateInitializationContext initializationContext = new StateInitializationContextImpl(
			context.isRestored(), // information whether we restore or start for the first time
			operatorStateBackend, // access to operator state backend
			keyedStateStore, // access to keyed state backend
			keyedStateInputs, // access to keyed state stream
			operatorStateInputs); // access to operator state stream

		initializeState(initializationContext);
	} finally {
		closeFromRegistry(operatorStateInputs, streamTaskCloseableRegistry);
		closeFromRegistry(keyedStateInputs, streamTaskCloseableRegistry);
	}
}