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 java.util.concurrent.TimeUnit;
13 import org.opendaylight.controller.cluster.common.actor.CommonConfig;
14 import scala.concurrent.duration.FiniteDuration;
18 public class RemoteRpcProviderConfig extends CommonConfig {
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";
29 //locally cached values
30 private Timeout cachedAskDuration;
31 private FiniteDuration cachedGossipTickInterval;
33 public RemoteRpcProviderConfig(Config config){
37 public String getRpcBrokerName(){
38 return get().getString(TAG_RPC_BROKER_NAME);
41 public String getRpcRegistryName(){
42 return get().getString(TAG_RPC_REGISTRY_NAME);
45 public String getRpcManagerName(){
46 return get().getString(TAG_RPC_MGR_NAME);
49 public String getRpcBrokerPath(){
50 return get().getString(TAG_RPC_BROKER_PATH);
53 public String getRpcRegistryPath(){
54 return get().getString(TAG_RPC_REGISTRY_PATH);
58 public String getRpcManagerPath(){
59 return get().getString(TAG_RPC_MGR_PATH);
63 public Timeout getAskDuration(){
64 if (cachedAskDuration != null){
65 return cachedAskDuration;
68 cachedAskDuration = new Timeout(new FiniteDuration(
69 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
71 return cachedAskDuration;
74 public FiniteDuration getGossipTickInterval(){
75 if (cachedGossipTickInterval != null) {
76 return cachedGossipTickInterval;
79 cachedGossipTickInterval = new FiniteDuration(
80 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
82 return cachedGossipTickInterval;
86 * This is called via blueprint xml as the builder pattern can't be used.
88 public static RemoteRpcProviderConfig newInstance(String actorSystemName, boolean metricCaptureEnabled,
89 int mailboxCapacity) {
90 return new Builder(actorSystemName).metricCaptureEnabled(metricCaptureEnabled).
91 mailboxCapacity(mailboxCapacity).build();
94 public static class Builder extends CommonConfig.Builder<Builder>{
96 public Builder(String actorSystemName){
97 super(actorSystemName);
100 configHolder.put(TAG_RPC_BROKER_NAME, "broker");
101 configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
102 configHolder.put(TAG_RPC_MGR_NAME, "rpc");
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");
110 configHolder.put(TAG_ASK_DURATION, "15s");
111 configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
115 public Builder gossipTickInterval(String interval) {
116 configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
121 public RemoteRpcProviderConfig build(){
122 return new RemoteRpcProviderConfig(merge());