String performance and maintenability
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / mbeans / RemoteRpcRegistryMXBeanImpl.java
index 5fbd91cc81c349ad0244ac4b0d96c39f6ab4ebf7..58abcac0d5b87ba0995c664d33ad06b1485005d6 100644 (file)
@@ -15,10 +15,10 @@ 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.md.sal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.controller.remote.rpc.registry.RoutingTable;
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
 import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
-import org.opendaylight.controller.sal.connector.api.RpcRouter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,8 +27,6 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     protected final Logger log = LoggerFactory.getLogger(getClass());
 
-    private static final String NULL_CONSTANT = "null";
-
     private static final String LOCAL_CONSTANT = "local";
 
     private static final String ROUTE_CONSTANT = "route:";
@@ -45,11 +43,11 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Set<String> getGlobalRpc() {
-        RoutingTable table = rpcRegistry.getLocalBucket().getData();
+        RoutingTable table = rpcRegistry.getLocalData();
         Set<String> globalRpc = new HashSet<>(table.getRoutes().size());
-        for (RpcRouter.RouteIdentifier<?, ?, ?> route : table.getRoutes()) {
-            if (route.getRoute() == null) {
-                globalRpc.add(route.getType() != null ? route.getType().toString() : NULL_CONSTANT);
+        for (DOMRpcIdentifier route : table.getRoutes()) {
+            if (route.getContextReference().isEmpty()) {
+                globalRpc.add(route.getType().toString());
             }
         }
 
@@ -59,14 +57,11 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Set<String> getLocalRegisteredRoutedRpc() {
-        RoutingTable table = rpcRegistry.getLocalBucket().getData();
+        RoutingTable table = rpcRegistry.getLocalData();
         Set<String> routedRpc = new HashSet<>(table.getRoutes().size());
-        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);
-                routedRpc.add(builder.toString());
+        for (DOMRpcIdentifier route : table.getRoutes()) {
+            if (!route.getContextReference().isEmpty()) {
+                routedRpc.add(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + route.getType());
             }
         }
 
@@ -76,7 +71,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Map<String, String> findRpcByName(final String name) {
-        RoutingTable localTable = rpcRegistry.getLocalBucket().getData();
+        RoutingTable localTable = rpcRegistry.getLocalData();
         // Get all RPCs from local bucket
         Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
 
@@ -92,8 +87,8 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
     }
 
     @Override
-    public Map<String, String> findRpcByRoute(String routeId) {
-        RoutingTable localTable = rpcRegistry.getLocalBucket().getData();
+    public Map<String, String> findRpcByRoute(final String routeId) {
+        RoutingTable localTable = rpcRegistry.getLocalData();
         Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT));
 
         Map<Address, Bucket<RoutingTable>> buckets = rpcRegistry.getRemoteBuckets();
@@ -109,18 +104,15 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
     /**
      * Search if the routing table route String contains routeName.
      */
-    private Map<String,String> getRpcMemberMapByRoute(final RoutingTable table, final String routeName,
+    private static Map<String,String> getRpcMemberMapByRoute(final RoutingTable table, final String routeName,
                                                       final String address) {
-        Set<RpcRouter.RouteIdentifier<?, ?, ?>> routes = table.getRoutes();
+        Set<DOMRpcIdentifier> routes = table.getRoutes();
         Map<String, String> rpcMap = new HashMap<>(routes.size());
-        for (RpcRouter.RouteIdentifier<?, ?, ?> route : table.getRoutes()) {
-            if (route.getRoute() != null) {
-                String routeString = route.getRoute().toString();
+        for (DOMRpcIdentifier route : routes) {
+            if (!route.getContextReference().isEmpty()) {
+                String routeString = route.getContextReference().toString();
                 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);
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
                 }
             }
         }
@@ -130,18 +122,15 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
     /**
      * Search if the routing table route type contains name.
      */
-    private Map<String, String>  getRpcMemberMapByName(final RoutingTable table, final String name,
+    private static Map<String, String>  getRpcMemberMapByName(final RoutingTable table, final String name,
                                                        final String address) {
-        Set<RpcRouter.RouteIdentifier<?, ?, ?>> routes = table.getRoutes();
+        Set<DOMRpcIdentifier> routes = table.getRoutes();
         Map<String, String> rpcMap = new HashMap<>(routes.size());
-        for (RpcRouter.RouteIdentifier<?, ?, ?> route : routes) {
-            if (route.getType() != null) {
+        for (DOMRpcIdentifier route : routes) {
+            if (!route.getContextReference().isEmpty()) {
                 String type = route.getType().toString();
                 if (type.contains(name)) {
-                    StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                    builder.append(route.getRoute() != null ? route.getRoute().toString() : NULL_CONSTANT)
-                        .append(NAME_CONSTANT).append(type);
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + type, address);
                 }
             }
         }