use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.
the class OperatorChainTest method setupOperatorChain.
// ------------------------------------------------------------------------
// Operator Chain Setup Utils
// ------------------------------------------------------------------------
@SafeVarargs
public static <T, OP extends StreamOperator<T>> OperatorChain<T, OP> setupOperatorChain(OneInputStreamOperator<T, T>... operators) throws Exception {
checkNotNull(operators);
checkArgument(operators.length > 0);
try (MockEnvironment env = MockEnvironment.builder().build()) {
final StreamTask<?, ?> containingTask = new MockStreamTaskBuilder(env).build();
final StreamConfig cfg = new StreamConfig(new Configuration());
cfg.setOperatorID(new OperatorID());
cfg.setStateKeySerializer(new StringSerializer());
final List<StreamOperatorWrapper<?, ?>> operatorWrappers = new ArrayList<>();
// initial output goes to nowhere
@SuppressWarnings({ "unchecked", "rawtypes" }) WatermarkGaugeExposingOutput<StreamRecord<T>> lastWriter = new BroadcastingOutputCollector<>(new Output[0]);
// build the reverse operators array
for (int i = 0; i < operators.length; i++) {
int operatorIndex = operators.length - i - 1;
OneInputStreamOperator<T, T> op = operators[operatorIndex];
if (op instanceof SetupableStreamOperator) {
((SetupableStreamOperator) op).setup(containingTask, cfg, lastWriter);
}
lastWriter = new ChainingOutput<>(op, null);
ProcessingTimeService processingTimeService = null;
if (op instanceof AbstractStreamOperator) {
processingTimeService = ((AbstractStreamOperator) op).getProcessingTimeService();
}
operatorWrappers.add(new StreamOperatorWrapper<>(op, Optional.ofNullable(processingTimeService), containingTask.getMailboxExecutorFactory().createExecutor(i), operatorIndex == 0));
}
@SuppressWarnings("unchecked") final StreamOperatorWrapper<T, OP> headOperatorWrapper = (StreamOperatorWrapper<T, OP>) operatorWrappers.get(operatorWrappers.size() - 1);
return new RegularOperatorChain<>(operatorWrappers, new RecordWriterOutput<?>[0], lastWriter, headOperatorWrapper);
}
}
use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.
the class StateBootstrapWrapperOperator method setup.
@Override
public void setup(StreamTask<?, ?> containingTask, StreamConfig config, Output<StreamRecord<TaggedOperatorSubtaskState>> output) {
((SetupableStreamOperator) operator).setup(containingTask, config, new VoidOutput<>());
operator.setProcessingTimeService(new NeverFireProcessingTimeService());
this.output = output;
}
use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.
the class AbstractStreamOperatorTestHarness method setup.
/**
* Calls {@link SetupableStreamOperator#setup(StreamTask, StreamConfig, Output)} ()}.
*/
public void setup(TypeSerializer<OUT> outputSerializer) {
if (!setupCalled) {
streamTaskStateInitializer = createStreamTaskStateManager(environment, stateBackend, ttlTimeProvider, timeServiceManagerProvider);
mockTask.setStreamTaskStateInitializer(streamTaskStateInitializer);
if (operator == null) {
this.operator = StreamOperatorFactoryUtil.createOperator(factory, mockTask, config, new MockOutput(outputSerializer), new OperatorEventDispatcherImpl(this.getClass().getClassLoader(), new NoOpTaskOperatorEventGateway())).f0;
} else {
if (operator instanceof AbstractStreamOperator) {
((AbstractStreamOperator) operator).setProcessingTimeService(processingTimeService);
}
if (operator instanceof SetupableStreamOperator) {
((SetupableStreamOperator) operator).setup(mockTask, config, new MockOutput(outputSerializer));
}
}
setupCalled = true;
this.mockTask.init();
}
}
Aggregations