/** * Invoke the HTTP REST call. * * @return The valid Result from the server */ public T withResult() { return ExponentialBackOff.execute(this::doWork); }
private static void handleFailure(int attempt, @NotNull RuntimeException e) { if (!EXPECTED_COMMUNICATION_ERRORS.contains(e.getClass())) throw e; doWait(attempt, e); }
@NotNull public static <T> T execute(@NotNull ExponentialBackOffFunction<T> fn) { for (int attempt = 0; attempt < FIBONACCI.length; attempt++) { try { return fn.execute(); } catch (Exception e) { handleFailure(attempt, (RuntimeException) e); } } throw new CognitiveException("Failed to communicate."); }