##### Coverage Report - com.ctrip.apollo.internals.DefaultConfigManager

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultConfigManager |
100% | 12/12
75% | 3/4
| 3.0;3

1 |  |
     package com.ctrip.apollo.internals;
2 |  |
3 |  |
     import com.google.common.collect.Maps;
4 |  |
5 |  |
     import com.ctrip.apollo.Config;
6 |  |
     import com.ctrip.apollo.spi.ConfigFactory;
7 |  |
     import com.ctrip.apollo.spi.ConfigFactoryManager;
8 |  |
9 |  |
     import org.unidal.lookup.annotation.Inject;
10 |  |
     import org.unidal.lookup.annotation.Named;
11 |  |
12 |  |
     import java.util.Map;
13 |  |
14 |  |
     /**
15 |  |
      * @author Jason Song(song_s@ctrip.com)
16 |  |
      */
17 |  |
     @Named(type = ConfigManager.class, value = "default")
18 | 13 |
     public class DefaultConfigManager implements ConfigManager {
19 |  |
       @Inject
20 |  |
       private ConfigFactoryManager m_factoryManager;
21 |  |
22 | 13 |
       private Map<String, Config> m_configs = Maps.newConcurrentMap();
23 |  |
24 |  |
       @Override
25 |  |
       public Config getConfig(String namespace) {
26 | 15 |
         Config config = m_configs.get(namespace);
27 |  |
28 | 15 |
         if (config == null) {
29 | 14 |
           synchronized (this) {
30 | 14 |
             config = m_configs.get(namespace);
31 |  |
32 | 14 |
             if (config == null) {
33 | 14 |
               ConfigFactory factory = m_factoryManager.getFactory(namespace);
34 |  |
35 | 14 |
               config = factory.create(namespace);
36 | 14 |
               m_configs.put(namespace, config);
37 |  |
             }
38 | 14 |
           }
39 |  |
         }
40 |  |
41 | 15 |
         return config;
42 |  |
       }
43 |  |
     }