You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2024/05/24 00:06:25 UTC
Change in asterixdb[master]: [NO ISSUE]: Allow closing resources silently
From Hussain Towaileb <hu...@gmail.com>:
Hussain Towaileb has uploaded this change for review. ( 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
---
M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/CleanupUtils.java
1 file changed, 35 insertions(+), 8 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/17/18317/1
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: 1
Gerrit-Owner: Hussain Towaileb <hu...@gmail.com>
Gerrit-MessageType: newchange