EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[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)100% (82/82)100% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

1/*
2 * Copyright 2006-2013 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        @Override
64        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
65 
66                @SuppressWarnings("unchecked")
67                Chunk<I> inputs = (Chunk<I>) chunkContext.getAttribute(INPUTS_KEY);
68                if (inputs == null) {
69                        inputs = chunkProvider.provide(contribution);
70                        if (buffering) {
71                                chunkContext.setAttribute(INPUTS_KEY, inputs);
72                        }
73                }
74 
75                chunkProcessor.process(contribution, inputs);
76                chunkProvider.postProcess(contribution, inputs);
77 
78                // Allow a message coming back from the processor to say that we
79                // are not done yet
80                if (inputs.isBusy()) {
81                        logger.debug("Inputs still busy");
82                        return RepeatStatus.CONTINUABLE;
83                }
84 
85                chunkContext.removeAttribute(INPUTS_KEY);
86                chunkContext.setComplete();
87 
88                logger.debug("Inputs not busy, ended: " + inputs.isEnd());
89                return RepeatStatus.continueIf(!inputs.isEnd());
90 
91        }
92 
93}

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