2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.remote.rpc;
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;
15 import java.util.concurrent.TimeUnit;
19 public class RemoteRpcProviderConfig extends CommonConfig {
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";
30 //locally cached values
31 private Timeout cachedAskDuration;
32 private FiniteDuration cachedGossipTickInterval;
34 public RemoteRpcProviderConfig(Config config){
38 public String getRpcBrokerName(){
39 return get().getString(TAG_RPC_BROKER_NAME);
42 public String getRpcRegistryName(){
43 return get().getString(TAG_RPC_REGISTRY_NAME);
46 public String getRpcManagerName(){
47 return get().getString(TAG_RPC_MGR_NAME);
50 public String getRpcBrokerPath(){
51 return get().getString(TAG_RPC_BROKER_PATH);
54 public String getRpcRegistryPath(){
55 return get().getString(TAG_RPC_REGISTRY_PATH);
59 public String getRpcManagerPath(){
60 return get().getString(TAG_RPC_MGR_PATH);
64 public Timeout getAskDuration(){
65 if (cachedAskDuration != null){
66 return cachedAskDuration;
69 cachedAskDuration = new Timeout(new FiniteDuration(
70 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
72 return cachedAskDuration;
75 public FiniteDuration getGossipTickInterval(){
76 if (cachedGossipTickInterval != null) {
77 return cachedGossipTickInterval;
80 cachedGossipTickInterval = new FiniteDuration(
81 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
83 return cachedGossipTickInterval;
86 public static class Builder extends CommonConfig.Builder<Builder>{
88 public Builder(String actorSystemName){
89 super(actorSystemName);
92 configHolder.put(TAG_RPC_BROKER_NAME, "broker");
93 configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
94 configHolder.put(TAG_RPC_MGR_NAME, "rpc");
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");
102 configHolder.put(TAG_ASK_DURATION, "15s");
103 configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
107 public RemoteRpcProviderConfig build(){
108 return new RemoteRpcProviderConfig(merge());