cb5097d24e40f5a73fd675835519b22c7957cec4
[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 java.util.concurrent.TimeUnit;
13 import org.opendaylight.controller.cluster.common.actor.CommonConfig;
14 import scala.concurrent.duration.FiniteDuration;
15
16 /**
17  */
18 public class RemoteRpcProviderConfig extends CommonConfig {
19
20     protected static final String TAG_RPC_BROKER_NAME = "rpc-broker-name";
21     protected static final String TAG_RPC_REGISTRY_NAME = "registry-name";
22     protected static final String TAG_RPC_MGR_NAME = "rpc-manager-name";
23     protected static final String TAG_RPC_BROKER_PATH = "rpc-broker-path";
24     protected static final String TAG_RPC_REGISTRY_PATH = "rpc-registry-path";
25     protected static final String TAG_RPC_MGR_PATH = "rpc-manager-path";
26     protected static final String TAG_ASK_DURATION = "ask-duration";
27     private static final String TAG_GOSSIP_TICK_INTERVAL = "gossip-tick-interval";
28
29     //locally cached values
30     private Timeout cachedAskDuration;
31     private FiniteDuration cachedGossipTickInterval;
32
33     public RemoteRpcProviderConfig(Config config){
34         super(config);
35     }
36
37     public String getRpcBrokerName(){
38         return get().getString(TAG_RPC_BROKER_NAME);
39     }
40
41     public String getRpcRegistryName(){
42         return get().getString(TAG_RPC_REGISTRY_NAME);
43     }
44
45     public String getRpcManagerName(){
46         return get().getString(TAG_RPC_MGR_NAME);
47     }
48
49     public String getRpcBrokerPath(){
50         return get().getString(TAG_RPC_BROKER_PATH);
51     }
52
53     public String getRpcRegistryPath(){
54         return get().getString(TAG_RPC_REGISTRY_PATH);
55
56     }
57
58     public String getRpcManagerPath(){
59         return get().getString(TAG_RPC_MGR_PATH);
60     }
61
62
63     public Timeout getAskDuration(){
64         if (cachedAskDuration != null){
65             return cachedAskDuration;
66         }
67
68         cachedAskDuration = new Timeout(new FiniteDuration(
69                 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
70
71         return cachedAskDuration;
72     }
73
74     public FiniteDuration getGossipTickInterval(){
75         if (cachedGossipTickInterval != null) {
76             return cachedGossipTickInterval;
77         }
78
79         cachedGossipTickInterval = new FiniteDuration(
80                 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
81
82         return cachedGossipTickInterval;
83     }
84
85     /**
86      * This is called via blueprint xml as the builder pattern can't be used.
87      */
88     public static RemoteRpcProviderConfig newInstance(String actorSystemName, boolean metricCaptureEnabled,
89             int mailboxCapacity) {
90         return new Builder(actorSystemName).metricCaptureEnabled(metricCaptureEnabled).
91                 mailboxCapacity(mailboxCapacity).build();
92     }
93
94     public static class Builder extends CommonConfig.Builder<Builder>{
95
96         public Builder(String actorSystemName){
97             super(actorSystemName);
98
99             //Actor names
100             configHolder.put(TAG_RPC_BROKER_NAME, "broker");
101             configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
102             configHolder.put(TAG_RPC_MGR_NAME, "rpc");
103
104             //Actor paths
105             configHolder.put(TAG_RPC_BROKER_PATH, "/user/rpc/broker");
106             configHolder.put(TAG_RPC_REGISTRY_PATH, "/user/rpc/registry");
107             configHolder.put(TAG_RPC_MGR_PATH, "/user/rpc");
108
109             //durations
110             configHolder.put(TAG_ASK_DURATION, "15s");
111             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
112
113         }
114
115         public Builder gossipTickInterval(String interval) {
116             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
117             return this;
118         }
119
120         @Override
121         public RemoteRpcProviderConfig build(){
122             return new RemoteRpcProviderConfig(merge());
123         }
124     }
125
126
127 }