]> git.basschouten.com Git - openhab-addons.git/blob
7240577c3de5a2df1a6d6b203b017ca77b34b54b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mielecloud.internal.webservice.retry;
14
15 import java.util.function.Consumer;
16 import java.util.function.Supplier;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * {@link RetryStrategy} implementation wrapping the consecutive execution of two retry strategies.
23  *
24  * @author Björn Lange and Roland Edelhoff - Initial contribution
25  */
26 @NonNullByDefault
27 public class RetryStrategyCombiner implements RetryStrategy {
28     private final RetryStrategy first;
29     private final RetryStrategy second;
30
31     /**
32      * Creates a new {@link RetryStrategy} combining the given ones.
33      *
34      * @param first First strategy to execute.
35      * @param second Strategy to execute in each execution of {@code first}.
36      */
37     public RetryStrategyCombiner(RetryStrategy first, RetryStrategy second) {
38         this.first = first;
39         this.second = second;
40     }
41
42     @Override
43     public <@Nullable T> T performRetryableOperation(Supplier<T> operation, Consumer<Exception> onException) {
44         return first.performRetryableOperation(() -> second.performRetryableOperation(operation, onException),
45                 onException);
46     }
47 }