>From Michael Blow <[email protected]>: Michael Blow has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17686 )
Change subject: [NO ISSUE][HYR][MISC] += InvokeUtil.getUninterruptible() ...................................................................... [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]> --- A hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/InterruptibleSupplier.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java 2 files changed, 60 insertions(+), 0 deletions(-) Approvals: Michael Blow: Looks good to me, but someone else must approve Ali Alsuliman: Looks good to me, approved Jenkins: Verified; 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 57f9750..f4b6e20 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.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; @@ -94,6 +95,27 @@ } /** + * 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. * * @return true if the original operation was interrupted, otherwise false 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 0000000..5de8c84 --- /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; +} -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17686 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: neo Gerrit-Change-Id: I65f866d1ebc68f2601869ddefef7fc12df890561 Gerrit-Change-Number: 17686 Gerrit-PatchSet: 2 Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Murtadha Al Hubail <[email protected]> Gerrit-MessageType: merged
