>From Hussain Towaileb <[email protected]>:

Hussain Towaileb has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18317 )

Change subject: [NO ISSUE]: Allow closing resources silently
......................................................................

[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]>
---
M 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
1 file changed, 39 insertions(+), 8 deletions(-)

Approvals:
  Michael Blow: Looks good to me, approved
  Hussain Towaileb: Verified
  Jenkins: Verified

Objections:
  Anon. E. Moose #1000171: Violations found




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
             }

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18317
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I5d4b9f953fcc5557fe0556dac4004c44dd26be5c
Gerrit-Change-Number: 18317
Gerrit-PatchSet: 2
Gerrit-Owner: Hussain Towaileb <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Hussain Towaileb <[email protected]>
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Michael Blow <[email protected]>
Gerrit-MessageType: merged

Reply via email to