String errorMessage = String.format("Operation '%s:%s' failed after retrying %d times, retry limit %d", operationName, shortDescription, internalNumberOfRetries.get(), 3); logger.debug(errorMessage, retryException.getLastFailedAttempt().getExceptionCause()); throw new RuntimeException(errorMessage, retryException.getLastFailedAttempt().getExceptionCause());
private byte[] retrieveBytes(String url) { MutableInt retry = new MutableInt(0); try { return retryer.call(() -> request(url, retry)); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } catch (RetryException e) { if (e.getLastFailedAttempt().hasException()) { throw new RuntimeException("Max retries exceeded", e.getLastFailedAttempt().getExceptionCause()); } else { throw new RuntimeException("Max retries exceeded", e); } } }
private void handleException(final String request, final String type, final List<String> ids, final Exception exception, final String metricName) { log.error("Failed {} metadata of type {} with ids {}. {}", request, type, ids, exception); String exceptionName = exception.getClass().getSimpleName(); if (exception instanceof RetryException) { final Throwable error = ((RetryException) exception).getLastFailedAttempt().getExceptionCause(); if (error != null) { exceptionName = error.getClass().getSimpleName(); } } final Map<String, String> tags = ImmutableMap .<String, String>builder().put("status", "failure").put("exception", exceptionName).build(); registry.counter(registry.createId(metricName).withTags(tags)).increment(); log(request, type, ids.toString(), null, exception.getMessage(), exception, true); }
private void handleException(final String request, final String type, final String id, final Exception exception, final String metricName) { log.error("Failed {} metadata of type {} with id {}. {}", request, type, id, exception); String exceptionName = exception.getClass().getSimpleName(); if (exception instanceof RetryException) { final Throwable error = ((RetryException) exception).getLastFailedAttempt().getExceptionCause(); if (error != null) { exceptionName = error.getClass().getSimpleName(); } } final Map<String, String> tags = ImmutableMap .<String, String>builder().put("status", "failure").put("name", id).put("exception", exceptionName).build(); registry.counter(registry.createId(metricName).withTags(tags)).increment(); log(request, type, id, null, exception.getMessage(), exception, true); }
String errorMessage = String.format("Operation '%s:%s' failed after retrying %d times, retry limit %d", operationName, shortDescription, internalNumberOfRetries.get(), 3); logger.debug(errorMessage, retryException.getLastFailedAttempt().getExceptionCause()); throw new RuntimeException(errorMessage, retryException.getLastFailedAttempt().getExceptionCause());
} catch (RetryException e) { LOGGER.error("Retry error getting leaders for partitions of " + topic, e); LOGGER.error("ATTEMPT EXCEPTION: ", e.getLastFailedAttempt().getExceptionCause()); throw new BrokerQueryException("Error finding broker:", e.getLastFailedAttempt().getExceptionCause());
@Test public void testRetryIfResult() throws Exception { Callable<Boolean> callable = notNullAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .build(); assertTrue(retryer.call(callable)); callable = notNullAfter5Attempts(); retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); try { retryer.call(callable); fail("Exception expected"); } catch (RetryException e) { assertEquals(3, e.getNumberOfFailedAttempts()); assertTrue(e.getLastFailedAttempt().hasResult()); assertNull(e.getLastFailedAttempt().getResult()); assertNull(e.getCause()); } }