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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.cluster.common.actor.CommonConfig;
15 import scala.concurrent.duration.FiniteDuration;
17 public class RemoteRpcProviderConfig extends CommonConfig {
19 protected static final String TAG_RPC_BROKER_NAME = "rpc-broker-name";
20 protected static final String TAG_RPC_REGISTRAR_NAME = "rpc-registrar-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";
28 private static final String TAG_GOSSIP_TICK_INTERVAL = "gossip-tick-interval";
29 private static final String TAG_RPC_REGISTRY_PERSISTENCE_ID = "rpc-registry-persistence-id";
31 //locally cached values
32 private Timeout cachedAskDuration;
33 private FiniteDuration cachedGossipTickInterval;
35 public RemoteRpcProviderConfig(final Config config) {
39 public String getRpcBrokerName() {
40 return get().getString(TAG_RPC_BROKER_NAME);
43 public String getRpcRegistrarName() {
44 return get().getString(TAG_RPC_REGISTRAR_NAME);
47 public String getRpcRegistryName() {
48 return get().getString(TAG_RPC_REGISTRY_NAME);
51 public String getRpcManagerName() {
52 return get().getString(TAG_RPC_MGR_NAME);
55 public String getRpcBrokerPath() {
56 return get().getString(TAG_RPC_BROKER_PATH);
59 public String getRpcRegistryPath() {
60 return get().getString(TAG_RPC_REGISTRY_PATH);
63 public String getRpcRegistryPersistenceId() {
64 return get().getString(TAG_RPC_REGISTRY_PERSISTENCE_ID);
67 public String getRpcManagerPath() {
68 return get().getString(TAG_RPC_MGR_PATH);
71 public Timeout getAskDuration() {
72 if (cachedAskDuration != null) {
73 return cachedAskDuration;
76 cachedAskDuration = new Timeout(new FiniteDuration(
77 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
79 return cachedAskDuration;
82 public FiniteDuration getGossipTickInterval() {
83 if (cachedGossipTickInterval != null) {
84 return cachedGossipTickInterval;
87 cachedGossipTickInterval = new FiniteDuration(
88 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
90 return cachedGossipTickInterval;
94 * This is called via blueprint xml as the builder pattern can't be used.
96 @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
97 justification = "Findbugs flags this as an unconfirmed cast of return value but the build method clearly "
98 + "returns RemoteRpcProviderConfig. Perhaps it's confused b/c the build method is overloaded and "
99 + "and differs in return type from the base class.")
100 public static RemoteRpcProviderConfig newInstance(final String actorSystemName, final boolean metricCaptureEnabled,
101 final int mailboxCapacity) {
102 return new Builder(actorSystemName).metricCaptureEnabled(metricCaptureEnabled)
103 .mailboxCapacity(mailboxCapacity).build();
106 public static class Builder extends CommonConfig.Builder<Builder> {
108 public Builder(final String actorSystemName) {
109 super(actorSystemName);
112 configHolder.put(TAG_RPC_BROKER_NAME, "broker");
113 configHolder.put(TAG_RPC_REGISTRAR_NAME, "registrar");
114 configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
115 configHolder.put(TAG_RPC_MGR_NAME, "rpc");
118 configHolder.put(TAG_RPC_BROKER_PATH, "/user/rpc/broker");
119 configHolder.put(TAG_RPC_REGISTRY_PATH, "/user/rpc/registry");
120 configHolder.put(TAG_RPC_MGR_PATH, "/user/rpc");
123 configHolder.put(TAG_ASK_DURATION, "15s");
124 configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
127 configHolder.put(TAG_RPC_REGISTRY_PERSISTENCE_ID, "remote-rpc-registry");
130 public Builder gossipTickInterval(final String interval) {
131 configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
136 public RemoteRpcProviderConfig build() {
137 return new RemoteRpcProviderConfig(merge());