EMMA Coverage Report (generated Tue May 06 07:29:23 PDT 2008)
[all classes][org.springframework.batch.core.step.item]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleRetryExceptionHandler.java]

nameclass, %method, %block, %line, %
SimpleRetryExceptionHandler.java100% (1/1)100% (5/5)89%  (64/72)88%  (14.9/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleRetryExceptionHandler100% (1/1)100% (5/5)89%  (64/72)88%  (14.9/17)
handleException (RepeatContext, Throwable): void 100% (1/1)67%  (10/15)67%  (2/3)
getRepeatContext (): RepeatContext 100% (1/1)80%  (8/10)75%  (3/4)
<static initializer> 100% (1/1)94%  (17/18)94%  (0.9/1)
SimpleRetryExceptionHandler (RetryPolicy, ExceptionHandler, Class []): void 100% (1/1)100% (18/18)100% (6/6)
close (RetryContext, RetryCallback, Throwable): void 100% (1/1)100% (11/11)100% (3/3)

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 */
16package org.springframework.batch.core.step.item;
17 
18import org.springframework.batch.repeat.RepeatContext;
19import org.springframework.batch.repeat.exception.ExceptionHandler;
20import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
21import org.springframework.batch.retry.RetryCallback;
22import org.springframework.batch.retry.RetryContext;
23import org.springframework.batch.retry.RetryPolicy;
24import org.springframework.batch.retry.listener.RetryListenerSupport;
25import org.springframework.batch.support.BinaryExceptionClassifier;
26 
27/**
28 * @author Dave Syer
29 * 
30 */
31public class SimpleRetryExceptionHandler extends RetryListenerSupport implements ExceptionHandler {
32 
33        /**
34         * Attribute key, whose existence signals an exhausted retry.
35         */
36        private static final String EXHAUSTED = SimpleRetryExceptionHandler.class.getName() + ".RETRY_EXHAUSTED";
37 
38        final private RetryPolicy retryPolicy;
39 
40        final private ExceptionHandler exceptionHandler;
41 
42        final private BinaryExceptionClassifier fatalExceptionClassifier;
43 
44        /**
45         * @param retryPolicy
46         * @param exceptionHandler
47         * @param classes 
48         */
49        public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Class[] classes) {
50                this.retryPolicy = retryPolicy;
51                this.exceptionHandler = exceptionHandler;
52                this.fatalExceptionClassifier =  new BinaryExceptionClassifier();
53                fatalExceptionClassifier.setExceptionClasses(classes);
54        }
55 
56        /*
57         * (non-Javadoc)
58         * @see org.springframework.batch.repeat.exception.handler.ExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext,
59         * java.lang.Throwable)
60         */
61        public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
62                // Only bother to check the delegate exception handler if we know that
63                // retry is exhausted
64                if (!fatalExceptionClassifier.isDefault(throwable) || context.hasAttribute(EXHAUSTED)) {
65                        exceptionHandler.handleException(context, throwable);
66                }
67        }
68 
69        /*
70         * (non-Javadoc)
71         * @see org.springframework.batch.retry.RetryListener#close(org.springframework.batch.retry.RetryContext,
72         * org.springframework.batch.retry.RetryCallback, java.lang.Throwable)
73         */
74        public void close(RetryContext context, RetryCallback callback, Throwable throwable) {
75                if (!retryPolicy.canRetry(context)) {
76                        getRepeatContext().setAttribute(EXHAUSTED, "true");
77                }
78        }
79 
80        /**
81         * Get the parent context (the retry is in an inner "chunk" loop and we want
82         * the exception to be handled at the outer "step" level).
83         * @return the {@link RepeatContext} that should hold the exhausted flag.
84         */
85        private RepeatContext getRepeatContext() {
86                RepeatContext context = RepeatSynchronizationManager.getContext();
87                if (context.getParent() != null) {
88                        return context.getParent();
89                }
90                return context;
91        }
92 
93}

[all classes][org.springframework.batch.core.step.item]
EMMA 2.0.5312 (C) Vladimir Roubtsov