>From Michael Blow <[email protected]>: Michael Blow has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18399 )
Change subject: [NO ISSUE][HYR][MISC] += invocation helpers for unchecked exceptions ...................................................................... [NO ISSUE][HYR][MISC] += invocation helpers for unchecked exceptions Ext-ref: MB-62442 Change-Id: I3b36376e51dbed8915c9bc32963a4243852879cf Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18399 Reviewed-by: Michael Blow <[email protected]> Tested-by: Michael Blow <[email protected]> --- M hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingSupplier.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java 2 files changed, 54 insertions(+), 0 deletions(-) Approvals: Michael Blow: Looks good to me, approved; Verified diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java index f4b6e20..c50c6b5 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java @@ -39,6 +39,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.google.common.util.concurrent.UncheckedExecutionException; + public class InvokeUtil { private static final Logger LOGGER = LogManager.getLogger(); @@ -357,6 +359,26 @@ throw HyracksDataException.create(new InterruptedException()); } + public static Exception unwrapUnchecked(UncheckedExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof Error err) { + throw err; + } else if (cause instanceof Exception ex) { + return ex; + } else { + return HyracksDataException.create(cause); + } + } + + public static HyracksDataException unwrapUncheckedHyracks(UncheckedExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof Error err) { + throw err; + } else { + return HyracksDataException.create(cause); + } + } + @FunctionalInterface public interface IFailedAttemptCallback { void attemptFailed(ComputingAction<?> action, int attempt, boolean isFinal, Span span, Throwable failure); diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingSupplier.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingSupplier.java index 28f5e29..9389953 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingSupplier.java +++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingSupplier.java @@ -18,7 +18,26 @@ */ package org.apache.hyracks.util; +import java.util.function.Supplier; + +import com.google.common.util.concurrent.UncheckedExecutionException; + @FunctionalInterface public interface ThrowingSupplier<T> { T get() throws Exception; + + @SuppressWarnings("Duplicates") + static <T> Supplier<T> asUnchecked(ThrowingSupplier<T> supplier) { + return () -> { + try { + return supplier.get(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new UncheckedExecutionException(e); + } catch (Exception e) { + throw new UncheckedExecutionException(e); + } + }; + } + } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18399 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: trinity Gerrit-Change-Id: I3b36376e51dbed8915c9bc32963a4243852879cf Gerrit-Change-Number: 18399 Gerrit-PatchSet: 3 Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Hussain Towaileb <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-MessageType: merged
