1 /*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.retry;
18
19
20 /**
21 * Interface for listener that can be used to add behaviour to a retry.
22 * Implementations of {@link RetryOperations} can chose to issue callbacks to an
23 * interceptor during the retry lifecycle.
24 *
25 * @author Dave Syer
26 *
27 */
28 public interface RetryListener {
29
30 /**
31 * Called before the first attempt in a retry. For instance, implementers
32 * can set up state that is needed by the policies in the
33 * {@link RetryOperations}. The whole retry can be vetoed by returning
34 * false from this method, in which case a {@link TerminatedRetryException}
35 * will be thrown.
36 *
37 * @param <T> the type of object returned by the callback
38 * @param <E> the type of exception it declares may be thrown
39 * @param context the current {@link RetryContext}.
40 * @param callback the current {@link RetryCallback}.
41 * @return true if the retry should proceed.
42 */
43 <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback);
44
45 /**
46 * Called after the final attempt (successful or not). Allow the interceptor
47 * to clean up any resource it is holding before control returns to the
48 * retry caller.
49 *
50 * @param context the current {@link RetryContext}.
51 * @param callback the current {@link RetryCallback}.
52 * @param throwable the last exception that was thrown by the callback.
53 * @param <E> the exception type
54 * @param <T> the return value
55 */
56 <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable);
57
58 /**
59 * Called after every unsuccessful attempt at a retry.
60 *
61 * @param context the current {@link RetryContext}.
62 * @param callback the current {@link RetryCallback}.
63 * @param throwable the last exception that was thrown by the callback.
64 * @param <T> the return value
65 * @param <E> the exception to throw
66 */
67 <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable);
68 }
69