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 c693439730260e769d28fbc08e3ae640f65a4027
Author: Michael Blow <[email protected]>
AuthorDate: Tue Aug 1 17:56:14 2023 -0400

    [NO ISSUE][HYR][MISC] += InvokeUtil.getUninterruptible()
    
    Change-Id: I65f866d1ebc68f2601869ddefef7fc12df890561
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17686
    Reviewed-by: Michael Blow <[email protected]>
    Reviewed-by: Ali Alsuliman <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
---
 .../org/apache/hyracks/api/util/InvokeUtil.java    | 22 ++++++++++++++++++++
 .../apache/hyracks/util/InterruptibleSupplier.java | 24 ++++++++++++++++++++++
 2 files changed, 46 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 57f9750459..f4b6e20858 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
@@ -32,6 +32,7 @@ import org.apache.hyracks.util.IOInterruptibleAction;
 import org.apache.hyracks.util.IOThrowingAction;
 import org.apache.hyracks.util.IRetryPolicy;
 import org.apache.hyracks.util.InterruptibleAction;
+import org.apache.hyracks.util.InterruptibleSupplier;
 import org.apache.hyracks.util.Span;
 import org.apache.hyracks.util.ThrowingAction;
 import org.apache.logging.log4j.Level;
@@ -93,6 +94,27 @@ public class InvokeUtil {
         }
     }
 
+    /**
+     * Executes the passed interruptible supplier, retrying if the operation 
is interrupted. Once the interruptible
+     * supplier completes, the current thread will be re-interrupted, if the 
original operation was interrupted.
+     */
+    public static <T> T getUninterruptibly(InterruptibleSupplier<T> 
interruptible) {
+        boolean interrupted = Thread.interrupted();
+        try {
+            while (true) {
+                try {
+                    return interruptible.get();
+                } catch (InterruptedException e) { // NOSONAR- we will 
re-interrupt the thread during unwind
+                    interrupted = true;
+                }
+            }
+        } finally {
+            if (interrupted) {
+                Thread.currentThread().interrupt();
+            }
+        }
+    }
+
     /**
      * Executes the passed interruptible, retrying if the operation is 
interrupted.
      *
diff --git 
a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/InterruptibleSupplier.java
 
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/InterruptibleSupplier.java
new file mode 100644
index 0000000000..5de8c84c9e
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/InterruptibleSupplier.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+@FunctionalInterface
+public interface InterruptibleSupplier<T> {
+    T get() throws InterruptedException;
+}

Reply via email to