Search in sources :

Example 1 with ExternalResourceReadResult

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);
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) IOException(java.io.IOException) URI(java.net.URI) ArrayDeque(java.util.ArrayDeque) URISyntaxException(java.net.URISyntaxException) UncheckedException(org.gradle.internal.UncheckedException) IOException(java.io.IOException) ExternalResourceReadResult(org.gradle.internal.resource.ExternalResourceReadResult)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayDeque (java.util.ArrayDeque)1 UncheckedException (org.gradle.internal.UncheckedException)1 ExternalResourceName (org.gradle.internal.resource.ExternalResourceName)1 ExternalResourceReadResult (org.gradle.internal.resource.ExternalResourceReadResult)1