Skip to content

Instantly share code, notes, and snippets.

@mchernyavskaya
Last active July 23, 2017 11:32
Show Gist options
  • Save mchernyavskaya/9f582e8186aaae4344332d46c9c65b0c to your computer and use it in GitHub Desktop.
Save mchernyavskaya/9f582e8186aaae4344332d46c9c65b0c to your computer and use it in GitHub Desktop.
private class SuccessCallback implements RetryCallback<Boolean, RuntimeException> {
@Override
public Boolean doWithRetry(RetryContext context) throws RuntimeException {
System.out.println("Success callback: attempt " + context.getRetryCount());
return true;
}
}
private class ExceptionCallback implements RetryCallback<Boolean, Exception> {
@Override
public Boolean doWithRetry(RetryContext context) throws Exception {
System.out.println("Exception callback: attempt " + context.getRetryCount());
throw new Exception("Test Exception");
}
}
private class SpecificExceptionCallback implements RetryCallback<Boolean, IOException> {
@Override
public Boolean doWithRetry(RetryContext context) throws IOException {
System.out.println("IO Exception callback: attempt " + context.getRetryCount());
throw new IOException("Test IO Exception");
}
}
private class LoggingRecoveryCallback implements RecoveryCallback<Boolean> {
@Override
public Boolean recover(RetryContext context) throws Exception {
System.out.println("Attempts exhausted. Total: " + context.getRetryCount());
System.out.println("Last exception: " + Optional.ofNullable(context.getLastThrowable())
.orElse(new Throwable("No exception thrown")).getMessage());
System.out.println("\n");
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment