Filter throwable by ExceptionTypeFilter.
Signed-off-by: Mengqi Xu <2663479778@qq.com>
This commit is contained in:
parent
ed86daa080
commit
c9a099339f
|
@ -20,6 +20,8 @@ import java.time.Duration;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.springframework.util.ExceptionTypeFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specification for retry attempts on a given method, combining common
|
* A specification for retry attempts on a given method, combining common
|
||||||
* retry characteristics. This roughly matches the annotation attributes
|
* retry characteristics. This roughly matches the annotation attributes
|
||||||
|
@ -62,28 +64,9 @@ public record MethodRetrySpec(
|
||||||
|
|
||||||
|
|
||||||
MethodRetryPredicate combinedPredicate() {
|
MethodRetryPredicate combinedPredicate() {
|
||||||
return (method, throwable) -> {
|
return (method, throwable) -> new ExceptionTypeFilter(this.includes, this.excludes, true)
|
||||||
if (!this.excludes.isEmpty()) {
|
.match(throwable.getClass()) &&
|
||||||
for (Class<? extends Throwable> exclude : this.excludes) {
|
this.predicate.shouldRetry(method, throwable);
|
||||||
if (exclude.isInstance(throwable)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.includes.isEmpty()) {
|
|
||||||
boolean included = false;
|
|
||||||
for (Class<? extends Throwable> include : this.includes) {
|
|
||||||
if (include.isInstance(throwable)) {
|
|
||||||
included = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!included) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.predicate.shouldRetry(method, throwable);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
|
import org.springframework.util.ExceptionTypeFilter;
|
||||||
import org.springframework.util.backoff.BackOff;
|
import org.springframework.util.backoff.BackOff;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +30,7 @@ import org.springframework.util.backoff.BackOff;
|
||||||
*
|
*
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @author Mahmoud Ben Hassine
|
* @author Mahmoud Ben Hassine
|
||||||
|
* @author Mengqi Xu
|
||||||
* @since 7.0
|
* @since 7.0
|
||||||
*/
|
*/
|
||||||
class DefaultRetryPolicy implements RetryPolicy {
|
class DefaultRetryPolicy implements RetryPolicy {
|
||||||
|
@ -55,26 +57,10 @@ class DefaultRetryPolicy implements RetryPolicy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldRetry(Throwable throwable) {
|
public boolean shouldRetry(Throwable throwable) {
|
||||||
if (!this.excludes.isEmpty()) {
|
ExceptionTypeFilter exceptionTypeFilter = new ExceptionTypeFilter(this.includes,
|
||||||
for (Class<? extends Throwable> excludedType : this.excludes) {
|
this.excludes, true);
|
||||||
if (excludedType.isInstance(throwable)) {
|
return exceptionTypeFilter.match(throwable.getClass()) &&
|
||||||
return false;
|
(this.predicate == null || this.predicate.test(throwable));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.includes.isEmpty()) {
|
|
||||||
boolean included = false;
|
|
||||||
for (Class<? extends Throwable> includedType : this.includes) {
|
|
||||||
if (includedType.isInstance(throwable)) {
|
|
||||||
included = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!included) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.predicate == null || this.predicate.test(throwable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue