Suppress modernization
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / jmx / mbeans / shard / ShardDataTreeListenerInfoMXBeanImpl.java
index 54cb49cc17607c2b1b3b722a187c3f08b972f22a..6384735cf15554235e47c585e255cef7bb6d1df0 100644 (file)
@@ -7,17 +7,22 @@
  */
 package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.dispatch.Futures;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
+import com.google.common.collect.Streams;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
 import org.opendaylight.controller.cluster.datastore.messages.DataTreeListenerInfo;
 import org.opendaylight.controller.cluster.datastore.messages.GetInfo;
 import org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState;
@@ -39,7 +44,7 @@ public class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implemen
     public ShardDataTreeListenerInfoMXBeanImpl(final String shardName, final String mxBeanType,
             final ActorRef shardActor) {
         super(shardName, mxBeanType, JMX_CATEGORY);
-        stateCache = new OnDemandShardStateCache(shardName, Preconditions.checkNotNull(shardActor));
+        stateCache = new OnDemandShardStateCache(shardName, requireNonNull(shardActor));
     }
 
     @Override
@@ -47,11 +52,6 @@ public class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implemen
         return getListenerActorsInfo(getState().getTreeChangeListenerActors());
     }
 
-    @Override
-    public List<DataTreeListenerInfo> getDataChangeListenerInfo() {
-        return getListenerActorsInfo(getState().getDataChangeListenerActors());
-    }
-
     @SuppressWarnings("checkstyle:IllegalCatch")
     private OnDemandShardState getState() {
         try {
@@ -63,20 +63,22 @@ public class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implemen
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private List<DataTreeListenerInfo> getListenerActorsInfo(Collection<ActorSelection> actors) {
+    @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Akka's Await.result() API contract")
+    private static List<DataTreeListenerInfo> getListenerActorsInfo(final Collection<ActorSelection> actors) {
         final Timeout timeout = new Timeout(20, TimeUnit.SECONDS);
         final List<Future<Object>> futureList = new ArrayList<>(actors.size());
         for (ActorSelection actor: actors) {
             futureList.add(Patterns.ask(actor, GetInfo.INSTANCE, timeout));
         }
 
+        final Iterable<Object> listenerInfos;
         try {
-            final List<DataTreeListenerInfo> listenerInfoList = new ArrayList<>();
-            Await.result(Futures.sequence(futureList, ExecutionContext.Implicits$.MODULE$.global()),
-                    timeout.duration()).forEach(obj -> listenerInfoList.add((DataTreeListenerInfo) obj));
-            return listenerInfoList;
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+            listenerInfos = Await.result(Futures.sequence(futureList, ExecutionContext.Implicits$.MODULE$.global()),
+                timeout.duration());
+        } catch (TimeoutException | InterruptedException e) {
+            throw new IllegalStateException("Failed to acquire listeners", e);
         }
+
+        return Streams.stream(listenerInfos).map(DataTreeListenerInfo.class::cast).collect(Collectors.toList());
     }
 }