|
@@ -139,7 +139,17 @@ public class RetryPolicies {
|
|
|
Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap) {
|
|
|
return new RemoteExceptionDependentRetry(defaultPolicy, exceptionToPolicyMap);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A retry policy for exceptions other than RemoteException.
|
|
|
+ */
|
|
|
+ public static final RetryPolicy retryOtherThanRemoteException(
|
|
|
+ RetryPolicy defaultPolicy,
|
|
|
+ Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap) {
|
|
|
+ return new OtherThanRemoteExceptionDependentRetry(defaultPolicy,
|
|
|
+ exceptionToPolicyMap);
|
|
|
+ }
|
|
|
+
|
|
|
public static final RetryPolicy failoverOnNetworkException(int maxFailovers) {
|
|
|
return failoverOnNetworkException(TRY_ONCE_THEN_FAIL, maxFailovers);
|
|
|
}
|
|
@@ -489,7 +499,37 @@ public class RetryPolicies {
|
|
|
return policy.shouldRetry(e, retries, failovers, isIdempotentOrAtMostOnce);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ static class OtherThanRemoteExceptionDependentRetry implements RetryPolicy {
|
|
|
+
|
|
|
+ private RetryPolicy defaultPolicy;
|
|
|
+ private Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap;
|
|
|
+
|
|
|
+ public OtherThanRemoteExceptionDependentRetry(RetryPolicy defaultPolicy,
|
|
|
+ Map<Class<? extends Exception>,
|
|
|
+ RetryPolicy> exceptionToPolicyMap) {
|
|
|
+ this.defaultPolicy = defaultPolicy;
|
|
|
+ this.exceptionToPolicyMap = exceptionToPolicyMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetryAction shouldRetry(Exception e, int retries, int failovers,
|
|
|
+ boolean isIdempotentOrAtMostOnce) throws Exception {
|
|
|
+ RetryPolicy policy = null;
|
|
|
+ // ignore Remote Exception
|
|
|
+ if (e instanceof RemoteException) {
|
|
|
+ // do nothing
|
|
|
+ } else {
|
|
|
+ policy = exceptionToPolicyMap.get(e.getClass());
|
|
|
+ }
|
|
|
+ if (policy == null) {
|
|
|
+ policy = defaultPolicy;
|
|
|
+ }
|
|
|
+ return policy.shouldRetry(
|
|
|
+ e, retries, failovers, isIdempotentOrAtMostOnce);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static class ExponentialBackoffRetry extends RetryLimited {
|
|
|
|
|
|
public ExponentialBackoffRetry(
|