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

COVERAGE SUMMARY FOR SOURCE FILE [ChunkOrientedTasklet.java]

nameclass, %method, %block, %line, %
ChunkOrientedTasklet.java100% (1/1)100% (4/4)94%  (77/82)91%  (20/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ChunkOrientedTasklet100% (1/1)100% (4/4)94%  (77/82)91%  (20/22)
execute (StepContribution, ChunkContext): RepeatStatus 100% (1/1)92%  (57/62)86%  (12/14)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ChunkOrientedTasklet (ChunkProvider, ChunkProcessor): void 100% (1/1)100% (12/12)100% (5/5)
setBuffering (boolean): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2006-2009 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.core.step.item;
18 
19import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogFactory;
21import org.springframework.batch.core.StepContribution;
22import org.springframework.batch.core.scope.context.ChunkContext;
23import org.springframework.batch.core.step.tasklet.Tasklet;
24import org.springframework.batch.repeat.RepeatStatus;
25 
26/**
27 * A {@link Tasklet} implementing variations on read-process-write item
28 * handling.
29 * 
30 * @author Dave Syer
31 * 
32 * @param <I> input item type
33 */
34public class ChunkOrientedTasklet<I> implements Tasklet {
35 
36        private static final String INPUTS_KEY = "INPUTS";
37 
38        private final ChunkProcessor<I> chunkProcessor;
39 
40        private final ChunkProvider<I> chunkProvider;
41 
42        private boolean buffering = true;
43 
44        private static Log logger = LogFactory.getLog(ChunkOrientedTasklet.class);
45 
46        public ChunkOrientedTasklet(ChunkProvider<I> chunkProvider, ChunkProcessor<I> chunkProcessor) {
47                this.chunkProvider = chunkProvider;
48                this.chunkProcessor = chunkProcessor;
49        }
50 
51        /**
52         * Flag to indicate that items should be buffered once read. Defaults to
53         * true, which is appropriate for forward-only, non-transactional item
54         * readers. Main (or only) use case for setting this flag to false is a
55         * transactional JMS item reader.
56         * 
57         * @param buffering
58         */
59        public void setBuffering(boolean buffering) {
60                this.buffering = buffering;
61        }
62 
63        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
64 
65                @SuppressWarnings("unchecked")
66                Chunk<I> inputs = (Chunk<I>) chunkContext.getAttribute(INPUTS_KEY);
67                if (inputs == null) {
68                        inputs = chunkProvider.provide(contribution);
69                        if (buffering) {
70                                chunkContext.setAttribute(INPUTS_KEY, inputs);
71                        }
72                }
73 
74                chunkProcessor.process(contribution, inputs);
75                chunkProvider.postProcess(contribution, inputs);
76 
77                // Allow a message coming back from the processor to say that we
78                // are not done yet
79                if (inputs.isBusy()) {
80                        logger.debug("Inputs still busy");
81                        return RepeatStatus.CONTINUABLE;
82                }
83 
84                chunkContext.removeAttribute(INPUTS_KEY);
85                chunkContext.setComplete();
86 
87                logger.debug("Inputs not busy, ended: " + inputs.isEnd());
88                return RepeatStatus.continueIf(!inputs.isEnd());
89 
90        }
91 
92}

[all classes][org.springframework.batch.core.step.item]
EMMA 2.0.5312 (C) Vladimir Roubtsov