[NO ISSUE]: Allow closing resources silently

Change-Id: I5d4b9f953fcc5557fe0556dac4004c44dd26be5c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18317
Reviewed-by: Michael Blow <mblow@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Hussain Towaileb <hussainht@gmail.com>
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 4de44be..5ebfba4 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 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 @@
      *            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 @@
      *            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
             }