EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.listener]

COVERAGE SUMMARY FOR SOURCE FILE [CompositeChunkListener.java]

nameclass, %method, %block, %line, %
CompositeChunkListener.java100% (1/1)83%  (5/6)92%  (61/66)90%  (19/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeChunkListener100% (1/1)83%  (5/6)92%  (61/66)90%  (19/21)
setListeners (List): void 0%   (0/1)0%   (0/5)0%   (0/2)
CompositeChunkListener (): void 100% (1/1)100% (8/8)100% (2/2)
afterChunk (ChunkContext): void 100% (1/1)100% (16/16)100% (5/5)
afterChunkError (ChunkContext): void 100% (1/1)100% (16/16)100% (5/5)
beforeChunk (ChunkContext): void 100% (1/1)100% (16/16)100% (5/5)
register (ChunkListener): void 100% (1/1)100% (5/5)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 */
16package org.springframework.batch.core.listener;
17 
18import java.util.Iterator;
19import java.util.List;
20 
21import org.springframework.batch.core.ChunkListener;
22import org.springframework.batch.core.scope.context.ChunkContext;
23import org.springframework.core.Ordered;
24 
25/**
26 * @author Lucas Ward
27 *
28 */
29public class CompositeChunkListener implements ChunkListener {
30 
31        private OrderedComposite<ChunkListener> listeners = new OrderedComposite<ChunkListener>();
32 
33        /**
34         * Public setter for the listeners.
35         *
36         * @param listeners
37         */
38        public void setListeners(List<? extends ChunkListener> listeners) {
39                this.listeners.setItems(listeners);
40        }
41 
42        /**
43         * Register additional listener.
44         *
45         * @param chunkListener
46         */
47        public void register(ChunkListener chunkListener) {
48                listeners.add(chunkListener);
49        }
50 
51        /**
52         * Call the registered listeners in order, respecting and prioritizing those
53         * that implement {@link Ordered}.
54         *
55         * @see org.springframework.batch.core.ChunkListener#afterChunk(ChunkContext context)
56         */
57        @Override
58        public void afterChunk(ChunkContext context) {
59                for (Iterator<ChunkListener> iterator = listeners.iterator(); iterator.hasNext();) {
60                        ChunkListener listener = iterator.next();
61                        listener.afterChunk(context);
62                }
63        }
64 
65        /**
66         * Call the registered listeners in reverse order.
67         *
68         * @see org.springframework.batch.core.ChunkListener#beforeChunk(ChunkContext context)
69         */
70        @Override
71        public void beforeChunk(ChunkContext context) {
72                for (Iterator<ChunkListener> iterator = listeners.reverse(); iterator.hasNext();) {
73                        ChunkListener listener = iterator.next();
74                        listener.beforeChunk(context);
75                }
76        }
77 
78        @Override
79        public void afterChunkError(ChunkContext context) {
80                for (Iterator<ChunkListener> iterator = listeners.iterator(); iterator.hasNext();) {
81                        ChunkListener listener = iterator.next();
82                        listener.afterChunkError(context);
83                }
84        }
85}

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