EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.step.item]

COVERAGE SUMMARY FOR SOURCE FILE [FaultTolerantChunkProvider.java]

nameclass, %method, %block, %line, %
FaultTolerantChunkProvider.java100% (1/1)100% (5/5)100% (92/92)100% (23/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FaultTolerantChunkProvider100% (1/1)100% (5/5)100% (92/92)100% (23/23)
FaultTolerantChunkProvider (ItemReader, RepeatOperations): void 100% (1/1)100% (17/17)100% (4/4)
postProcess (StepContribution, Chunk): void 100% (1/1)100% (26/26)100% (5/5)
read (StepContribution, Chunk): Object 100% (1/1)100% (41/41)100% (10/10)
setRollbackClassifier (Classifier): void 100% (1/1)100% (4/4)100% (2/2)
setSkipPolicy (SkipPolicy): void 100% (1/1)100% (4/4)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.core.step.item;
18 
19import org.springframework.batch.classify.BinaryExceptionClassifier;
20import org.springframework.batch.classify.Classifier;
21import org.springframework.batch.core.StepContribution;
22import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
23import org.springframework.batch.core.step.skip.NonSkippableReadException;
24import org.springframework.batch.core.step.skip.SkipListenerFailedException;
25import org.springframework.batch.core.step.skip.SkipPolicy;
26import org.springframework.batch.item.ItemReader;
27import org.springframework.batch.repeat.RepeatOperations;
28 
29/**
30 * FaultTolerant implementation of the {@link ChunkProcessor} interface, that
31 * allows for skipping or retry of items that cause exceptions during reading or
32 * processing.
33 * 
34 */
35public class FaultTolerantChunkProvider<I> extends SimpleChunkProvider<I> {
36 
37        private SkipPolicy skipPolicy = new LimitCheckingItemSkipPolicy(0);
38 
39        private Classifier<Throwable, Boolean> rollbackClassifier = new BinaryExceptionClassifier(true);
40 
41        public FaultTolerantChunkProvider(ItemReader<? extends I> itemReader, RepeatOperations repeatOperations) {
42                super(itemReader, repeatOperations);
43        }
44 
45        /**
46         * The policy that determines whether exceptions can be skipped on read.
47         * @param SkipPolicy
48         */
49        public void setSkipPolicy(SkipPolicy SkipPolicy) {
50                this.skipPolicy = SkipPolicy;
51        }
52 
53        /**
54         * Classifier to determine whether exceptions have been marked as
55         * no-rollback (as opposed to skippable). If ecnounterd they are simply
56         * ignored, unless also skippable.
57         * 
58         * @param rollbackClassifier the rollback classifier to set
59         */
60        public void setRollbackClassifier(Classifier<Throwable, Boolean> rollbackClassifier) {
61                this.rollbackClassifier = rollbackClassifier;
62        }
63 
64        @Override
65        protected I read(StepContribution contribution, Chunk<I> chunk) throws Exception {
66                while (true) {
67                        try {
68                                return doRead();
69                        }
70                        catch (Exception e) {
71 
72                                if (skipPolicy.shouldSkip(e, contribution.getStepSkipCount())) {
73                                        // increment skip count and try again
74                                        contribution.incrementReadSkipCount();
75                                        chunk.skip(e);
76 
77                                        logger.debug("Skipping failed input", e);
78                                }
79                                else {
80                                        if (rollbackClassifier.classify(e)) {
81                                                throw new NonSkippableReadException("Non-skippable exception during read", e);
82                                        }
83                                        logger.debug("No-rollback for non-skippable exception (ignored)", e);
84                                }
85 
86                        }
87                }
88        }
89 
90        @Override
91        public void postProcess(StepContribution contribution, Chunk<I> chunk) {
92                for (Exception e : chunk.getErrors()) {
93                        try {
94                                getListener().onSkipInRead(e);
95                        }
96                        catch (RuntimeException ex) {
97                                throw new SkipListenerFailedException("Fatal exception in SkipListener.", ex, e);
98                        }
99                }
100        }
101 
102}

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