Search in sources :

Example 1 with ProcessingTimeServiceAware

use of org.apache.flink.streaming.runtime.tasks.ProcessingTimeServiceAware in project flink by apache.

the class StreamOperatorFactoryUtil method createOperator.

/**
 * Creates a new operator using a factory and makes sure that all special factory traits are
 * properly handled.
 *
 * @param operatorFactory the operator factory.
 * @param containingTask the containing task.
 * @param configuration the configuration of the operator.
 * @param output the output of the operator.
 * @param operatorEventDispatcher the operator event dispatcher for communication between
 *     operator and coordinators.
 * @return a newly created and configured operator, and the {@link ProcessingTimeService}
 *     instance it can access.
 */
public static <OUT, OP extends StreamOperator<OUT>> Tuple2<OP, Optional<ProcessingTimeService>> createOperator(StreamOperatorFactory<OUT> operatorFactory, StreamTask<OUT, ?> containingTask, StreamConfig configuration, Output<StreamRecord<OUT>> output, OperatorEventDispatcher operatorEventDispatcher) {
    MailboxExecutor mailboxExecutor = containingTask.getMailboxExecutorFactory().createExecutor(configuration.getChainIndex());
    if (operatorFactory instanceof YieldingOperatorFactory) {
        ((YieldingOperatorFactory<?>) operatorFactory).setMailboxExecutor(mailboxExecutor);
    }
    final Supplier<ProcessingTimeService> processingTimeServiceFactory = () -> containingTask.getProcessingTimeServiceFactory().createProcessingTimeService(mailboxExecutor);
    final ProcessingTimeService processingTimeService;
    if (operatorFactory instanceof ProcessingTimeServiceAware) {
        processingTimeService = processingTimeServiceFactory.get();
        ((ProcessingTimeServiceAware) operatorFactory).setProcessingTimeService(processingTimeService);
    } else {
        processingTimeService = null;
    }
    // TODO: what to do with ProcessingTimeServiceAware?
    OP op = operatorFactory.createStreamOperator(new StreamOperatorParameters<>(containingTask, configuration, output, processingTimeService != null ? () -> processingTimeService : processingTimeServiceFactory, operatorEventDispatcher));
    return new Tuple2<>(op, Optional.ofNullable(processingTimeService));
}
Also used : ProcessingTimeService(org.apache.flink.streaming.runtime.tasks.ProcessingTimeService) Tuple2(org.apache.flink.api.java.tuple.Tuple2) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) ProcessingTimeServiceAware(org.apache.flink.streaming.runtime.tasks.ProcessingTimeServiceAware)

Aggregations

MailboxExecutor (org.apache.flink.api.common.operators.MailboxExecutor)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 ProcessingTimeService (org.apache.flink.streaming.runtime.tasks.ProcessingTimeService)1 ProcessingTimeServiceAware (org.apache.flink.streaming.runtime.tasks.ProcessingTimeServiceAware)1