Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteOpsProviderConfig.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 RemoteOpsProviderConfig 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_ACTION_REGISTRY_NAME = "action-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_ACTION_REGISTRY_PATH = "action-registry-path";
27     protected static final String TAG_RPC_MGR_PATH = "rpc-manager-path";
28     protected static final String TAG_ASK_DURATION = "ask-duration";
29
30     private static final String TAG_GOSSIP_TICK_INTERVAL = "gossip-tick-interval";
31     private static final String TAG_RPC_REGISTRY_PERSISTENCE_ID = "rpc-registry-persistence-id";
32     private static final String TAG_ACTION_REGISTRY_PERSISTENCE_ID = "action-registry-persistence-id";
33
34     //locally cached values
35     private Timeout cachedAskDuration;
36     private FiniteDuration cachedGossipTickInterval;
37
38     public RemoteOpsProviderConfig(final Config config) {
39         super(config);
40     }
41
42     public String getRpcBrokerName() {
43         return get().getString(TAG_RPC_BROKER_NAME);
44     }
45
46     public String getRpcRegistrarName() {
47         return get().getString(TAG_RPC_REGISTRAR_NAME);
48     }
49
50     public String getRpcRegistryName() {
51         return get().getString(TAG_RPC_REGISTRY_NAME);
52     }
53
54     public String getActionRegistryName() {
55         return get().getString(TAG_ACTION_REGISTRY_NAME);
56     }
57
58     public String getRpcManagerName() {
59         return get().getString(TAG_RPC_MGR_NAME);
60     }
61
62     public String getRpcBrokerPath() {
63         return get().getString(TAG_RPC_BROKER_PATH);
64     }
65
66     public String getRpcRegistryPath() {
67         return get().getString(TAG_RPC_REGISTRY_PATH);
68     }
69
70     public String getRpcRegistryPersistenceId() {
71         return get().getString(TAG_RPC_REGISTRY_PERSISTENCE_ID);
72     }
73
74     public String getActionRegistryPath() {
75         return get().getString(TAG_ACTION_REGISTRY_PATH);
76     }
77
78     public String getActionRegistryPersistenceId() {
79         return get().getString(TAG_ACTION_REGISTRY_PERSISTENCE_ID);
80     }
81
82     public String getRpcManagerPath() {
83         return get().getString(TAG_RPC_MGR_PATH);
84     }
85
86     public Timeout getAskDuration() {
87         if (cachedAskDuration != null) {
88             return cachedAskDuration;
89         }
90
91         cachedAskDuration = new Timeout(new FiniteDuration(
92                 get().getDuration(TAG_ASK_DURATION, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS));
93
94         return cachedAskDuration;
95     }
96
97     public FiniteDuration getGossipTickInterval() {
98         if (cachedGossipTickInterval != null) {
99             return cachedGossipTickInterval;
100         }
101
102         cachedGossipTickInterval = new FiniteDuration(
103                 get().getDuration(TAG_GOSSIP_TICK_INTERVAL, TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
104
105         return cachedGossipTickInterval;
106     }
107
108     /**
109      * This is called via blueprint xml as the builder pattern can't be used.
110      */
111     @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
112             justification = "Findbugs flags this as an unconfirmed cast of return value but the build method clearly "
113                 + "returns RemoteOpsProviderConfig. Perhaps it's confused b/c the build method is overloaded and "
114                 + "and differs in return type from the base class.")
115     public static RemoteOpsProviderConfig newInstance(final String actorSystemName, final boolean metricCaptureEnabled,
116                                                       final int mailboxCapacity) {
117         return new Builder(actorSystemName).metricCaptureEnabled(metricCaptureEnabled)
118                 .mailboxCapacity(mailboxCapacity).build();
119     }
120
121     public static class Builder extends CommonConfig.Builder<Builder> {
122
123         public Builder(final String actorSystemName) {
124             super(actorSystemName);
125
126             //Actor names
127             configHolder.put(TAG_RPC_BROKER_NAME, "broker");
128             configHolder.put(TAG_RPC_REGISTRAR_NAME, "registrar");
129             configHolder.put(TAG_RPC_REGISTRY_NAME, "registry");
130             configHolder.put(TAG_ACTION_REGISTRY_NAME, "action-registry");
131             configHolder.put(TAG_RPC_MGR_NAME, "rpc");
132
133             //Actor paths
134             configHolder.put(TAG_RPC_BROKER_PATH, "/user/rpc/broker");
135             configHolder.put(TAG_RPC_REGISTRY_PATH, "/user/rpc/registry");
136             configHolder.put(TAG_ACTION_REGISTRY_PATH, "/user/action/registry");
137             configHolder.put(TAG_RPC_MGR_PATH, "/user/rpc");
138
139             //durations
140             configHolder.put(TAG_ASK_DURATION, "15s");
141             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, "500ms");
142
143             // persistence
144             configHolder.put(TAG_RPC_REGISTRY_PERSISTENCE_ID, "remote-rpc-registry");
145             configHolder.put(TAG_ACTION_REGISTRY_PERSISTENCE_ID, "remote-action-registry");
146         }
147
148         public Builder gossipTickInterval(final String interval) {
149             configHolder.put(TAG_GOSSIP_TICK_INTERVAL, interval);
150             return this;
151         }
152
153         @Override
154         public RemoteOpsProviderConfig build() {
155             return new RemoteOpsProviderConfig(merge());
156         }
157     }
158 }

©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.