This is an automated email from the ASF dual-hosted git repository.

htowaileb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 59a9bd72f9 [NO ISSUE]: Allow closing resources silently
59a9bd72f9 is described below

commit 59a9bd72f99c4738888ef0d1a4ff3961034f5aee
Author: Hussain Towaileb <[email protected]>
AuthorDate: Fri May 24 01:28:39 2024 +0300

    [NO ISSUE]: Allow closing resources silently
    
    Change-Id: I5d4b9f953fcc5557fe0556dac4004c44dd26be5c
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18317
    Reviewed-by: Michael Blow <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Hussain Towaileb <[email protected]>
---
 .../org/apache/hyracks/api/util/CleanupUtils.java  | 34 +++++++++++++++++-----
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
index 4de44bee40..5ebfba428b 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
@@ -102,6 +102,14 @@ public class CleanupUtils {
         }
     }
 
+    public static Throwable close(AutoCloseable[] closables, Throwable root) {
+        return close(closables, root, false);
+    }
+
+    public static Throwable closeSilently(AutoCloseable[] closables, Throwable 
root) {
+        return close(closables, root, true);
+    }
+
     /**
      * Close the AutoCloseable and suppress any Throwable thrown by the close 
call.
      * This method must NEVER throw any Throwable
@@ -112,15 +120,23 @@ public class CleanupUtils {
      *            the first exception encountered during release of resources
      * @return the root Throwable if not null or a new Throwable if any was 
thrown, otherwise, it returns null
      */
-    public static Throwable close(AutoCloseable[] closables, Throwable root) {
+    private static Throwable close(AutoCloseable[] closables, Throwable root, 
boolean silent) {
         if (closables != null) {
             for (AutoCloseable closable : closables) {
-                root = close(closable, root);
+                root = close(closable, root, silent);
             }
         }
         return root;
     }
 
+    public static Throwable close(AutoCloseable closable, Throwable root) {
+        return close(closable, root, false);
+    }
+
+    public static Throwable closeSilently(AutoCloseable closable, Throwable 
root) {
+        return close(closable, root, true);
+    }
+
     /**
      * Close the AutoCloseable and suppress any Throwable thrown by the close 
call.
      * This method must NEVER throw any Throwable
@@ -131,16 +147,18 @@ public class CleanupUtils {
      *            the first exception encountered during release of resources
      * @return the root Throwable if not null or a new Throwable if any was 
thrown, otherwise, it returns null
      */
-    public static Throwable close(AutoCloseable closable, Throwable root) {
+    private static Throwable close(AutoCloseable closable, Throwable root, 
boolean silent) {
         if (closable != null) {
             try {
                 closable.close();
             } catch (Throwable th) { // NOSONAR Will be suppressed
-                try {
-                    LOGGER.log(ExceptionUtils.causedByInterrupt(th) ? 
Level.DEBUG : Level.WARN,
-                            "Failure closing a closeable resource {}", 
closable.getClass().getName(), th);
-                } catch (Throwable loggingFailure) { // NOSONAR: Ignore 
catching Throwable
-                    // NOSONAR ignore logging failure
+                if (!silent) {
+                    try {
+                        LOGGER.log(ExceptionUtils.causedByInterrupt(th) ? 
Level.DEBUG : Level.WARN,
+                                "Failure closing a closeable resource {}", 
closable.getClass().getName(), th);
+                    } catch (Throwable loggingFailure) { // NOSONAR: Ignore 
catching Throwable
+                        // NOSONAR ignore logging failure
+                    }
                 }
                 root = ExceptionUtils.suppress(root, th); // NOSONAR
             }

Reply via email to