EMMA Coverage Report (generated Tue May 06 07:28:24 PDT 2008)
[all classes][org.springframework.batch.repeat.policy]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleCompletionPolicy.java]

nameclass, %method, %block, %line, %
SimpleCompletionPolicy.java100% (2/2)100% (10/10)100% (64/64)100% (19/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleCompletionPolicy100% (1/1)100% (7/7)100% (44/44)100% (13/13)
SimpleCompletionPolicy (): void 100% (1/1)100% (4/4)100% (2/2)
SimpleCompletionPolicy (int): void 100% (1/1)100% (9/9)100% (4/4)
isComplete (RepeatContext): boolean 100% (1/1)100% (4/4)100% (1/1)
isComplete (RepeatContext, ExitStatus): boolean 100% (1/1)100% (13/13)100% (1/1)
setChunkSize (int): void 100% (1/1)100% (4/4)100% (2/2)
start (RepeatContext): RepeatContext 100% (1/1)100% (6/6)100% (1/1)
update (RepeatContext): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimpleCompletionPolicy$SimpleTerminationContext100% (1/1)100% (3/3)100% (20/20)100% (6/6)
SimpleCompletionPolicy$SimpleTerminationContext (SimpleCompletionPolicy, Repe... 100% (1/1)100% (7/7)100% (3/3)
isComplete (): boolean 100% (1/1)100% (10/10)100% (1/1)
update (): void 100% (1/1)100% (3/3)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.repeat.policy;
18 
19import org.springframework.batch.repeat.ExitStatus;
20import org.springframework.batch.repeat.RepeatContext;
21import org.springframework.batch.repeat.context.RepeatContextSupport;
22import org.springframework.batch.repeat.support.RepeatTemplate;
23 
24/**
25 * Policy for terminating a batch after a fixed number of operations. Internal
26 * state is maintained and a counter incremented, so successful use of this
27 * policy requires that isComplete() is only called once per batch item. Using
28 * the standard {@link RepeatTemplate} should ensure this contract is kept, but it needs
29 * to be carefully monitored.
30 * 
31 * @author Dave Syer
32 * 
33 */
34public class SimpleCompletionPolicy extends DefaultResultCompletionPolicy {
35 
36        public static final int DEFAULT_CHUNK_SIZE = 5;
37 
38        int chunkSize = 0;
39 
40        public SimpleCompletionPolicy() {
41                this(DEFAULT_CHUNK_SIZE);
42        }
43 
44        public SimpleCompletionPolicy(int chunkSize) {
45                super();
46                this.chunkSize = chunkSize;
47        }
48 
49        public void setChunkSize(int chunkSize) {
50                this.chunkSize = chunkSize;
51        }
52 
53        /**
54         * Reset the counter.
55         * 
56         * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext)
57         */
58        public RepeatContext start(RepeatContext context) {
59                return new SimpleTerminationContext(context);
60        }
61 
62        /**
63         * Terminate if the chunk size has been reached, or the result is null.
64         * 
65         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext,
66         * ExitStatus)
67         * @throws RuntimeException (normally terminating the batch) if the result is
68         * itself an exception.
69         */
70        public boolean isComplete(RepeatContext context, ExitStatus result) {
71                return super.isComplete(context, result) || ((SimpleTerminationContext) context).isComplete();
72        }
73 
74        /**
75         * Terminate if the chunk size has been reached.
76         * 
77         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext)
78         */
79        public boolean isComplete(RepeatContext context) {
80                return ((SimpleTerminationContext) context).isComplete();
81        }
82 
83        /**
84         * Increment the counter in the context.
85         * 
86         * @see org.springframework.batch.repeat.CompletionPolicy#update(RepeatContext)
87         */
88        public void update(RepeatContext context) {
89                ((SimpleTerminationContext) context).update();
90        }
91 
92        protected class SimpleTerminationContext extends RepeatContextSupport {
93 
94                public SimpleTerminationContext(RepeatContext context) {
95                        super(context);
96                }
97 
98                public void update() {
99                        increment();
100                }
101 
102                public boolean isComplete() {
103                        return getStartedCount() >= chunkSize;
104                }
105        }
106 
107}

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