EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.retry.policy]

COVERAGE SUMMARY FOR SOURCE FILE [NeverRetryPolicy.java]

nameclass, %method, %block, %line, %
NeverRetryPolicy.java100% (2/2)100% (8/8)100% (39/39)100% (14/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NeverRetryPolicy100% (1/1)100% (5/5)100% (25/25)100% (8/8)
NeverRetryPolicy (): void 100% (1/1)100% (3/3)100% (2/2)
canRetry (RetryContext): boolean 100% (1/1)100% (8/8)100% (1/1)
close (RetryContext): void 100% (1/1)100% (1/1)100% (1/1)
open (RetryContext): RetryContext 100% (1/1)100% (5/5)100% (1/1)
registerThrowable (RetryContext, Throwable): void 100% (1/1)100% (8/8)100% (3/3)
     
class NeverRetryPolicy$NeverRetryContext100% (1/1)100% (3/3)100% (14/14)100% (6/6)
NeverRetryPolicy$NeverRetryContext (RetryContext): void 100% (1/1)100% (7/7)100% (3/3)
isFinished (): boolean 100% (1/1)100% (3/3)100% (1/1)
setFinished (): void 100% (1/1)100% (4/4)100% (2/2)

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 
17package org.springframework.batch.retry.policy;
18 
19import org.springframework.batch.retry.RetryContext;
20import org.springframework.batch.retry.RetryPolicy;
21import org.springframework.batch.retry.context.RetryContextSupport;
22 
23/**
24 * A {@link RetryPolicy} that allows the first attempt but never permits a
25 * retry. Also be used as a base class for other policies, e.g. for test
26 * purposes as a stub.
27 * 
28 * @author Dave Syer
29 * 
30 */
31public class NeverRetryPolicy implements RetryPolicy {
32 
33        /**
34         * Returns false after the first exception. So there is always one try, and
35         * then the retry is prevented.
36         * 
37         * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext)
38         */
39        public boolean canRetry(RetryContext context) {
40                return !((NeverRetryContext) context).isFinished();
41        }
42 
43        /**
44         * Do nothing.
45         * 
46         * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
47         */
48        public void close(RetryContext context) {
49                // no-op
50        }
51 
52        /**
53         * Return a context that can respond to early termination requests, but does
54         * nothing else.
55         * 
56         * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext)
57         */
58        public RetryContext open(RetryContext parent) {
59                return new NeverRetryContext(parent);
60        }
61 
62        /**
63         * Make the throwable available for downstream use through the context.
64         * @see org.springframework.batch.retry.RetryPolicy#registerThrowable(org.springframework.batch.retry.RetryContext,
65         * Throwable)
66         */
67        public void registerThrowable(RetryContext context, Throwable throwable) {
68                ((NeverRetryContext) context).setFinished();
69                ((RetryContextSupport) context).registerThrowable(throwable);
70        }
71 
72        /**
73         * Special context object for {@link NeverRetryPolicy}. Implements a flag
74         * with a similar function to {@link RetryContext#isExhaustedOnly()}, but
75         * kept separate so that if subclasses of {@link NeverRetryPolicy} need to
76         * they can modify the behaviour of
77         * {@link NeverRetryPolicy#canRetry(RetryContext)} without affecting
78         * {@link RetryContext#isExhaustedOnly()}.
79         * 
80         * @author Dave Syer
81         * 
82         */
83        private static class NeverRetryContext extends RetryContextSupport {
84                private boolean finished = false;
85 
86                public NeverRetryContext(RetryContext parent) {
87                        super(parent);
88                }
89 
90                public boolean isFinished() {
91                        return finished;
92                }
93 
94                public void setFinished() {
95                        this.finished = true;
96                }
97        }
98 
99}

[all classes][org.springframework.batch.retry.policy]
EMMA 2.0.5312 (C) Vladimir Roubtsov