2 * Copyright (c) 2015 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.registry.mbeans;
10 import akka.actor.Address;
11 import akka.util.Timeout;
12 import java.util.HashMap;
13 import java.util.HashSet;
15 import java.util.Map.Entry;
17 import org.opendaylight.controller.remote.rpc.registry.RoutingTable;
18 import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
20 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
22 public class RemoteRpcRegistryMXBeanImpl extends AbstractRegistryMXBean<RoutingTable, DOMRpcIdentifier>
23 implements RemoteRpcRegistryMXBean {
24 public RemoteRpcRegistryMXBeanImpl(final BucketStoreAccess rpcRegistryAccess, final Timeout timeout) {
25 super("RemoteRpcRegistry", "RemoteRpcBroker", rpcRegistryAccess, timeout);
29 public Set<String> getGlobalRpc() {
30 RoutingTable table = localData();
31 Set<String> globalRpc = new HashSet<>(table.getItems().size());
32 for (DOMRpcIdentifier route : table.getItems()) {
33 if (route.getContextReference().isEmpty()) {
34 globalRpc.add(route.getType().toString());
38 log.debug("Locally registered global RPCs {}", globalRpc);
43 public Set<String> getLocalRegisteredRoutedRpc() {
44 RoutingTable table = localData();
45 Set<String> routedRpc = new HashSet<>(table.getItems().size());
46 for (DOMRpcIdentifier route : table.getItems()) {
47 if (!route.getContextReference().isEmpty()) {
48 routedRpc.add(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + route.getType());
52 log.debug("Locally registered routed RPCs {}", routedRpc);
57 public Map<String, String> findRpcByName(final String name) {
58 RoutingTable localTable = localData();
59 // Get all RPCs from local bucket
60 Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
62 // Get all RPCs from remote bucket
63 Map<Address, Bucket<RoutingTable>> buckets = remoteBuckets();
64 for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
65 RoutingTable table = entry.getValue().getData();
66 rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString()));
69 log.debug("list of RPCs {} searched by name {}", rpcMap, name);
74 public Map<String, String> findRpcByRoute(final String routeId) {
75 RoutingTable localTable = localData();
76 Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT));
78 Map<Address, Bucket<RoutingTable>> buckets = remoteBuckets();
79 for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
80 RoutingTable table = entry.getValue().getData();
81 rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, entry.getKey().toString()));
84 log.debug("list of RPCs {} searched by route {}", rpcMap, routeId);
89 * Search if the routing table route String contains routeName.
91 private static Map<String,String> getRpcMemberMapByRoute(final RoutingTable table, final String routeName,
92 final String address) {
93 Set<DOMRpcIdentifier> routes = table.getItems();
94 Map<String, String> rpcMap = new HashMap<>(routes.size());
95 for (DOMRpcIdentifier route : routes) {
96 if (!route.getContextReference().isEmpty()) {
97 String routeString = route.getContextReference().toString();
98 if (routeString.contains(routeName)) {
99 rpcMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
107 * Search if the routing table route type contains name.
109 private static Map<String, String> getRpcMemberMapByName(final RoutingTable table, final String name,
110 final String address) {
111 Set<DOMRpcIdentifier> routes = table.getItems();
112 Map<String, String> rpcMap = new HashMap<>(routes.size());
113 for (DOMRpcIdentifier route : routes) {
114 if (!route.getContextReference().isEmpty()) {
115 String type = route.getType().toString();
116 if (type.contains(name)) {
117 rpcMap.put(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + type, address);
125 public String getBucketVersions() {
126 return bucketVersions();