X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Fatomix%2Futils%2Fsrc%2Fmain%2Fjava%2Fio%2Fatomix%2Futils%2Fconcurrent%2FRetries.java;fp=third-party%2Fatomix%2Futils%2Fsrc%2Fmain%2Fjava%2Fio%2Fatomix%2Futils%2Fconcurrent%2FRetries.java;h=0000000000000000000000000000000000000000;hb=593b4db0e12137995d5dc2e2a1fa984feca5ed2d;hp=bd42a2b9fa2ce6ca6430010c4838018f38623d73;hpb=aad091c6b6f05b167214f0f0091aaad5446a6715;p=controller.git diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/concurrent/Retries.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/concurrent/Retries.java deleted file mode 100644 index bd42a2b9fa..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/concurrent/Retries.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2017-present Open Networking Foundation - * - * Licensed 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 io.atomix.utils.concurrent; - -import java.util.concurrent.ThreadLocalRandom; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * Retry utilities. - */ -public final class Retries { - - /** - * Returns a function that retries execution on failure. - * @param base base function - * @param exceptionClass type of exception for which to retry - * @param maxRetries max number of retries before giving up - * @param maxDelayBetweenRetries max delay between successive retries. The actual delay is randomly picked from - * the interval (0, maxDelayBetweenRetries] - * @return function - * @param type of function input - * @param type of function output - */ - public static Function retryable(Function base, - Class exceptionClass, - int maxRetries, - int maxDelayBetweenRetries) { - return new RetryingFunction<>(base, exceptionClass, maxRetries, maxDelayBetweenRetries); - } - - /** - * Returns a Supplier that retries execution on failure. - * @param base base supplier - * @param exceptionClass type of exception for which to retry - * @param maxRetries max number of retries before giving up - * @param maxDelayBetweenRetries max delay between successive retries. The actual delay is randomly picked from - * the interval (0, maxDelayBetweenRetries] - * @return supplier - * @param type of supplied result - */ - public static Supplier retryable(Supplier base, - Class exceptionClass, - int maxRetries, - int maxDelayBetweenRetries) { - return () -> new RetryingFunction<>(v -> base.get(), - exceptionClass, - maxRetries, - maxDelayBetweenRetries).apply(null); - } - - /** - * Suspends the current thread for a random number of millis between 0 and - * the indicated limit. - * - * @param ms max number of millis - */ - public static void randomDelay(int ms) { - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(ms)); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted", e); - } - } - - /** - * Suspends the current thread for a specified number of millis and nanos. - * - * @param ms number of millis - * @param nanos number of nanos - */ - public static void delay(int ms, int nanos) { - try { - Thread.sleep(ms, nanos); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted", e); - } - } - - private Retries() { - } - -}