Increased number of retries and added variable delay to better withstand StorageException timeout.
Change-Id: Ic33d4e66e2787c717f7e3c90879d725a6e3e74d7
diff --git a/utils/misc/src/main/java/org/onlab/util/Tools.java b/utils/misc/src/main/java/org/onlab/util/Tools.java
index d9eb111..73c8802 100644
--- a/utils/misc/src/main/java/org/onlab/util/Tools.java
+++ b/utils/misc/src/main/java/org/onlab/util/Tools.java
@@ -39,6 +39,7 @@
import java.util.Collection;
import java.util.Dictionary;
import java.util.List;
+import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -62,6 +63,8 @@
private static final Logger log = getLogger(Tools.class);
+ private static Random random = new Random();
+
/**
* Returns a thread factory that produces threads named according to the
* supplied name pattern.
@@ -195,6 +198,20 @@
}
/**
+ * 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(random.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