2 * Copyright (c) 2015 Cisco Systems, Inc. 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.openflowplugin.common.wait;
11 import java.util.concurrent.Callable;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
16 * Created by mirehak on 4/28/15.
18 public class SimpleTaskRetryLooper {
20 private static Logger LOG = LoggerFactory.getLogger(SimpleTaskRetryLooper.class);
22 private final long tick;
23 private final int maxRetries;
26 * @param tick sleep between steps in miliseconds
27 * @param maxRetries retries limit
29 public SimpleTaskRetryLooper(long tick, int maxRetries) {
31 this.maxRetries = maxRetries;
34 public <T> T loopUntilNoException(Callable<T> task) throws Exception {
37 Exception taskException = null;
38 for (int i = 0; i < maxRetries; i++) {
43 } catch (Exception exception) {
44 LOG.debug("looper step failed: {}", exception.getMessage());
45 taskException = exception;
50 } catch (InterruptedException e) {
51 LOG.debug("interrupted: {}", e.getMessage(), e);
55 if (taskException != null) {