2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.vpnservice.datastoreutils;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
14 import java.util.concurrent.Callable;
16 public class TaskRetryLooper {
17 private static final Logger LOG = LoggerFactory.getLogger(TaskRetryLooper.class);
19 private final long tick;
20 private final int maxRetries;
23 * @param tick sleep between steps in miliseconds
24 * @param maxRetries retries limit
26 public TaskRetryLooper(long tick, int maxRetries) {
28 this.maxRetries = maxRetries;
31 public <T> T loopUntilNoException(Callable<T> task) throws Exception {
34 Exception taskException = null;
35 for (int i = 0; i < maxRetries; i++) {
40 } catch (Exception exception) {
41 LOG.debug("looper step failed: {}", exception.getMessage());
42 taskException = exception;
47 } catch (InterruptedException e) {
48 LOG.debug("interrupted: {}", e.getMessage(), e);
52 if (taskException != null) {
56 LOG.debug("looper step succeeded: {}", output);