You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2021/12/03 16:32:27 UTC
[ratis] branch master updated: RATIS-1458. Implement ExceptionDependentRetry#toString (#553)
This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 6fef0f7 RATIS-1458. Implement ExceptionDependentRetry#toString (#553)
6fef0f7 is described below
commit 6fef0f72aa5e811a4f5f717def2bff65ab65fac4
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Fri Dec 3 17:32:21 2021 +0100
RATIS-1458. Implement ExceptionDependentRetry#toString (#553)
---
.../apache/ratis/retry/ExceptionDependentRetry.java | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/ratis-common/src/main/java/org/apache/ratis/retry/ExceptionDependentRetry.java b/ratis-common/src/main/java/org/apache/ratis/retry/ExceptionDependentRetry.java
index 4ac81a9..560301b 100644
--- a/ratis-common/src/main/java/org/apache/ratis/retry/ExceptionDependentRetry.java
+++ b/ratis-common/src/main/java/org/apache/ratis/retry/ExceptionDependentRetry.java
@@ -18,11 +18,13 @@
package org.apache.ratis.retry;
+import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.Preconditions;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
+import java.util.function.Supplier;
/**
* Exception dependent retry policy.
@@ -69,7 +71,7 @@ public final class ExceptionDependentRetry implements RetryPolicy {
private final RetryPolicy defaultPolicy;
private final Map<String, RetryPolicy> exceptionNameToPolicyMap;
private final int maxAttempts;
-
+ private final Supplier<String> toStringSupplier;
private ExceptionDependentRetry(RetryPolicy defaultPolicy,
Map<String, RetryPolicy> policyMap, int maxAttempts) {
@@ -77,6 +79,15 @@ public final class ExceptionDependentRetry implements RetryPolicy {
this.defaultPolicy = defaultPolicy;
this.exceptionNameToPolicyMap = Collections.unmodifiableMap(policyMap);
this.maxAttempts = maxAttempts;
+ this.toStringSupplier = JavaUtils.memoize(() -> {
+ final StringBuilder b = new StringBuilder(JavaUtils.getClassSimpleName(getClass())).append("(")
+ .append("maxAttempts=").append(maxAttempts).append("; ")
+ .append("defaultPolicy=").append(defaultPolicy).append("; ")
+ .append("map={");
+ policyMap.forEach((key, value) -> b.append(key).append("->").append(value).append(", "));
+ b.setLength(b.length() - 2);
+ return b.append("})").toString();
+ });
}
@Override
@@ -98,4 +109,9 @@ public final class ExceptionDependentRetry implements RetryPolicy {
return event.getAttemptCount() < maxAttempts ? policy.handleAttemptFailure(event::getCauseCount) :
NO_RETRY_ACTION;
}
+
+ @Override
+ public String toString() {
+ return toStringSupplier.get();
+ }
}