/** * Creates a first attempt {@link TimedAttemptSettings}. * * @return first attempt settings */ public TimedAttemptSettings createFirstAttempt() { return timedAlgorithm.createFirstAttempt(); }
/** * Returns {@code true} if another attempt should be made, or {@code false} otherwise. * * @param prevThrowable exception thrown by the previous attempt or null if a result was returned * instead * @param prevResponse response returned by the previous attempt or null if an exception was * thrown instead * @param nextAttemptSettings attempt settings, which will be used for the next attempt, if * accepted * @throws CancellationException if the retrying process should be canceled * @return {@code true} if another attempt should be made, or {@code false} otherwise */ public boolean shouldRetry( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings nextAttemptSettings) throws CancellationException { return resultAlgorithm.shouldRetry(prevThrowable, prevResponse) && nextAttemptSettings != null && timedAlgorithm.shouldRetry(nextAttemptSettings); }
/** * Creates a next attempt {@link TimedAttemptSettings}. This method will return first non-null * value, returned by either result or timed retry algorithms in that particular order. * * @param prevThrowable exception thrown by the previous attempt or null if a result was returned * instead * @param prevResponse response returned by the previous attempt or null if an exception was * thrown instead * @param prevSettings previous attempt settings * @return next attempt settings, can be {@code null}, if no there should be no new attempt */ public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { // a small optimization, which allows to avoid calling relatively heavy methods // like timedAlgorithm.createNextAttempt(), when it is not necessary. if (!resultAlgorithm.shouldRetry(prevThrowable, prevResponse)) { return null; } TimedAttemptSettings newSettings = resultAlgorithm.createNextAttempt(prevThrowable, prevResponse, prevSettings); if (newSettings == null) { newSettings = timedAlgorithm.createNextAttempt(prevSettings); } return newSettings; }
/** * Returns {@code true} if another attempt should be made, or {@code false} otherwise. * * @param prevThrowable exception thrown by the previous attempt or null if a result was returned * instead * @param prevResponse response returned by the previous attempt or null if an exception was * thrown instead * @param nextAttemptSettings attempt settings, which will be used for the next attempt, if * accepted * @throws CancellationException if the retrying process should be canceled * @return {@code true} if another attempt should be made, or {@code false} otherwise */ public boolean shouldRetry( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings nextAttemptSettings) throws CancellationException { return resultAlgorithm.shouldRetry(prevThrowable, prevResponse) && nextAttemptSettings != null && timedAlgorithm.shouldRetry(nextAttemptSettings); }
/** * Creates a next attempt {@link TimedAttemptSettings}. This method will return first non-null * value, returned by either result or timed retry algorithms in that particular order. * * @param prevThrowable exception thrown by the previous attempt or null if a result was returned * instead * @param prevResponse response returned by the previous attempt or null if an exception was * thrown instead * @param prevSettings previous attempt settings * @return next attempt settings, can be {@code null}, if no there should be no new attempt */ public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { // a small optimization, which allows to avoid calling relatively heavy methods // like timedAlgorithm.createNextAttempt(), when it is not necessary. if (!resultAlgorithm.shouldRetry(prevThrowable, prevResponse)) { return null; } TimedAttemptSettings newSettings = resultAlgorithm.createNextAttempt(prevThrowable, prevResponse, prevSettings); if (newSettings == null) { newSettings = timedAlgorithm.createNextAttempt(prevSettings); } return newSettings; }
/** * Creates a first attempt {@link TimedAttemptSettings}. * * @return first attempt settings */ public TimedAttemptSettings createFirstAttempt() { return timedAlgorithm.createFirstAttempt(); }