feat: 2.0.0
1. 删除GuavaRetry的retryIfException
This commit is contained in:
parent
4e3aec94c2
commit
b19bc2afb8
@ -1,7 +1,6 @@
|
|||||||
package com.aizuda.easy.retry.client.core;
|
package com.aizuda.easy.retry.client.core;
|
||||||
|
|
||||||
import com.github.rholder.retry.RetryListener;
|
import com.github.rholder.retry.RetryListener;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,8 +10,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface RetryExecutorParameter<BR, SR> {
|
public interface RetryExecutorParameter<BR, SR> {
|
||||||
|
|
||||||
Predicate<Throwable> exceptionPredicate();
|
|
||||||
|
|
||||||
BR backOff();
|
BR backOff();
|
||||||
|
|
||||||
SR stop();
|
SR stop();
|
||||||
|
@ -33,7 +33,6 @@ public class GuavaRetryExecutor extends AbstractRetryExecutor<WaitStrategy, Stop
|
|||||||
public Retryer build(RetryExecutorParameter<WaitStrategy, StopStrategy> parameter) {
|
public Retryer build(RetryExecutorParameter<WaitStrategy, StopStrategy> parameter) {
|
||||||
|
|
||||||
RetryerBuilder<Object> retryerBuilder = RetryerBuilder.newBuilder();
|
RetryerBuilder<Object> retryerBuilder = RetryerBuilder.newBuilder();
|
||||||
retryerBuilder.retryIfException(throwable -> parameter.exceptionPredicate().apply(throwable));
|
|
||||||
retryerBuilder.withWaitStrategy(parameter.backOff());
|
retryerBuilder.withWaitStrategy(parameter.backOff());
|
||||||
retryerBuilder.withStopStrategy(parameter.stop());
|
retryerBuilder.withStopStrategy(parameter.stop());
|
||||||
for (RetryListener retryListener : parameter.getRetryListeners()) {
|
for (RetryListener retryListener : parameter.getRetryListeners()) {
|
||||||
|
@ -76,11 +76,6 @@ public class ReportListener implements Listener<RetryTaskDTO> {
|
|||||||
public RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter() {
|
public RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter() {
|
||||||
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Predicate<Throwable> exceptionPredicate() {
|
|
||||||
return throwable -> Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WaitStrategy backOff() {
|
public WaitStrategy backOff() {
|
||||||
return WaitStrategies.fixedWait(2, TimeUnit.SECONDS);
|
return WaitStrategies.fixedWait(2, TimeUnit.SECONDS);
|
||||||
|
@ -127,30 +127,6 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
|
|||||||
protected abstract Consumer<Throwable> doGetRetryErrorConsumer(RetryerInfo retryerInfo, Object[] params);
|
protected abstract Consumer<Throwable> doGetRetryErrorConsumer(RetryerInfo retryerInfo, Object[] params);
|
||||||
protected abstract Callable doGetCallable(RetryExecutor<WaitStrategy, StopStrategy> retryExecutor,Object[] params);
|
protected abstract Callable doGetCallable(RetryExecutor<WaitStrategy, StopStrategy> retryExecutor,Object[] params);
|
||||||
protected abstract RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo);
|
protected abstract RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo);
|
||||||
|
|
||||||
protected boolean validate(Class<? extends Throwable> throwable,RetryerInfo retryerInfo) {
|
|
||||||
|
|
||||||
Set<Class<? extends Throwable>> exclude = retryerInfo.getExclude();
|
|
||||||
Set<Class<? extends Throwable>> include = retryerInfo.getInclude();
|
|
||||||
if (CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (Class<? extends Throwable> e : include) {
|
|
||||||
if (e.isAssignableFrom(throwable)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(exclude)) {
|
|
||||||
for (Class<? extends Throwable> e : exclude) {
|
|
||||||
if (e.isAssignableFrom(throwable)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上报数据
|
* 上报数据
|
||||||
*
|
*
|
||||||
|
@ -128,11 +128,6 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
|||||||
|
|
||||||
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Predicate<Throwable> exceptionPredicate() {
|
|
||||||
return throwable -> LocalRetryStrategies.super.validate(throwable.getClass(), retryerInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WaitStrategy backOff() {
|
public WaitStrategy backOff() {
|
||||||
return WaitStrategies.fixedWait(retryerInfo.getLocalInterval(), TimeUnit.SECONDS);
|
return WaitStrategies.fixedWait(retryerInfo.getLocalInterval(), TimeUnit.SECONDS);
|
||||||
|
@ -95,11 +95,6 @@ public class ManualRetryStrategies extends AbstractRetryStrategies {
|
|||||||
protected RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo) {
|
protected RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo) {
|
||||||
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Predicate<Throwable> exceptionPredicate() {
|
|
||||||
return throwable -> ManualRetryStrategies.super.validate(throwable.getClass(), retryerInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WaitStrategy backOff() {
|
public WaitStrategy backOff() {
|
||||||
return WaitStrategies.fixedWait(500, TimeUnit.MILLISECONDS);
|
return WaitStrategies.fixedWait(500, TimeUnit.MILLISECONDS);
|
||||||
|
@ -92,10 +92,6 @@ public class RemoteRetryStrategies extends AbstractRetryStrategies {
|
|||||||
@Override
|
@Override
|
||||||
protected RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo) {
|
protected RetryExecutorParameter<WaitStrategy, StopStrategy> getRetryExecutorParameter(RetryerInfo retryerInfo) {
|
||||||
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
return new RetryExecutorParameter<WaitStrategy, StopStrategy>() {
|
||||||
@Override
|
|
||||||
public Predicate<Throwable> exceptionPredicate() {
|
|
||||||
return throwable -> RemoteRetryStrategies.super.validate(throwable.getClass(), retryerInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WaitStrategy backOff() {
|
public WaitStrategy backOff() {
|
||||||
|
Loading…
Reference in New Issue
Block a user