*/
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;
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
return getListenerActorsInfo(getState().getTreeChangeListenerActors());
}
- @Override
- public List<DataTreeListenerInfo> getDataChangeListenerInfo() {
- return getListenerActorsInfo(getState().getDataChangeListenerActors());
- }
-
@SuppressWarnings("checkstyle:IllegalCatch")
private OnDemandShardState getState() {
try {
}
@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());
}
}