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

COVERAGE SUMMARY FOR SOURCE FILE [MapJobRegistry.java]

nameclass, %method, %block, %line, %
MapJobRegistry.java100% (1/1)100% (5/5)100% (79/79)100% (17/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapJobRegistry100% (1/1)100% (5/5)100% (79/79)100% (17/17)
MapJobRegistry (): void 100% (1/1)100% (8/8)100% (2/2)
getJob (String): Job 100% (1/1)100% (25/25)100% (4/4)
getJobNames (): Set 100% (1/1)100% (5/5)100% (1/1)
register (JobFactory): void 100% (1/1)100% (32/32)100% (7/7)
unregister (String): void 100% (1/1)100% (9/9)100% (3/3)

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.configuration.support;
17 
18import java.util.Collections;
19import java.util.Set;
20import java.util.concurrent.ConcurrentHashMap;
21import java.util.concurrent.ConcurrentMap;
22 
23import org.springframework.batch.core.Job;
24import org.springframework.batch.core.configuration.DuplicateJobException;
25import org.springframework.batch.core.configuration.JobFactory;
26import org.springframework.batch.core.configuration.JobRegistry;
27import org.springframework.batch.core.launch.NoSuchJobException;
28import org.springframework.util.Assert;
29 
30/**
31 * Simple, thread-safe, map-based implementation of {@link JobRegistry}.
32 *
33 * @author Dave Syer
34 * @author Robert Fischer
35 */
36public class MapJobRegistry implements JobRegistry {
37 
38        /**
39         * The map holding the registered job factories.
40         */
41        // The "final" ensures that it is visible and initialized when the constructor resolves.
42        private final ConcurrentMap<String, JobFactory> map = new ConcurrentHashMap<String, JobFactory>();
43 
44        @Override
45        public void register(JobFactory jobFactory) throws DuplicateJobException {
46                Assert.notNull(jobFactory);
47                String name = jobFactory.getJobName();
48                Assert.notNull(name, "Job configuration must have a name.");
49                JobFactory previousValue = map.putIfAbsent(name, jobFactory);
50                if (previousValue != null) {
51                        throw new DuplicateJobException("A job configuration with this name [" + name
52                                        + "] was already registered");
53                }
54        }
55 
56        @Override
57        public void unregister(String name) {
58                Assert.notNull(name, "Job configuration must have a name.");
59                map.remove(name);
60        }
61 
62        @Override
63        public Job getJob(String name) throws NoSuchJobException {
64                JobFactory factory = map.get(name);
65                if (factory == null) {
66                        throw new NoSuchJobException("No job configuration with the name [" + name + "] was registered");
67                } else {
68                        return factory.createJob();
69                }
70        }
71 
72        /**
73         * Provides an unmodifiable view of the job names.
74         */
75        @Override
76        public Set<String> getJobNames() {
77                return Collections.unmodifiableSet(map.keySet());
78        }
79 
80}

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