2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.webservice.retry;
15 import java.util.function.Consumer;
16 import java.util.function.Supplier;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Interface for strategies implementing the retry behavior of requests against the Miele cloud.
24 * @author Björn Lange - Initial contribution
27 public interface RetryStrategy {
29 * Performs an operation which may be retried several times.
31 * If retrying fails or a critical error occurred, this method may throw {@link Exception}s of any type.
33 * @param operation The operation to perform. To signal that an error can be resolved by retrying this operation it
34 * should throw an {@link Exception}. Whether the operation is retried is up to the {@link RetryStrategy}
36 * @param onException Handler to invoke when an {@link Exception} is handled by retrying the {@code operation}. This
37 * handler should at least log a message. It must not throw any exception.
38 * @return The object returned by {@code operation} if it completed successfully.
40 <@Nullable T> T performRetryableOperation(Supplier<T> operation, Consumer<Exception> onException);
43 * Performs an operation which may be retried several times.
45 * If retrying fails or a critical error occurred, this method may throw {@link Exception}s of any type.
47 * @param operation The operation to perform. To signal that an error can be resolved by retrying this operation it
48 * should throw an {@link Exception}. Whether the operation is retried is up to the {@link RetryStrategy}
50 * @param onException Handler to invoke when an {@link Exception} is handled by retrying the {@code operation}. This
51 * handler should at least log a message. It may not throw any exception.
53 default void performRetryableOperation(Runnable operation, Consumer<Exception> onException) {
54 performRetryableOperation(new Supplier<@Nullable Void>() {
56 public @Nullable Void get() {