Add support for reusable streaming
[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 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;
16
17 public class RemoteRpcProviderConfig extends CommonConfig {
18
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";
27
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";
30
31     //locally cached values
32     private Timeout cachedAskDuration;
33     private FiniteDuration cachedGossipTickInterval;
34
35     public RemoteRpcProviderConfig(final Config config) {
36         super(config);
37     }
38
39     public String getRpcBrokerName() {
40         return get().getString(TAG_RPC_BROKER_NAME);
41     }
42
43     public String getRpcRegistrarName() {
44         return get().getString(TAG_RPC_REGISTRAR_NAME);
45     }
46
47     public String getRpcRegistryName() {
48         return get().getString(TAG_RPC_REGISTRY_NAME);
49     }
50
51     public String getRpcManagerName() {
52         return get().getString(TAG_RPC_MGR_NAME);
53     }
54
55     public String getRpcBrokerPath() {
56         return get().getString(TAG_RPC_BROKER_PATH);
57     }
58
59     public String getRpcRegistryPath() {
60         return get().getString(TAG_RPC_REGISTRY_PATH);
61     }
62
63     public String getRpcRegistryPersistenceId() {
64         return get().getString(TAG_RPC_REGISTRY_PERSISTENCE_ID);
65     }
66
67     public String getRpcManagerPath() {
68         return get().getString(TAG_RPC_MGR_PATH);
69     }
70
71     public Timeout getAskDuration() {
72         if (cachedAskDuration != null) {
73             return cachedAskDuration;
74         }
75
76         cachedAskDuration = new Timeout(new FiniteDuration(
77                 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
78
79         return cachedAskDuration;
80     }
81
82     public FiniteDuration getGossipTickInterval() {
83         if (cachedGossipTickInterval != null) {
84             return cachedGossipTickInterval;
85         }
86
87         cachedGossipTickInterval = new FiniteDuration(
88                 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
89
90         return cachedGossipTickInterval;
91     }
92
93     /**
94      * This is called via blueprint xml as the builder pattern can't be used.
95      */
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();
104     }
105
106     public static class Builder extends CommonConfig.Builder<Builder> {
107
108         public Builder(final String actorSystemName) {
109             super(actorSystemName);
110
111             //Actor names
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");
116
117             //Actor paths
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");
121
122             //durations
123             configHolder.put(TAG_ASK_DURATION, "15s");
124             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
125
126             // persistence
127             configHolder.put(TAG_RPC_REGISTRY_PERSISTENCE_ID, "remote-rpc-registry");
128         }
129
130         public Builder gossipTickInterval(final String interval) {
131             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
132             return this;
133         }
134
135         @Override
136         public RemoteRpcProviderConfig build() {
137             return new RemoteRpcProviderConfig(merge());
138         }
139     }
140 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.