AHeise commented on a change in pull request #16701:
URL: https://github.com/apache/flink/pull/16701#discussion_r682836051



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/sink/CommitterHandler.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.streaming.runtime.operators.sink;
+
+import org.apache.flink.runtime.state.StateInitializationContext;
+import org.apache.flink.runtime.state.StateSnapshotContext;
+import org.apache.flink.util.function.SupplierWithException;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A wrapper around multiple {@link 
org.apache.flink.api.connector.sink.Committer} or {@link
+ * org.apache.flink.api.connector.sink.GlobalCommitter} that manages states.
+ *
+ * @param <InputT>
+ * @param <OutputT>
+ */
+interface CommitterHandler<InputT, OutputT> extends AutoCloseable, 
Serializable {
+
+    /** Initializes the state of the committer and this handler. */
+    default void initializeState(StateInitializationContext context) throws 
Exception {}
+
+    /** Snapshots the state of the committer and this handler. */
+    default void snapshotState(StateSnapshotContext context) throws Exception 
{}
+
+    /**
+     * Processes the committables be either directly transforming them or by 
adding them to the
+     * internal state of this handler. The supplier should only be queried 
once.
+     *
+     * @return a list of output committables that is send downstream.
+     */
+    List<OutputT> processCommittables(
+            SupplierWithException<List<InputT>, IOException> 
committableSupplier)
+            throws IOException;
+
+    /**
+     * Called when no more committables are going to be added through {@link
+     * #processCommittables(SupplierWithException)}.
+     *
+     * @return a list of output committables that is send downstream.
+     */
+    default List<OutputT> endOfInput() throws IOException {
+        return Collections.emptyList();
+    }
+
+    default void close() throws Exception {}
+
+    /** Called when a checkpoint is completed and returns a list of output to 
be sent downstream. */
+    default Collection<OutputT> notifyCheckpointCompleted(long checkpointId) 
throws IOException {
+        return Collections.emptyList();
+    }
+
+    /** Swallows all committables and emits nothing. */
+    @SuppressWarnings("unchecked")
+    static <InputT, OutputT> CommitterHandler<InputT, OutputT> noop() {

Review comment:
       I can't fully remove it without introducing some ugliness: This method 
is for casting the singleton into the expected type. The 
`NoopCommitterHandler.INSTANCE` could actually be covariant to any type but you 
can't express that in Java. 
   I have moved it to `NoopCommitterHandler#getInstance()`. PTAL if it's less 
confusing. I'm also promoting `NoopCommitterHandler` to top-level.




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to