@Override
public void fetchSegmentToLocal(final String uri, final File tempFile)
throws Exception {
RetryPolicies.exponentialBackoffRetryPolicy(_retryCount, _retryWaitMs, 5).attempt(() -> {
try {
int statusCode = _httpClient.downloadFile(new URI(uri), tempFile);
_logger.info("Downloaded file from: {} to: {}; Length of downloaded file: {}; Response status code: {}", uri,
tempFile, tempFile.length(), statusCode);
return true;
} catch (HttpErrorStatusException e) {
int statusCode = e.getStatusCode();
if (statusCode >= 500) {
_logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e);
return false;
} else {
_logger.error("Caught permanent exception while downloading file from: {}, won't retry", uri, e);
throw e;
}
} catch (Exception e) {
_logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e);
return false;
}
});
}