echauchot commented on code in PR #19935:
URL: https://github.com/apache/flink/pull/19935#discussion_r917800509


##########
flink-connectors/flink-connector-cassandra/src/main/java/org/apache/flink/batch/connectors/cassandra/CassandraOutputFormatBase.java:
##########
@@ -59,31 +63,45 @@ public void configure(Configuration parameters) {
 
     /** Opens a Session to Cassandra . */
     @Override
-    public void open(int taskNumber, int numTasks) {
+    protected void postOpen() {
         this.session = cluster.connect();
-        super.open(taskNumber, numTasks);
     }
 
     /** Closes all resources used by Cassandra connection. */
     @Override
-    public void close() throws IOException {
+    protected void postClose() {
         try {
-            super.close();
-        } finally {
-            try {
-                if (session != null) {
-                    session.close();
-                }
-            } catch (Exception e) {
-                LOG.error("Error while closing session.", e);
+            if (session != null) {
+                session.close();
             }
-            try {
-                if (cluster != null) {
-                    cluster.close();
-                }
-            } catch (Exception e) {
-                LOG.error("Error while closing cluster.", e);
+        } catch (Exception e) {
+            LOG.error("Error while closing session.", e);
+        }
+        try {
+            if (cluster != null) {
+                cluster.close();
             }
+        } catch (Exception e) {
+            LOG.error("Error while closing cluster.", e);
         }
     }
+
+    protected static <T> CompletableFuture<T> 
listenableFutureToCompletableFuture(
+            final ListenableFuture<T> listenableFuture) {
+        CompletableFuture<T> completable = new CompletableFuture<T>();
+        Futures.addCallback(
+                listenableFuture,
+                new FutureCallback<T>() {
+                    @Override
+                    public void onSuccess(T result) {
+                        completable.complete(result);
+                    }
+
+                    @Override
+                    public void onFailure(Throwable t) {
+                        completable.completeExceptionally(t);
+                    }
+                });

Review Comment:
   thanks for catching this. My bad ! How could I write this code that 
allocates with each send call ?!! :scream: 



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