Suppress modernization
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / jmx / mbeans / shard / ShardDataTreeListenerInfoMXBeanImpl.java
index 6c6726ca08d5054d0715ac776fbc6c29152f6858..6384735cf15554235e47c585e255cef7bb6d1df0 100644 (file)
@@ -15,11 +15,14 @@ import akka.dispatch.Futures;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
 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;
@@ -68,13 +71,14 @@ public class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implemen
             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());
     }
 }