<dependency>
<groupId>com.github.rholder</groupId>
<artifactId>guava-retrying</artifactId>
<version>2.0.0</version>
</dependency>
Method method = getCurrentMethod(point);
Retryable retryable = method.getAnnotation(Retryable.class);
int maxAttempts = retryable.maxAttempts();
Retryer<Object> retryer = RetryerBuilder.<Object>newBuilder()
.retryIfResult(Predicates.isNull()
.retryIfExceptionOfType(Exception.class)
.retryIfRuntimeException()
.retryIfException(Predicates.equalTo(new Exception()))
.withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts))
.build();
try {
return retryer.call(()->{
try {
return point.proceed();
} catch (Throwable throwable) {
log.info("Try again......");
}
return null;
});
} catch (RetryException | ExecutionException e) {
log.error("Retrying failed......",e);
}
return null;