Merge "Add missing copyright text"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractConfig.java
1 package org.opendaylight.controller.cluster.common.actor;
2
3 import com.google.common.base.Preconditions;
4 import com.typesafe.config.Config;
5 import com.typesafe.config.ConfigFactory;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10 public abstract class AbstractConfig implements UnifiedConfig {
11
12     private Config config;
13
14     public AbstractConfig(Config config){
15         this.config = config;
16     }
17
18     @Override
19     public Config get() {
20         return config;
21     }
22
23     public static abstract class Builder<T extends Builder<T>> {
24         protected Map<String, Object> configHolder;
25         protected Config fallback;
26
27         private final String actorSystemName;
28
29         public Builder(String actorSystemName){
30             Preconditions.checkArgument(actorSystemName != null, "Actor system name must not be null");
31             this.actorSystemName = actorSystemName;
32             configHolder = new HashMap<>();
33         }
34
35         public T withConfigReader(AkkaConfigurationReader reader){
36             fallback = reader.read().getConfig(actorSystemName);
37             return (T)this;
38         }
39
40         protected Config merge(){
41             if (fallback == null)
42                 fallback = ConfigFactory.load().getConfig(actorSystemName);
43
44             return ConfigFactory.parseMap(configHolder).withFallback(fallback);
45         }
46     }
47 }