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 | * http://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.batch.retry.policy; |
18 | |
19 | import org.springframework.batch.retry.ExhaustedRetryException; |
20 | import org.springframework.batch.retry.RetryContext; |
21 | import org.springframework.batch.retry.RetryPolicy; |
22 | |
23 | /** |
24 | * Base class for "normal" retry policies: those that operate in the context of |
25 | * a callback that is called repeatedly in a loop until it succeeds, or the |
26 | * policy decides to terminate. There is no need for such policies to store |
27 | * state outside the context. |
28 | * |
29 | * @see RetryPolicy#handleRetryExhausted(RetryContext) |
30 | * @see AbstractStatefulRetryPolicy |
31 | * |
32 | * @author Dave Syer |
33 | * |
34 | */ |
35 | public abstract class AbstractStatelessRetryPolicy implements RetryPolicy { |
36 | |
37 | /** |
38 | * Just returns the negative of {@link RetryPolicy#canRetry(RetryContext)}, |
39 | * i.e. if we cannot retry then the exception should be thrown. |
40 | * |
41 | * @see org.springframework.batch.retry.RetryPolicy#shouldRethrow(org.springframework.batch.retry.RetryContext) |
42 | */ |
43 | public boolean shouldRethrow(RetryContext context) { |
44 | return !canRetry(context); |
45 | } |
46 | |
47 | /** |
48 | * Throw an exception. |
49 | * |
50 | * @see org.springframework.batch.retry.RetryPolicy#handleRetryExhausted(org.springframework.batch.retry.RetryContext) |
51 | */ |
52 | public Object handleRetryExhausted(RetryContext context) throws Exception, ExhaustedRetryException { |
53 | throw new ExhaustedRetryException("Retry exhausted after last attempt with no recovery path.", context |
54 | .getLastThrowable()); |
55 | } |
56 | |
57 | } |