3f6d42d7422fd3d06d71e921cbf691d43dd1ed8a
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteRpcProviderConfig.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.remote.rpc;
9
10 import akka.util.Timeout;
11 import com.typesafe.config.Config;
12 import org.opendaylight.controller.cluster.common.actor.CommonConfig;
13 import scala.concurrent.duration.FiniteDuration;
14
15 import java.util.concurrent.TimeUnit;
16
17 /**
18  */
19 public class RemoteRpcProviderConfig extends CommonConfig {
20
21     protected static final String TAG_RPC_BROKER_NAME = "rpc-broker-name";
22     protected static final String TAG_RPC_REGISTRY_NAME = "registry-name";
23     protected static final String TAG_RPC_MGR_NAME = "rpc-manager-name";
24     protected static final String TAG_RPC_BROKER_PATH = "rpc-broker-path";
25     protected static final String TAG_RPC_REGISTRY_PATH = "rpc-registry-path";
26     protected static final String TAG_RPC_MGR_PATH = "rpc-manager-path";
27     protected static final String TAG_ASK_DURATION = "ask-duration";
28     private static final String TAG_GOSSIP_TICK_INTERVAL = "gossip-tick-interval";
29
30     //locally cached values
31     private Timeout cachedAskDuration;
32     private FiniteDuration cachedGossipTickInterval;
33
34     public RemoteRpcProviderConfig(Config config){
35         super(config);
36     }
37
38     public String getRpcBrokerName(){
39         return get().getString(TAG_RPC_BROKER_NAME);
40     }
41
42     public String getRpcRegistryName(){
43         return get().getString(TAG_RPC_REGISTRY_NAME);
44     }
45
46     public String getRpcManagerName(){
47         return get().getString(TAG_RPC_MGR_NAME);
48     }
49
50     public String getRpcBrokerPath(){
51         return get().getString(TAG_RPC_BROKER_PATH);
52     }
53
54     public String getRpcRegistryPath(){
55         return get().getString(TAG_RPC_REGISTRY_PATH);
56
57     }
58
59     public String getRpcManagerPath(){
60         return get().getString(TAG_RPC_MGR_PATH);
61     }
62
63
64     public Timeout getAskDuration(){
65         if (cachedAskDuration != null){
66             return cachedAskDuration;
67         }
68
69         cachedAskDuration = new Timeout(new FiniteDuration(
70                 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
71
72         return cachedAskDuration;
73     }
74
75     public FiniteDuration getGossipTickInterval(){
76         if (cachedGossipTickInterval != null) {
77             return cachedGossipTickInterval;
78         }
79
80         cachedGossipTickInterval = new FiniteDuration(
81                 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
82
83         return cachedGossipTickInterval;
84     }
85
86     public static class Builder extends CommonConfig.Builder<Builder>{
87
88         public Builder(String actorSystemName){
89             super(actorSystemName);
90
91             //Actor names
92             configHolder.put(TAG_RPC_BROKER_NAME, "broker");
93             configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
94             configHolder.put(TAG_RPC_MGR_NAME, "rpc");
95
96             //Actor paths
97             configHolder.put(TAG_RPC_BROKER_PATH, "/user/rpc/broker");
98             configHolder.put(TAG_RPC_REGISTRY_PATH, "/user/rpc/registry");
99             configHolder.put(TAG_RPC_MGR_PATH, "/user/rpc");
100
101             //durations
102             configHolder.put(TAG_ASK_DURATION, "15s");
103             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
104
105         }
106
107         public RemoteRpcProviderConfig build(){
108             return new RemoteRpcProviderConfig(merge());
109         }
110     }
111
112
113 }