pnowojski commented on a change in pull request #8476: [FLINK-12490][network] 
Introduce Input and NetworkInput interfaces
URL: https://github.com/apache/flink/pull/8476#discussion_r287728336
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/AsyncDataInput.java
 ##########
 @@ -0,0 +1,85 @@
+/*
+ * 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.io;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Interface defining couple of essential methods for asynchronous and non 
blocking data polling.
+ *
+ * <p>For the most efficient usage, user of this class is suppose to call 
{@link #pollNext()}
+ * until it returns that no more elements are available. If that happens, he 
should check if
+ * input {@link #isFinished()}. If not, he should wait for {@link 
#isAvailable()}
+ * {@link CompletableFuture} to be completed. For example:
+ *
+ * <pre>
+ * {@code
+ *     while (!input.isFinished()) {
+ *             AsyncDataInput<Optional<T>> input = ...;
+ *             Optional<T> next;
+ *
+ *             while (true) {
+ *                     next = input.pollNext();
+ *                     if (!next.isPresent()) {
+ *                             break;
+ *                     }
+ *                     // do something with next
+ *             }
+ *
+ *             input.isAvailable().get();
+ *     }
+ * }
+ * </pre>
+ */
+@Internal
+public interface AsyncDataInput<T> {
+       CompletableFuture<?> AVAILABLE = 
CompletableFuture.completedFuture(null);
+
+       /**
+        * Poll the next element.
+        *
+        * @return
+        * <ol>
+        *     <li>
+        *         If the {@link T} is an {@code Optional}: return {@code 
Optional.of(element)} -
+        *         next returned element. {@code Optional.empty()} will be 
returned if there is no data
+        *         to return or if {@link #isFinished()} returns true.
+        *     </li>
+        *     <li>
+        *         If next element or {@code null} if there is no data to 
return or if
+        *         {@link #isFinished()} returns true.
+        *     </li>
+        * </ol>
+        */
+       T pollNext() throws Exception;
+
+       /**
+        * @return true if end of input was reached, false otherwise.
+        */
+       boolean isFinished();
+
+       /**
+        * @return a future that is completed if there are more records 
available. If there are more
+        * records available immediately, {@link #AVAILABLE} should be 
returned. Previously returned
+        * not completed futures should become completed once there is more 
input available or if
+        * the input {@link #isFinished()}.
+        */
+       CompletableFuture<?> isAvailable();
 
 Review comment:
   Originally I was proposing `isBlocked()` name for this method - whether the 
input/source/thingy is blocked and waiting for more input. Someone else 
(Stephan?) preferred `isAvailable`, since `isBlocked` returning a feature was 
confusing for him and Becket. IMO `isAvailable` is good enough, as long as you 
think about it in the similar terms: is the input available for further 
processing - in other words, the opposite of `isBlocked()`. Not if has it more 
data available. 
   
   Either way I would vote `isBlocked` > `isAvailable` > `available` > 
`awaitStatusChange` > `isAvailableOrFinished`.
   
   Can we postpone the name voting until the source interface refactoring, 
because first and foremost I want this naming convention be in sync in those 
two places? We can rename it quite easily, but I don't want to spend too much 
time discussing it twice with a different audience.

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