Java Code Examples for org.apache.flink.streaming.api.operators.StreamOperatorStateContext#operatorStateBackend()

The following examples show how to use org.apache.flink.streaming.api.operators.StreamOperatorStateContext#operatorStateBackend() . 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: StreamTaskTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer();
	return (operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup) -> {

		final StreamOperatorStateContext context = streamTaskStateManager.streamOperatorStateContext(
			operatorID,
			operatorClassName,
			keyContext,
			keySerializer,
			closeableRegistry,
			metricGroup);

		return new StreamOperatorStateContext() {
			@Override
			public boolean isRestored() {
				return context.isRestored();
			}

			@Override
			public OperatorStateBackend operatorStateBackend() {
				return context.operatorStateBackend();
			}

			@Override
			public AbstractKeyedStateBackend<?> keyedStateBackend() {
				return context.keyedStateBackend();
			}

			@Override
			public InternalTimeServiceManager<?> internalTimerServiceManager() {
				InternalTimeServiceManager<?> timeServiceManager = context.internalTimerServiceManager();
				return timeServiceManager != null ? spy(timeServiceManager) : null;
			}

			@Override
			public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() {
				return replaceWithSpy(context.rawOperatorStateInputs());
			}

			@Override
			public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() {
				return replaceWithSpy(context.rawKeyedStateInputs());
			}

			public <T extends Closeable> T replaceWithSpy(T closeable) {
				T spyCloseable = spy(closeable);
				if (closeableRegistry.unregisterCloseable(closeable)) {
					try {
						closeableRegistry.registerCloseable(spyCloseable);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return spyCloseable;
			}
		};
	};
}
 
Example 2
Source File: StreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer();
	return (operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup) -> {

		final StreamOperatorStateContext context = streamTaskStateManager.streamOperatorStateContext(
			operatorID,
			operatorClassName,
			keyContext,
			keySerializer,
			closeableRegistry,
			metricGroup);

		return new StreamOperatorStateContext() {
			@Override
			public boolean isRestored() {
				return context.isRestored();
			}

			@Override
			public OperatorStateBackend operatorStateBackend() {
				return context.operatorStateBackend();
			}

			@Override
			public AbstractKeyedStateBackend<?> keyedStateBackend() {
				return context.keyedStateBackend();
			}

			@Override
			public InternalTimeServiceManager<?> internalTimerServiceManager() {
				InternalTimeServiceManager<?> timeServiceManager = context.internalTimerServiceManager();
				return timeServiceManager != null ? spy(timeServiceManager) : null;
			}

			@Override
			public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() {
				return replaceWithSpy(context.rawOperatorStateInputs());
			}

			@Override
			public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() {
				return replaceWithSpy(context.rawKeyedStateInputs());
			}

			public <T extends Closeable> T replaceWithSpy(T closeable) {
				T spyCloseable = spy(closeable);
				if (closeableRegistry.unregisterCloseable(closeable)) {
					try {
						closeableRegistry.registerCloseable(spyCloseable);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return spyCloseable;
			}
		};
	};
}
 
Example 3
Source File: StreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer();
	return (operatorID, operatorClassName, processingTimeService, keyContext, keySerializer, closeableRegistry, metricGroup) -> {

		final StreamOperatorStateContext controller = streamTaskStateManager.streamOperatorStateContext(
			operatorID,
			operatorClassName,
			processingTimeService,
			keyContext,
			keySerializer,
			closeableRegistry,
			metricGroup);

		return new StreamOperatorStateContext() {
			@Override
			public boolean isRestored() {
				return controller.isRestored();
			}

			@Override
			public OperatorStateBackend operatorStateBackend() {
				return controller.operatorStateBackend();
			}

			@Override
			public AbstractKeyedStateBackend<?> keyedStateBackend() {
				return controller.keyedStateBackend();
			}

			@Override
			public InternalTimeServiceManager<?> internalTimerServiceManager() {
				InternalTimeServiceManager<?> timeServiceManager = controller.internalTimerServiceManager();
				return timeServiceManager != null ? spy(timeServiceManager) : null;
			}

			@Override
			public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() {
				return replaceWithSpy(controller.rawOperatorStateInputs());
			}

			@Override
			public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() {
				return replaceWithSpy(controller.rawKeyedStateInputs());
			}

			public <T extends Closeable> T replaceWithSpy(T closeable) {
				T spyCloseable = spy(closeable);
				if (closeableRegistry.unregisterCloseable(closeable)) {
					try {
						closeableRegistry.registerCloseable(spyCloseable);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return spyCloseable;
			}
		};
	};
}