StephanEwen commented on a change in pull request #10487: 
[FLINK-15100][connector/source] Add a base implementation for SourceReader.
URL: https://github.com/apache/flink/pull/10487#discussion_r398819395
 
 

 ##########
 File path: 
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/SourceReaderBase.java
 ##########
 @@ -0,0 +1,206 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package org.apache.flink.connector.base.source.reader;
+
+import org.apache.flink.api.connector.source.SourceEvent;
+import org.apache.flink.api.connector.source.SourceOutput;
+import org.apache.flink.api.connector.source.SourceReader;
+import org.apache.flink.api.connector.source.SourceReaderContext;
+import org.apache.flink.api.connector.source.SourceSplit;
+import org.apache.flink.configuration.Configuration;
+import 
org.apache.flink.connector.base.source.reader.fetcher.SplitFetcherManager;
+import org.apache.flink.connector.base.source.reader.splitreader.SplitReader;
+import 
org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue;
+import 
org.apache.flink.connector.base.source.reader.synchronization.FutureNotifier;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * An abstract implementation of {@link SourceReader} which provides some 
sychronization between
+ * the mail box main thread and the SourceReader internal threads. This class 
allows user to
+ * just provide a {@link SplitReader} and snapshot the split state.
+ *
+ * @param <E> The rich element type that contains information for split state 
update or timestamp extraction.
+ * @param <T> The final element type to emit.
+ * @param <SplitT> the immutable split type.
+ * @param <SplitStateT> the mutable type of split state.
+ */
+public abstract class SourceReaderBase<E, T, SplitT extends SourceSplit, 
SplitStateT>
+               implements SourceReader<T, SplitT> {
+       private static final Logger LOG = 
LoggerFactory.getLogger(SourceReaderBase.class);
+
+       /** A future notifier to notify when this reader requires attention. */
+       private final FutureNotifier futureNotifier;
+
+       /** A queue to buffer the elements fetched by the fetcher thread. */
+       private final BlockingQueue<RecordsWithSplitIds<E>> elementsQueue;
+
+       /** The state of the splits. */
+       private final Map<String, SplitStateT> splitStates;
+
+       /** The record emitter to handle the records read by the SplitReaders. 
*/
+       protected final RecordEmitter<E, T, SplitStateT> recordEmitter;
+
+       /** The split fetcher manager to run split fetchers. */
+       protected final SplitFetcherManager<E, SplitT> splitFetcherManager;
+
+       /** The configuration for the reader. */
+       protected final SourceReaderOptions options;
+
+       /** The raw configurations that may be used by subclasses. */
+       protected final Configuration config;
+
+       /** The context of this source reader. */
+       protected SourceReaderContext context;
+
+       /** The last element to ensure it is fully handled. */
+       private SplitsRecordIterator<E> splitIter;
+
+       public SourceReaderBase(
+                       FutureNotifier futureNotifier,
+                       FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> 
elementsQueue,
+                       SplitFetcherManager<E, SplitT> splitFetcherManager,
+                       RecordEmitter<E, T, SplitStateT> recordEmitter,
+                       Configuration config,
+                       SourceReaderContext context) {
+               this.futureNotifier = futureNotifier;
+               this.elementsQueue = elementsQueue;
+               this.splitFetcherManager = splitFetcherManager;
+               this.recordEmitter = recordEmitter;
+               this.splitStates = new HashMap<>();
+               this.splitIter = null;
+               this.options = new SourceReaderOptions(config);
+               this.config = config;
+               this.context = context;
+       }
+
+       @Override
+       public void start() {
+
+       }
+
+       @Override
+       @SuppressWarnings("unchecked")
 
 Review comment:
   Is this suppression a left-over? I don't see any unchecked casts in the 
method.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to