@@ -78,32 +78,33 @@ public RetryState() {
7878 * which is usually synchronous code.
7979 *
8080 * @param attemptException The exception produced by the most recent attempt.
81- * It is passed to the {@code retryPredicate} and to the {@code exceptionTransformer}.
82- * @param exceptionTransformer A function that chooses which exception to preserve as a prospective failed result of the associated
83- * retryable activity and may also transform or mutate the exceptions.
84- * The choice is between
81+ * It is passed to the {@code retryPredicate} and to the {@code onAttemptFailureOperator}.
82+ * @param onAttemptFailureOperator The action that is called once per failed attempt before (in the happens-before order) the
83+ * {@code retryPredicate}, regardless of whether the {@code retryPredicate} is called.
84+ * This action is allowed to have side effects.
85+ * <p>
86+ * It also has to choose which exception to preserve as a prospective failed result of the associated retryable activity.
87+ * The {@code onAttemptFailureOperator} may mutate its arguments, choose from the arguments, or return a different exception,
88+ * but it must return a {@code @}{@link NonNull} value.
89+ * The choice is between</p>
8590 * <ul>
8691 * <li>the previously chosen exception or {@code null} if none has been chosen
87- * (the first argument of the {@code exceptionTransformer })</li>
88- * <li>and the exception from the most recent attempt (the second argument of the {@code exceptionTransformer }).</li>
92+ * (the first argument of the {@code onAttemptFailureOperator })</li>
93+ * <li>and the exception from the most recent attempt (the second argument of the {@code onAttemptFailureOperator }).</li>
8994 * </ul>
90- * The {@code exceptionTransformer} may either choose from its arguments, or return a different exception, a.k.a. transform,
91- * but it must return a {@code @}{@link NonNull} value.
92- * The {@code exceptionTransformer} is called once before (in the happens-before order) the {@code retryPredicate},
93- * regardless of whether the {@code retryPredicate} is called. The result of the {@code exceptionTransformer} does not affect
94- * what exception is passed to the {@code retryPredicate}.
95+ * The result of the {@code onAttemptFailureOperator} does not affect the exception passed to the {@code retryPredicate}.
9596 * @param retryPredicate {@code true} iff another attempt needs to be made. The {@code retryPredicate} is called not more than once
9697 * per attempt and only if all the following is true:
9798 * <ul>
98- * <li>{@code exceptionTransformer } completed normally;</li>
99+ * <li>{@code onAttemptFailureOperator } completed normally;</li>
99100 * <li>the most recent attempt is not the {@linkplain #isLastAttempt() last} one.</li>
100101 * </ul>
101102 * The {@code retryPredicate} accepts this {@link RetryState} and the exception from the most recent attempt,
102103 * and may mutate the exception. The {@linkplain RetryState} advances to represent the state of a new attempt
103104 * after (in the happens-before order) testing the {@code retryPredicate}, and only if the predicate completes normally.
104105 * @throws RuntimeException Iff any of the following is true:
105106 * <ul>
106- * <li>the {@code exceptionTransformer } completed abruptly;</li>
107+ * <li>the {@code onAttemptFailureOperator } completed abruptly;</li>
107108 * <li>the most recent attempt is the {@linkplain #isLastAttempt() last} one;</li>
108109 * <li>the {@code retryPredicate} completed abruptly;</li>
109110 * <li>the {@code retryPredicate} is {@code false}.</li>
@@ -112,10 +113,10 @@ public RetryState() {
112113 * i.e., the caller must not do any more attempts.
113114 * @see #advanceOrThrow(Throwable, BinaryOperator, BiPredicate)
114115 */
115- void advanceOrThrow (final RuntimeException attemptException , final BinaryOperator <Throwable > exceptionTransformer ,
116+ void advanceOrThrow (final RuntimeException attemptException , final BinaryOperator <Throwable > onAttemptFailureOperator ,
116117 final BiPredicate <RetryState , Throwable > retryPredicate ) throws RuntimeException {
117118 try {
118- doAdvanceOrThrow (attemptException , exceptionTransformer , retryPredicate , true );
119+ doAdvanceOrThrow (attemptException , onAttemptFailureOperator , retryPredicate , true );
119120 } catch (RuntimeException | Error unchecked ) {
120121 throw unchecked ;
121122 } catch (Throwable checked ) {
@@ -129,18 +130,19 @@ void advanceOrThrow(final RuntimeException attemptException, final BinaryOperato
129130 *
130131 * @see #advanceOrThrow(RuntimeException, BinaryOperator, BiPredicate)
131132 */
132- void advanceOrThrow (final Throwable attemptException , final BinaryOperator <Throwable > exceptionTransformer ,
133+ void advanceOrThrow (final Throwable attemptException , final BinaryOperator <Throwable > onAttemptFailureOperator ,
133134 final BiPredicate <RetryState , Throwable > retryPredicate ) throws Throwable {
134- doAdvanceOrThrow (attemptException , exceptionTransformer , retryPredicate , false );
135+ doAdvanceOrThrow (attemptException , onAttemptFailureOperator , retryPredicate , false );
135136 }
136137
137138 /**
138139 * @param onlyRuntimeExceptions {@code true} iff the method must expect {@link #exception} and {@code attemptException} to be
139140 * {@link RuntimeException}s and must not explicitly handle other {@link Throwable} types, of which only {@link Error} is possible
140141 * as {@link RetryState} does not have any source of {@link Exception}s.
142+ * @param onAttemptFailureOperator See {@link #advanceOrThrow(RuntimeException, BinaryOperator, BiPredicate)}.
141143 */
142144 private void doAdvanceOrThrow (final Throwable attemptException ,
143- final BinaryOperator <Throwable > exceptionTransformer ,
145+ final BinaryOperator <Throwable > onAttemptFailureOperator ,
144146 final BiPredicate <RetryState , Throwable > retryPredicate ,
145147 final boolean onlyRuntimeExceptions ) throws Throwable {
146148 assertTrue (attempt () < attempts );
@@ -149,7 +151,7 @@ private void doAdvanceOrThrow(final Throwable attemptException,
149151 assertTrue (isRuntime (attemptException ));
150152 }
151153 assertTrue (!isFirstAttempt () || exception == null );
152- Throwable newlyChosenException = transformException (exception , attemptException , onlyRuntimeExceptions , exceptionTransformer );
154+ Throwable newlyChosenException = callOnAttemptFailureOperator (exception , attemptException , onlyRuntimeExceptions , onAttemptFailureOperator );
153155 if (isLastAttempt ()) {
154156 exception = newlyChosenException ;
155157 throw exception ;
@@ -167,27 +169,31 @@ private void doAdvanceOrThrow(final Throwable attemptException,
167169
168170 /**
169171 * @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BinaryOperator, BiPredicate, boolean)}.
172+ * @param onAttemptFailureOperator See {@link #advanceOrThrow(RuntimeException, BinaryOperator, BiPredicate)}.
170173 */
171- private static Throwable transformException (@ Nullable final Throwable previouslyChosenException , final Throwable attemptException ,
172- final boolean onlyRuntimeExceptions , final BinaryOperator <Throwable > exceptionTransformer ) {
174+ private static Throwable callOnAttemptFailureOperator (
175+ @ Nullable final Throwable previouslyChosenException ,
176+ final Throwable attemptException ,
177+ final boolean onlyRuntimeExceptions ,
178+ final BinaryOperator <Throwable > onAttemptFailureOperator ) {
173179 if (onlyRuntimeExceptions && previouslyChosenException != null ) {
174180 assertTrue (isRuntime (previouslyChosenException ));
175181 }
176182 Throwable result ;
177183 try {
178- result = assertNotNull (exceptionTransformer .apply (previouslyChosenException , attemptException ));
184+ result = assertNotNull (onAttemptFailureOperator .apply (previouslyChosenException , attemptException ));
179185 if (onlyRuntimeExceptions ) {
180186 assertTrue (isRuntime (result ));
181187 }
182- } catch (Throwable exceptionTransformerException ) {
183- if (onlyRuntimeExceptions && !isRuntime (exceptionTransformerException )) {
184- throw exceptionTransformerException ;
188+ } catch (Throwable onAttemptFailureOperatorException ) {
189+ if (onlyRuntimeExceptions && !isRuntime (onAttemptFailureOperatorException )) {
190+ throw onAttemptFailureOperatorException ;
185191 }
186192 if (previouslyChosenException != null ) {
187- exceptionTransformerException .addSuppressed (previouslyChosenException );
193+ onAttemptFailureOperatorException .addSuppressed (previouslyChosenException );
188194 }
189- exceptionTransformerException .addSuppressed (attemptException );
190- throw exceptionTransformerException ;
195+ onAttemptFailureOperatorException .addSuppressed (attemptException );
196+ throw onAttemptFailureOperatorException ;
191197 }
192198 return result ;
193199 }
0 commit comments