use of org.gradle.internal.resource.ExternalResourceReadResult in project gradle by gradle.
the class PublicKeyDownloadService method tryDownloadKeyFromServer.
@SuppressWarnings("OptionalAssignedToNull")
private void tryDownloadKeyFromServer(String fingerprint, List<URI> baseUris, PublicKeyResultBuilder builder, Consumer<? super PGPPublicKeyRing> onKeyring) {
Deque<URI> serversLeft = new ArrayDeque<>(baseUris);
try {
ExponentialBackoff<ExponentialBackoff.Signal> backoff = ExponentialBackoff.of(5, TimeUnit.SECONDS, 50, TimeUnit.MILLISECONDS);
backoff.retryUntil(() -> {
URI baseUri = serversLeft.poll();
if (baseUri == null) {
// no more servers left despite retries
return IOQuery.Result.successful(false);
}
try {
ExternalResourceName query = toQuery(baseUri, fingerprint);
ExternalResourceReadResult<IOQuery.Result<Boolean>> response = client.resource(query).withContentIfPresent(inputStream -> {
extractKeyRing(inputStream, builder, onKeyring);
return IOQuery.Result.successful(true);
});
if (response != null) {
return response.getResult();
} else {
logKeyDownloadAttempt(fingerprint, baseUri);
// null means the resource is missing from this repo
}
} catch (Exception e) {
logKeyDownloadAttempt(fingerprint, baseUri);
// add for retry
serversLeft.add(baseUri);
}
// retry
return IOQuery.Result.notSuccessful(false);
});
} catch (InterruptedException | IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
Aggregations