Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractConfig.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.common.actor;
10
11 import com.google.common.base.Preconditions;
12 import com.typesafe.config.Config;
13 import com.typesafe.config.ConfigFactory;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 public abstract class AbstractConfig implements UnifiedConfig {
18
19     private final Config config;
20
21     public AbstractConfig(Config config) {
22         this.config = config;
23     }
24
25     @Override
26     public Config get() {
27         return config;
28     }
29
30     public abstract static class Builder<T extends Builder<T>> {
31         protected Map<String, Object> configHolder;
32         protected Config fallback;
33
34         private final String actorSystemName;
35
36         public Builder(String actorSystemName) {
37             Preconditions.checkArgument(actorSystemName != null, "Actor system name must not be null");
38             this.actorSystemName = actorSystemName;
39             configHolder = new HashMap<>();
40         }
41
42         @SuppressWarnings("unchecked")
43         public T withConfigReader(AkkaConfigurationReader reader) {
44             fallback = reader.read().getConfig(actorSystemName);
45             return (T)this;
46         }
47
48         protected Config merge() {
49             Config config = ConfigFactory.parseMap(configHolder);
50             if (fallback != null) {
51                 config = config.withFallback(fallback);
52             }
53
54             return config;
55         }
56     }
57 }