use of com.amazonaws.retry.v2.RetryPolicyContext in project aws-msk-iam-auth by aws.
the class MSKCredentialProvider method loadCredentialsWithRetry.
private AWSCredentials loadCredentialsWithRetry() {
RetryPolicyContext retryPolicyContext = RetryPolicyContext.builder().build();
boolean shouldTry = true;
try {
while (shouldTry) {
try {
AWSCredentials credentials = compositeDelegate.getCredentials();
if (credentials == null) {
throw new SdkClientException("Composite delegate returned empty credentials.");
}
return credentials;
} catch (SdkBaseException se) {
log.warn("Exception loading credentials. Retry Attempts: {}", retryPolicyContext.retriesAttempted(), se);
retryPolicyContext = createRetryPolicyContext(se, retryPolicyContext.retriesAttempted());
shouldTry = retryPolicy.shouldRetry(retryPolicyContext);
if (shouldTry) {
Thread.sleep(retryPolicy.computeDelayBeforeNextRetry(retryPolicyContext));
retryPolicyContext = createRetryPolicyContext(retryPolicyContext.exception(), retryPolicyContext.retriesAttempted() + 1);
} else {
throw se;
}
}
}
throw new SdkClientException("loadCredentialsWithRetry in unexpected location " + retryPolicyContext.totalRequests(), retryPolicyContext.exception());
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException("Interrupted while waiting for credentials.", ie);
}
}
Aggregations