EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.repeat.policy]

COVERAGE SUMMARY FOR SOURCE FILE [TimeoutTerminationPolicy.java]

nameclass, %method, %block, %line, %
TimeoutTerminationPolicy.java100% (2/2)100% (6/6)100% (52/52)100% (14/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TimeoutTerminationPolicy100% (1/1)100% (4/4)100% (25/25)100% (8/8)
TimeoutTerminationPolicy (): void 100% (1/1)100% (6/6)100% (3/3)
TimeoutTerminationPolicy (long): void 100% (1/1)100% (9/9)100% (4/4)
isComplete (RepeatContext): boolean 100% (1/1)100% (4/4)100% (1/1)
start (RepeatContext): RepeatContext 100% (1/1)100% (6/6)100% (1/1)
     
class TimeoutTerminationPolicy$TimeoutBatchContext100% (1/1)100% (2/2)100% (27/27)100% (6/6)
TimeoutTerminationPolicy$TimeoutBatchContext (TimeoutTerminationPolicy, Repea... 100% (1/1)100% (15/15)100% (5/5)
isComplete (): 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.repeat.policy;
18 
19import org.springframework.batch.repeat.RepeatContext;
20import org.springframework.batch.repeat.context.RepeatContextSupport;
21 
22/**
23 * Termination policy that times out after a fixed period. Allows graceful exit
24 * from a batch if the latest result comes in after the timeout expires (i.e.
25 * does not throw a timeout exception).<br/>
26 * 
27 * N.B. It may often be the case that the batch governed by this policy will be
28 * transactional, and the transaction might have its own timeout. In this case
29 * the transaction might throw a timeout exception on commit if its timeout
30 * threshold is lower than the termination policy.
31 * 
32 * @author Dave Syer
33 * 
34 */
35public class TimeoutTerminationPolicy extends CompletionPolicySupport {
36 
37        /**
38         * Default timeout value in millisecs (the value equivalent to 30 seconds).
39         */
40        public static final long DEFAULT_TIMEOUT = 30000L;
41 
42        private long timeout = DEFAULT_TIMEOUT;
43 
44        /**
45         * Default constructor.
46         */
47        public TimeoutTerminationPolicy() {
48                super();
49        }
50 
51        /**
52         * Construct a {@link TimeoutTerminationPolicy} with the specified timeout
53         * value (in milliseconds).
54         * 
55         * @param timeout
56         */
57        public TimeoutTerminationPolicy(long timeout) {
58                super();
59                this.timeout = timeout;
60        }
61 
62        /**
63         * Check the timeout and complete gracefully if it has expires.
64         * 
65         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext)
66         */
67        public boolean isComplete(RepeatContext context) {
68                return ((TimeoutBatchContext) context).isComplete();
69        }
70 
71        /**
72         * Start the clock on the timeout.
73         * 
74         * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext)
75         */
76        public RepeatContext start(RepeatContext context) {
77                return new TimeoutBatchContext(context);
78        }
79 
80        protected class TimeoutBatchContext extends RepeatContextSupport {
81 
82                private volatile long time = System.currentTimeMillis();
83 
84                private final long timeout = TimeoutTerminationPolicy.this.timeout;
85 
86                public TimeoutBatchContext(RepeatContext context) {
87                        super(context);
88                }
89 
90                public boolean isComplete() {
91                        return (System.currentTimeMillis() - time) > timeout;
92                }
93 
94        }
95 
96}

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