Search in sources :

Example 1 with RequestSplitEvent

use of org.apache.flink.runtime.source.event.RequestSplitEvent in project flink by apache.

the class SourceCoordinator method handleEventFromOperator.

@Override
public void handleEventFromOperator(int subtask, OperatorEvent event) {
    runInEventLoop(() -> {
        if (event instanceof RequestSplitEvent) {
            LOG.info("Source {} received split request from parallel task {}", operatorName, subtask);
            enumerator.handleSplitRequest(subtask, ((RequestSplitEvent) event).hostName());
        } else if (event instanceof SourceEventWrapper) {
            final SourceEvent sourceEvent = ((SourceEventWrapper) event).getSourceEvent();
            LOG.debug("Source {} received custom event from parallel task {}: {}", operatorName, subtask, sourceEvent);
            enumerator.handleSourceEvent(subtask, sourceEvent);
        } else if (event instanceof ReaderRegistrationEvent) {
            final ReaderRegistrationEvent registrationEvent = (ReaderRegistrationEvent) event;
            LOG.info("Source {} registering reader for parallel task {} @ {}", operatorName, subtask, registrationEvent.location());
            handleReaderRegistrationEvent(registrationEvent);
        } else if (event instanceof ReportedWatermarkEvent) {
            handleReportedWatermark(subtask, new Watermark(((ReportedWatermarkEvent) event).getWatermark()));
        } else {
            throw new FlinkException("Unrecognized Operator Event: " + event);
        }
    }, "handling operator event %s from subtask %d", event, subtask);
}
Also used : RequestSplitEvent(org.apache.flink.runtime.source.event.RequestSplitEvent) SourceEventWrapper(org.apache.flink.runtime.source.event.SourceEventWrapper) ReaderRegistrationEvent(org.apache.flink.runtime.source.event.ReaderRegistrationEvent) Watermark(org.apache.flink.api.common.eventtime.Watermark) FlinkException(org.apache.flink.util.FlinkException) SourceEvent(org.apache.flink.api.connector.source.SourceEvent) ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent)

Example 2 with RequestSplitEvent

use of org.apache.flink.runtime.source.event.RequestSplitEvent in project flink by apache.

the class SourceOperator method initReader.

/**
 * Initializes the reader. The code from this method should ideally happen in the constructor or
 * in the operator factory even. It has to happen here at a slightly later stage, because of the
 * lazy metric initialization.
 *
 * <p>Calling this method explicitly is an optional way to have the reader initialization a bit
 * earlier than in open(), as needed by the {@link
 * org.apache.flink.streaming.runtime.tasks.SourceOperatorStreamTask}
 *
 * <p>This code should move to the constructor once the metric groups are available at task
 * setup time.
 */
public void initReader() throws Exception {
    if (sourceReader != null) {
        return;
    }
    final int subtaskIndex = getRuntimeContext().getIndexOfThisSubtask();
    final SourceReaderContext context = new SourceReaderContext() {

        @Override
        public SourceReaderMetricGroup metricGroup() {
            return sourceMetricGroup;
        }

        @Override
        public Configuration getConfiguration() {
            return configuration;
        }

        @Override
        public String getLocalHostName() {
            return localHostname;
        }

        @Override
        public int getIndexOfSubtask() {
            return subtaskIndex;
        }

        @Override
        public void sendSplitRequest() {
            operatorEventGateway.sendEventToCoordinator(new RequestSplitEvent(getLocalHostName()));
        }

        @Override
        public void sendSourceEventToCoordinator(SourceEvent event) {
            operatorEventGateway.sendEventToCoordinator(new SourceEventWrapper(event));
        }

        @Override
        public UserCodeClassLoader getUserCodeClassLoader() {
            return new UserCodeClassLoader() {

                @Override
                public ClassLoader asClassLoader() {
                    return getRuntimeContext().getUserCodeClassLoader();
                }

                @Override
                public void registerReleaseHookIfAbsent(String releaseHookName, Runnable releaseHook) {
                    getRuntimeContext().registerUserCodeClassLoaderReleaseHookIfAbsent(releaseHookName, releaseHook);
                }
            };
        }
    };
    sourceReader = readerFactory.apply(context);
}
Also used : RequestSplitEvent(org.apache.flink.runtime.source.event.RequestSplitEvent) UserCodeClassLoader(org.apache.flink.util.UserCodeClassLoader) SourceEventWrapper(org.apache.flink.runtime.source.event.SourceEventWrapper) SourceReaderContext(org.apache.flink.api.connector.source.SourceReaderContext) SourceEvent(org.apache.flink.api.connector.source.SourceEvent)

Aggregations

SourceEvent (org.apache.flink.api.connector.source.SourceEvent)2 RequestSplitEvent (org.apache.flink.runtime.source.event.RequestSplitEvent)2 SourceEventWrapper (org.apache.flink.runtime.source.event.SourceEventWrapper)2 Watermark (org.apache.flink.api.common.eventtime.Watermark)1 SourceReaderContext (org.apache.flink.api.connector.source.SourceReaderContext)1 ReaderRegistrationEvent (org.apache.flink.runtime.source.event.ReaderRegistrationEvent)1 ReportedWatermarkEvent (org.apache.flink.runtime.source.event.ReportedWatermarkEvent)1 FlinkException (org.apache.flink.util.FlinkException)1 UserCodeClassLoader (org.apache.flink.util.UserCodeClassLoader)1