Fix findbugs warnings
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / mbeans / RemoteRpcRegistryMXBeanImpl.java
index eabb170db244ce260a65dcb8e2dde86eb304be21..87adef3d9cedf30f62ce9de22653ea2a643cde3b 100644 (file)
@@ -5,26 +5,29 @@
  * 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 akka.util.Timeout;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 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.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.remote.rpc.registry.gossip.BucketStoreAccess;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+import scala.concurrent.Await;
+import scala.concurrent.Future;
 
 public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements RemoteRpcRegistryMXBean {
 
+    @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
     protected final Logger log = LoggerFactory.getLogger(getClass());
 
     private static final String LOCAL_CONSTANT = "local";
@@ -33,17 +36,38 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     private static final String NAME_CONSTANT = " | name:";
 
-    private final RpcRegistry rpcRegistry;
+    private final BucketStoreAccess rpcRegistryAccess;
+    private final Timeout timeout;
 
-    public RemoteRpcRegistryMXBeanImpl(final RpcRegistry rpcRegistry) {
+    public RemoteRpcRegistryMXBeanImpl(final BucketStoreAccess rpcRegistryAccess, final Timeout timeout) {
         super("RemoteRpcRegistry", "RemoteRpcBroker", null);
-        this.rpcRegistry = rpcRegistry;
+        this.rpcRegistryAccess = rpcRegistryAccess;
+        this.timeout = timeout;
         registerMBean();
     }
 
+    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
+    private RoutingTable getLocalData() {
+        try {
+            return (RoutingTable) Await.result((Future) rpcRegistryAccess.getLocalData(), timeout.duration());
+        } catch (Exception e) {
+            throw new RuntimeException("getLocalData failed", e);
+        }
+    }
+
+    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
+    private Map<Address, Bucket<RoutingTable>> getRemoteBuckets() {
+        try {
+            return (Map<Address, Bucket<RoutingTable>>) Await.result((Future)rpcRegistryAccess.getRemoteBuckets(),
+                    timeout.duration());
+        } catch (Exception e) {
+            throw new RuntimeException("getRemoteBuckets failed", e);
+        }
+    }
+
     @Override
     public Set<String> getGlobalRpc() {
-        RoutingTable table = rpcRegistry.getLocalData();
+        RoutingTable table = getLocalData();
         Set<String> globalRpc = new HashSet<>(table.getRoutes().size());
         for (DOMRpcIdentifier route : table.getRoutes()) {
             if (route.getContextReference().isEmpty()) {
@@ -57,13 +81,11 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Set<String> getLocalRegisteredRoutedRpc() {
-        RoutingTable table = rpcRegistry.getLocalData();
+        RoutingTable table = getLocalData();
         Set<String> routedRpc = new HashSet<>(table.getRoutes().size());
         for (DOMRpcIdentifier route : table.getRoutes()) {
             if (!route.getContextReference().isEmpty()) {
-                StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                builder.append(route.getContextReference().toString()).append(NAME_CONSTANT).append(route.getType());
-                routedRpc.add(builder.toString());
+                routedRpc.add(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + route.getType());
             }
         }
 
@@ -73,12 +95,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Map<String, String> findRpcByName(final String name) {
-        RoutingTable localTable = rpcRegistry.getLocalData();
+        RoutingTable localTable = getLocalData();
         // Get all RPCs from local bucket
         Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
 
         // Get all RPCs from remote bucket
-        Map<Address, Bucket<RoutingTable>> buckets = rpcRegistry.getRemoteBuckets();
+        Map<Address, Bucket<RoutingTable>> buckets = getRemoteBuckets();
         for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
             RoutingTable table = entry.getValue().getData();
             rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString()));
@@ -90,10 +112,10 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
 
     @Override
     public Map<String, String> findRpcByRoute(final String routeId) {
-        RoutingTable localTable = rpcRegistry.getLocalData();
+        RoutingTable localTable = getLocalData();
         Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT));
 
-        Map<Address, Bucket<RoutingTable>> buckets = rpcRegistry.getRemoteBuckets();
+        Map<Address, Bucket<RoutingTable>> buckets = getRemoteBuckets();
         for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
             RoutingTable table = entry.getValue().getData();
             rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, entry.getKey().toString()));
@@ -114,9 +136,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
             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());
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
                 }
             }
         }
@@ -134,9 +154,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
             if (!route.getContextReference().isEmpty()) {
                 String type = route.getType().toString();
                 if (type.contains(name)) {
-                    StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                    builder.append(route.getContextReference()).append(NAME_CONSTANT).append(type);
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + type, address);
                 }
             }
         }
@@ -144,7 +162,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
     }
 
     @Override
+    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
     public String getBucketVersions() {
-        return rpcRegistry.getVersions().toString();
+        try {
+            return Await.result((Future)rpcRegistryAccess.getBucketVersions(), timeout.duration()).toString();
+        } catch (Exception e) {
+            throw new RuntimeException("getVersions failed", e);
+        }
     }
 }