StephanEwen commented on a change in pull request #11554: 
[FLINK-15101][connector/common] Add SourceCoordinator implementation.
URL: https://github.com/apache/flink/pull/11554#discussion_r410746233
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/source/coordinator/SourceCoordinatorProvider.java
 ##########
 @@ -0,0 +1,73 @@
+/*
+ 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.runtime.source.coordinator;
+
+import org.apache.flink.api.connector.source.Source;
+import org.apache.flink.api.connector.source.SourceSplit;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.runtime.operators.coordination.OperatorCoordinator;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.BiConsumer;
+
+/**
+ * The provider of {@link SourceCoordinator}.
+ */
+public class SourceCoordinatorProvider<SplitT extends SourceSplit>
+               implements OperatorCoordinator.Provider {
+       private final OperatorID operatorID;
+       private final Source<?, SplitT, ?> source;
+       private final int numWorkerThreads;
+
+       /**
+        * Construct the {@link SourceCoordinatorProvider}.
+        *
+        * @param operatorID the ID of the operator this coordinator 
corresponds to.
+        * @param source the Source that will be used for this coordinator.
+        * @param numWorkerThreads the number of threads the should provide to 
the SplitEnumerator
+        *                         for doing async calls. See
+        *                         {@link 
org.apache.flink.api.connector.source.SplitEnumeratorContext#callAsync(Callable,
 BiConsumer)
+        *                         SplitEnumeratorContext.callAsync()}.
+        */
+       public SourceCoordinatorProvider(
+                       OperatorID operatorID,
+                       Source<?, SplitT, ?> source,
+                       int numWorkerThreads) {
+               this.operatorID = operatorID;
+               this.source = source;
+               this.numWorkerThreads = numWorkerThreads;
+       }
+
+       @Override
+       public OperatorID getOperatorId() {
+               return operatorID;
+       }
+
+       @Override
+       public OperatorCoordinator create(OperatorCoordinator.Context context) {
+               final String coordinatorThreadName = "SourceCoordinator-" + 
operatorID;
+               ExecutorService coordinatorExecutor = 
Executors.newSingleThreadExecutor(
 
 Review comment:
   Executors should always have an `UncaughtExceptionHandler`. I would suggest 
to try and reuse one of the existing thread factories, for example 
`DispatcherThreadFactory` for single threads, and `ExecutorThreadFactory` for 
pools of threads.

----------------------------------------------------------------
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