This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 85d2b0b814e12adea94f9a84ec0007a563be8028 Author: Michael Blow <[email protected]> AuthorDate: Mon Jun 24 14:52:15 2024 -0400 [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]> --- .../org/apache/hyracks/api/util/InvokeUtil.java | 22 ++++++++++++++++++++++ .../org/apache/hyracks/util/ThrowingSupplier.java | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) 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 f4b6e20858..c50c6b5fc0 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.Level; 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 @@ public class InvokeUtil { 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 28f5e29201..93899531d1 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); + } + }; + } + }
