X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2Fmbeans%2FRemoteRpcRegistryMXBeanImpl.java;h=5fbd91cc81c349ad0244ac4b0d96c39f6ab4ebf7;hp=c7d9b9955d912a14462afe4ffbd65344dc53332a;hb=b78ee4d6b08e2cc0cf5edd01af0e54c3bf619ab5;hpb=dea515c8870769408b9bea29f555d6b71ff43211 diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java index c7d9b9955d..5fbd91cc81 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java @@ -1,6 +1,19 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.remote.rpc.registry.mbeans; import akka.actor.Address; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import org.opendaylight.controller.remote.rpc.registry.RoutingTable; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; @@ -9,23 +22,18 @@ import org.opendaylight.controller.sal.connector.api.RpcRouter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements RemoteRpcRegistryMXBean { protected final Logger log = LoggerFactory.getLogger(getClass()); - private final String NULL_CONSTANT = "null"; + private static final String NULL_CONSTANT = "null"; - private final String LOCAL_CONSTANT = "local"; + private static final String LOCAL_CONSTANT = "local"; - private final String ROUTE_CONSTANT = "route:"; + private static final String ROUTE_CONSTANT = "route:"; - private final String NAME_CONSTANT = " | name:"; + private static final String NAME_CONSTANT = " | name:"; private final RpcRegistry rpcRegistry; @@ -39,14 +47,13 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot public Set getGlobalRpc() { RoutingTable table = rpcRegistry.getLocalBucket().getData(); Set globalRpc = new HashSet<>(table.getRoutes().size()); - for(RpcRouter.RouteIdentifier route : table.getRoutes()){ - if(route.getRoute() == null) { + for (RpcRouter.RouteIdentifier route : table.getRoutes()) { + if (route.getRoute() == null) { globalRpc.add(route.getType() != null ? route.getType().toString() : NULL_CONSTANT); } } - if(log.isDebugEnabled()) { - log.debug("Locally registered global RPCs {}", globalRpc); - } + + log.debug("Locally registered global RPCs {}", globalRpc); return globalRpc; } @@ -54,17 +61,16 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot public Set getLocalRegisteredRoutedRpc() { RoutingTable table = rpcRegistry.getLocalBucket().getData(); Set routedRpc = new HashSet<>(table.getRoutes().size()); - for(RpcRouter.RouteIdentifier route : table.getRoutes()){ - if(route.getRoute() != null) { + for (RpcRouter.RouteIdentifier route : table.getRoutes()) { + if (route.getRoute() != null) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(route.getRoute().toString()).append(NAME_CONSTANT).append(route.getType() != null ? - route.getType().toString() : NULL_CONSTANT); + builder.append(route.getRoute().toString()).append(NAME_CONSTANT).append(route.getType() != null + ? route.getType().toString() : NULL_CONSTANT); routedRpc.add(builder.toString()); } } - if(log.isDebugEnabled()) { - log.debug("Locally registered routed RPCs {}", routedRpc); - } + + log.debug("Locally registered routed RPCs {}", routedRpc); return routedRpc; } @@ -76,13 +82,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot // Get all RPCs from remote bucket Map> buckets = rpcRegistry.getRemoteBuckets(); - for(Address address : buckets.keySet()) { - RoutingTable table = buckets.get(address).getData(); - rpcMap.putAll(getRpcMemberMapByName(table, name, address.toString())); - } - if(log.isDebugEnabled()) { - log.debug("list of RPCs {} searched by name {}", rpcMap, name); + for (Entry> entry : buckets.entrySet()) { + RoutingTable table = entry.getValue().getData(); + rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString())); } + + log.debug("list of RPCs {} searched by name {}", rpcMap, name); return rpcMap; } @@ -92,32 +97,29 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot Map rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT)); Map> buckets = rpcRegistry.getRemoteBuckets(); - for(Address address : buckets.keySet()) { - RoutingTable table = buckets.get(address).getData(); - rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, address.toString())); - - } - if(log.isDebugEnabled()) { - log.debug("list of RPCs {} searched by route {}", rpcMap, routeId); + for (Entry> entry : buckets.entrySet()) { + RoutingTable table = entry.getValue().getData(); + rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, entry.getKey().toString())); } + + log.debug("list of RPCs {} searched by route {}", rpcMap, routeId); return rpcMap; } /** - * Search if the routing table route String contains routeName + * Search if the routing table route String contains routeName. */ - private Map getRpcMemberMapByRoute(final RoutingTable table, final String routeName, final String address) { Set> routes = table.getRoutes(); Map rpcMap = new HashMap<>(routes.size()); - for(RpcRouter.RouteIdentifier route : table.getRoutes()){ - if(route.getRoute() != null) { + for (RpcRouter.RouteIdentifier route : table.getRoutes()) { + if (route.getRoute() != null) { String routeString = route.getRoute().toString(); - if(routeString.contains(routeName)) { + if (routeString.contains(routeName)) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(routeString).append(NAME_CONSTANT).append(route.getType() != null ? - route.getType().toString() : NULL_CONSTANT); + builder.append(routeString).append(NAME_CONSTANT).append(route.getType() != null + ? route.getType().toString() : NULL_CONSTANT); rpcMap.put(builder.toString(), address); } } @@ -126,18 +128,18 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot } /** - * Search if the routing table route type contains name + * Search if the routing table route type contains name. */ private Map getRpcMemberMapByName(final RoutingTable table, final String name, final String address) { Set> routes = table.getRoutes(); Map rpcMap = new HashMap<>(routes.size()); - for(RpcRouter.RouteIdentifier route : routes){ - if(route.getType() != null) { + for (RpcRouter.RouteIdentifier route : routes) { + if (route.getType() != null) { String type = route.getType().toString(); - if(type.contains(name)) { + if (type.contains(name)) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(route.getRoute() != null ? route.getRoute().toString(): NULL_CONSTANT) + builder.append(route.getRoute() != null ? route.getRoute().toString() : NULL_CONSTANT) .append(NAME_CONSTANT).append(type); rpcMap.put(builder.toString(), address); } @@ -146,11 +148,8 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot return rpcMap; } - - @Override public String getBucketVersions() { return rpcRegistry.getVersions().toString(); } - -} \ No newline at end of file +}