Created
April 8, 2018 19:58
-
-
Save adelinor/fa80fc3287bb388a6d55631244f8697f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements a common retry policy for async operations | |
* @param fn Async method to retry if necessary | |
* @return Result of the function invoked | |
*/ | |
private <T> ListenableFuture<T> invoke(Function<SharePointFacade, ListenableFuture<T>> fn) { | |
// Define an executor with Retry | |
RetryExecutor retryExecutor | |
= new AsyncRetryExecutor(this.scheduledExecutor) | |
.retryOn(AuthenticationExpiredException.class, | |
ConnectionRefusedException.class, | |
ConnectionFailedException.class, | |
UncategorizedException.class) | |
.withExponentialBackoff(500, 1.5) | |
.withUniformJitter() | |
.withMaxRetries(5); | |
return retryExecutor.getFutureWithRetry(ctx -> { | |
// calls the async method and will perform some extra | |
// actions based on the retry context: for instance re-authenticate | |
// if the failure was due to a connection expired exception | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment