Parameterize exception type in RetryCallback

So RetryCallback<T, E extends Throwable> and the E parameter appears
in RetryOperations too, making it possible to call it with an unchecked
exception type in the parameter and not catch exceptions.

Users should beware: it's just syntactic sugar, and the actual runtime
type of the exception is never checked at runtime. So, for instance,
declaring a RetryCallback<Object,IllegalArgumentException> doesn't
mean that other Exceptions won't be retried, just that you won't be
able to explicitly throw them if they are checked.

A project using Spring Batch 2.2 was used to test that this works
with user code that uses a library compiled agains Spring Retry 1.0.

Fixes gh-6
This commit is contained in:
Dave Syer
2014-04-24 12:10:40 +01:00
parent 9fb92bccbd
commit 5fc484df58
14 changed files with 149 additions and 105 deletions

View File

@@ -23,7 +23,7 @@ package org.springframework.retry;
* @author Rob Harrop
* @author Dave Syer
*/
public interface RetryCallback<T> {
public interface RetryCallback<T, E extends Throwable> {
/**
* Execute an operation with retry semantics. Operations should generally be
@@ -33,5 +33,5 @@ public interface RetryCallback<T> {
* @return the result of the successful operation.
* @throws Exception if processing fails
*/
T doWithRetry(RetryContext context) throws Throwable;
T doWithRetry(RetryContext context) throws E;
}