@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); } }
@SuppressWarnings("unchecked") private static RetryAction retryWithNewVersion() { return (RetryContext c) -> { final SphereRequest sphereRequest = (SphereRequest) c.getLatestParameter(); final Object newParameter = new SphereRequestDecorator(sphereRequest) { @Override public HttpRequestIntent httpRequestIntent() { final HttpRequestIntent original = super.httpRequestIntent(); final Long currentVersion = ((ConcurrentModificationException) c.getLatestError()).getCurrentVersion(); final String path = original.getPath().replaceAll("\\bversion=\\d+", "version=" + currentVersion); return original.withPath(path); } }; return RetryStrategy.retryImmediately(newParameter); }; } }
@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 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; }