/** * Creates a predicate which will be true if the latest error is a subclass of {@code errorClass}. * * @param errorClass error class to match * @return predicate */ static RetryPredicate ofMatchingErrors(final Class<? extends Throwable> errorClass) { return retryContext -> errorClass.isAssignableFrom(retryContext.getLatestError().getClass()); }
/** * Creates a predicate which matches another predicate for status codes for {@link SphereServiceException}s. * * @param predicate predicate which tests if a status code should match the {@link RetryPredicate} * @return predicate */ static RetryPredicate ofMatchingStatusCodes(final Predicate<Integer> predicate) { return retryContext -> retryContext.getLatestError() instanceof SphereServiceException && predicate.test(((SphereServiceException) retryContext.getLatestError()).getStatusCode()); } }
@Override public RetryStrategy apply(final RetryContext retryOperationContext) { return RetryStrategy.stop(retryOperationContext.getLatestError()); }
@Override public RetryStrategy apply(final RetryContext retryOperationContext) { return RetryStrategy.resume(retryOperationContext.getLatestError()); }
@Override public RetryStrategy apply(final RetryContext retryOperationContext) { if (retryOperationContext.getAttempt() > maxAttempts) { return RetryStrategy.resume(retryOperationContext.getLatestError()); } else { final Duration duration = durationFunction.apply(retryOperationContext); final Object parameterObject = retryOperationContext.getLatestParameter(); return RetryStrategy.retryScheduled(parameterObject, duration); } }
@Override public RetryStrategy apply(final RetryContext retryOperationContext) { if (retryOperationContext.getAttempt() > maxAttempts) { return RetryStrategy.resume(retryOperationContext.getLatestError()); } else { final Object parameterObject = retryOperationContext.getLatestParameter(); return RetryStrategy.retryImmediately(parameterObject); } }
private List<RetryRule> createRules() { final Predicate<RetryContext> isFatal = r -> { final Throwable latestError = r.getLatestError(); final boolean unknownHost = latestError instanceof HttpException && latestError != null && latestError instanceof UnknownHostException; final boolean unauthorized = latestError instanceof UnauthorizedException; return unknownHost || unauthorized; }; final RetryRule fatalRetryRule = RetryRule.of(isFatal, RetryAction.ofShutdownServiceAndSendLatestException()); final RetryRule retryScheduledRetryRule = RetryRule.of(RetryPredicate.ofAlwaysTrue(), RetryAction.ofScheduledRetry(2, retryContext -> Duration.ofMillis(retryContext.getAttempt() * retryContext.getAttempt() * 50))); return asList(fatalRetryRule, retryScheduledRetryRule); }
private List<RetryRule> createRules() { final Predicate<RetryContext> isFatal = r -> { final Throwable latestError = r.getLatestError(); final boolean unknownHost = latestError instanceof HttpException && latestError != null && latestError instanceof UnknownHostException; final boolean unauthorized = latestError instanceof UnauthorizedException; return unknownHost || unauthorized; }; final RetryRule fatalRetryRule = RetryRule.of(isFatal, RetryAction.ofShutdownServiceAndSendLatestException()); final RetryRule retryScheduledRetryRule = RetryRule.of(RetryPredicate.ofAlwaysTrue(), RetryAction.ofScheduledRetry(2, retryContext -> Duration.ofMillis(retryContext.getAttempt() * retryContext.getAttempt() * 50))); return asList(fatalRetryRule, retryScheduledRetryRule); }
private static Predicate<RetryContext> isDeleteAndNewVersionIsKnown() { return retryContext -> retryContext.getLatestError() instanceof ConcurrentModificationException && ((ConcurrentModificationException) retryContext.getLatestError()).getCurrentVersion() != null && retryContext.getLatestParameter() instanceof SphereRequest && ((SphereRequest) retryContext.getLatestParameter()).httpRequestIntent().getHttpMethod() == HttpMethod.DELETE; }