Remove calls to deprecated Throwables.propagate() method
Change-Id: Id48a8f1d4fb02560cfb77108f554556a3cad9b16
diff --git a/utils/misc/src/main/java/org/onlab/util/RetriesExceededException.java b/utils/misc/src/main/java/org/onlab/util/RetriesExceededException.java
new file mode 100644
index 0000000..d815353
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/util/RetriesExceededException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onlab.util;
+
+/**
+ * Exception that indicates the retry threshold has been exceeded.
+ */
+public class RetriesExceededException extends RuntimeException {
+
+ /**
+ * Create a retries exceeded exception.
+ *
+ * @param t Throwable that cased the last iteration to fail
+ */
+ RetriesExceededException(Throwable t) {
+ super(t);
+ }
+}
diff --git a/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java b/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
index 0221e63..dc82047 100644
--- a/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
+++ b/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
@@ -15,10 +15,10 @@
*/
package org.onlab.util;
-import java.util.function.Function;
-
import com.google.common.base.Throwables;
+import java.util.function.Function;
+
/**
* Function that retries execution on failure.
*
@@ -52,7 +52,8 @@
return baseFunction.apply(input);
} catch (Throwable t) {
if (!exceptionClass.isAssignableFrom(t.getClass()) || retryAttempts == maxRetries) {
- Throwables.propagate(t);
+ Throwables.throwIfUnchecked(t);
+ throw new RetriesExceededException(t);
}
Tools.randomDelay(maxDelayBetweenRetries);
retryAttempts++;
diff --git a/utils/misc/src/main/java/org/onlab/util/SharedExecutorService.java b/utils/misc/src/main/java/org/onlab/util/SharedExecutorService.java
index 79a0baf..d12ba17 100644
--- a/utils/misc/src/main/java/org/onlab/util/SharedExecutorService.java
+++ b/utils/misc/src/main/java/org/onlab/util/SharedExecutorService.java
@@ -16,7 +16,6 @@
package org.onlab.util;
import com.codahale.metrics.Timer;
-import com.google.common.base.Throwables;
import org.onlab.metrics.MetricsComponent;
import org.onlab.metrics.MetricsFeature;
import org.onlab.metrics.MetricsService;
@@ -222,7 +221,7 @@
runnable.run();
} catch (Exception e) {
log.error("Uncaught exception on " + runnable.getClass().getSimpleName(), e);
- throw Throwables.propagate(e);
+ throw new IllegalStateException(e);
}
}
}
diff --git a/utils/misc/src/main/java/org/onlab/util/SharedScheduledExecutorService.java b/utils/misc/src/main/java/org/onlab/util/SharedScheduledExecutorService.java
index be6baa6..1bdd6c5 100644
--- a/utils/misc/src/main/java/org/onlab/util/SharedScheduledExecutorService.java
+++ b/utils/misc/src/main/java/org/onlab/util/SharedScheduledExecutorService.java
@@ -16,7 +16,6 @@
package org.onlab.util;
-import com.google.common.base.Throwables;
import org.slf4j.Logger;
import java.util.Collection;
@@ -280,7 +279,7 @@
// if repeat flag set as false, we simply throw an exception to
// terminate this task
if (!repeatFlag) {
- throw Throwables.propagate(e);
+ throw new IllegalStateException(e);
}
}
}