|
17 | 17 |
|
18 | 18 | import dev.failsafe.event.EventListener; |
19 | 19 | import dev.failsafe.event.ExecutionAttemptedEvent; |
20 | | -import dev.failsafe.internal.util.Assert; |
21 | 20 | import dev.failsafe.event.ExecutionCompletedEvent; |
22 | 21 | import dev.failsafe.event.ExecutionScheduledEvent; |
23 | 22 | import dev.failsafe.internal.RetryPolicyImpl; |
| 23 | +import dev.failsafe.internal.util.Assert; |
24 | 24 |
|
25 | 25 | import java.time.Duration; |
26 | 26 | import java.time.temporal.ChronoUnit; |
|
59 | 59 | * @see RetryPolicyConfig |
60 | 60 | */ |
61 | 61 | public class RetryPolicyBuilder<R> extends DelayablePolicyBuilder<RetryPolicyBuilder<R>, RetryPolicyConfig<R>, R> |
62 | | - implements RetryPolicyListeners<RetryPolicyBuilder<R>, R> { |
| 62 | + implements PolicyListeners<RetryPolicyBuilder<R>, R> { |
63 | 63 |
|
64 | 64 | private static final int DEFAULT_MAX_RETRIES = 2; |
65 | 65 |
|
@@ -159,31 +159,63 @@ public RetryPolicyBuilder<R> abortWhen(R result) { |
159 | 159 | return this; |
160 | 160 | } |
161 | 161 |
|
162 | | - @Override |
| 162 | + /** |
| 163 | + * Registers the {@code listener} to be called when an execution is aborted. |
| 164 | + * <p>Note: Any exceptions that are thrown from within the {@code listener} are ignored. To provide an alternative |
| 165 | + * result for a failed execution, use a {@link Fallback}.</p> |
| 166 | + */ |
163 | 167 | public RetryPolicyBuilder<R> onAbort(EventListener<ExecutionCompletedEvent<R>> listener) { |
164 | 168 | config.abortListener = Assert.notNull(listener, "listener"); |
165 | 169 | return this; |
166 | 170 | } |
167 | 171 |
|
168 | | - @Override |
| 172 | + /** |
| 173 | + * Registers the {@code listener} to be called when an execution attempt fails. You can also use {@link |
| 174 | + * #onFailure(EventListener) onFailure} to determine when the execution attempt fails <i>and</i> and all retries have |
| 175 | + * failed. |
| 176 | + * <p>Note: Any exceptions that are thrown from within the {@code listener} are ignored. To provide an alternative |
| 177 | + * result for a failed execution, use a {@link Fallback}.</p> |
| 178 | + */ |
169 | 179 | public RetryPolicyBuilder<R> onFailedAttempt(EventListener<ExecutionAttemptedEvent<R>> listener) { |
170 | 180 | config.failedAttemptListener = Assert.notNull(listener, "listener"); |
171 | 181 | return this; |
172 | 182 | } |
173 | 183 |
|
174 | | - @Override |
| 184 | + /** |
| 185 | + * Registers the {@code listener} to be called when an execution fails and the {@link |
| 186 | + * RetryPolicyConfig#getMaxRetries() max retry attempts} or {@link RetryPolicyConfig#getMaxDuration() max duration} |
| 187 | + * are exceeded. |
| 188 | + * <p>Note: Any exceptions that are thrown from within the {@code listener} are ignored. To provide an alternative |
| 189 | + * result for a failed execution, use a {@link Fallback}.</p> |
| 190 | + */ |
175 | 191 | public RetryPolicyBuilder<R> onRetriesExceeded(EventListener<ExecutionCompletedEvent<R>> listener) { |
176 | 192 | config.retriesExceededListener = Assert.notNull(listener, "listener"); |
177 | 193 | return this; |
178 | 194 | } |
179 | 195 |
|
180 | | - @Override |
| 196 | + /** |
| 197 | + * Registers the {@code listener} to be called when a retry is about to be attempted. |
| 198 | + * <p>Note: Any exceptions that are thrown from within the {@code listener} are ignored. To provide an alternative |
| 199 | + * result for a failed execution, use a {@link Fallback}.</p> |
| 200 | + * |
| 201 | + * @see #onRetryScheduled(EventListener) |
| 202 | + */ |
181 | 203 | public RetryPolicyBuilder<R> onRetry(EventListener<ExecutionAttemptedEvent<R>> listener) { |
182 | 204 | config.retryListener = Assert.notNull(listener, "listener"); |
183 | 205 | return this; |
184 | 206 | } |
185 | 207 |
|
186 | | - @Override |
| 208 | + /** |
| 209 | + * Registers the {@code listener} to be called when a retry for an async call is about to be scheduled. This method |
| 210 | + * differs from {@link #onRetry(EventListener)} since it is called when a retry is initially scheduled but before any |
| 211 | + * configured delay, whereas {@link #onRetry(EventListener) onRetry} is called after a delay, just before the retry |
| 212 | + * attempt takes place. |
| 213 | + * <p> |
| 214 | + * <p>Note: Any exceptions that are thrown from within the {@code listener} are ignored. To provide an alternative |
| 215 | + * result for a failed execution, use a {@link Fallback}.</p> |
| 216 | + * |
| 217 | + * @see #onRetry(EventListener) |
| 218 | + */ |
187 | 219 | public RetryPolicyBuilder<R> onRetryScheduled(EventListener<ExecutionScheduledEvent<R>> listener) { |
188 | 220 | config.retryScheduledListener = Assert.notNull(listener, "listener"); |
189 | 221 | return this; |
|
0 commit comments