Bug 4866: Add wait/retries for routed RPCs
[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     public static class Builder extends CommonConfig.Builder<Builder>{
86
87         public Builder(String actorSystemName){
88             super(actorSystemName);
89
90             //Actor names
91             configHolder.put(TAG_RPC_BROKER_NAME, "broker");
92             configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
93             configHolder.put(TAG_RPC_MGR_NAME, "rpc");
94
95             //Actor paths
96             configHolder.put(TAG_RPC_BROKER_PATH, "/user/rpc/broker");
97             configHolder.put(TAG_RPC_REGISTRY_PATH, "/user/rpc/registry");
98             configHolder.put(TAG_RPC_MGR_PATH, "/user/rpc");
99
100             //durations
101             configHolder.put(TAG_ASK_DURATION, "15s");
102             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
103
104         }
105
106         public Builder gossipTickInterval(String interval) {
107             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
108             return this;
109         }
110
111         @Override
112         public RemoteRpcProviderConfig build(){
113             return new RemoteRpcProviderConfig(merge());
114         }
115     }
116
117
118 }