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

COVERAGE SUMMARY FOR SOURCE FILE [TimeoutRetryPolicy.java]

nameclass, %method, %block, %line, %
TimeoutRetryPolicy.java100% (2/2)89%  (8/9)94%  (49/52)94%  (15/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TimeoutRetryPolicy100% (1/1)86%  (6/7)90%  (27/30)91%  (10/11)
getTimeout (): long 0%   (0/1)0%   (0/3)0%   (0/1)
TimeoutRetryPolicy (): void 100% (1/1)100% (6/6)100% (3/3)
canRetry (RetryContext): boolean 100% (1/1)100% (4/4)100% (1/1)
close (RetryContext): void 100% (1/1)100% (1/1)100% (1/1)
open (RetryContext): RetryContext 100% (1/1)100% (7/7)100% (1/1)
registerThrowable (RetryContext, Throwable): void 100% (1/1)100% (5/5)100% (2/2)
setTimeout (long): void 100% (1/1)100% (4/4)100% (2/2)
     
class TimeoutRetryPolicy$TimeoutRetryContext100% (1/1)100% (2/2)100% (22/22)100% (5/5)
TimeoutRetryPolicy$TimeoutRetryContext (RetryContext, long): void 100% (1/1)100% (10/10)100% (4/4)
isAlive (): boolean 100% (1/1)100% (12/12)100% (1/1)

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 a retry only if it hasn't timed out. The
25 * clock is started on a call to {@link #open(RetryContext)}.
26 * 
27 * @author Dave Syer
28 * 
29 */
30public class TimeoutRetryPolicy implements RetryPolicy {
31 
32        /**
33         * Default value for timeout (milliseconds).
34         */
35        public static final long DEFAULT_TIMEOUT = 1000;
36 
37        private long timeout = DEFAULT_TIMEOUT;
38 
39        /**
40         * Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
41         * @param timeout
42         */
43        public void setTimeout(long timeout) {
44                this.timeout = timeout;
45        }
46        
47        /**
48         * The value of the timeout.
49         * 
50         * @return the timeout in milliseconds
51         */
52        public long getTimeout() {
53                return timeout;
54        }
55 
56        /**
57         * Only permits a retry if the timeout has not expired. Does not check the
58         * exception at all.
59         * 
60         * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext)
61         */
62        public boolean canRetry(RetryContext context) {
63                return ((TimeoutRetryContext) context).isAlive();
64        }
65 
66        public void close(RetryContext context) {
67        }
68 
69        public RetryContext open(RetryContext parent) {
70                return new TimeoutRetryContext(parent, timeout);
71        }
72 
73        public void registerThrowable(RetryContext context, Throwable throwable) {
74                ((RetryContextSupport) context).registerThrowable(throwable);
75                // otherwise no-op - we only time out, otherwise retry everything...
76        }
77 
78        private static class TimeoutRetryContext extends RetryContextSupport {
79                private long timeout;
80 
81                private long start;
82 
83                public TimeoutRetryContext(RetryContext parent, long timeout) {
84                        super(parent);
85                        this.start = System.currentTimeMillis();
86                        this.timeout = timeout;
87                }
88 
89                public boolean isAlive() {
90                        return (System.currentTimeMillis() - start) <= timeout;
91                }
92        }
93 
94}

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