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

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