2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.remote.rpc.registry.mbeans;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.Address;
13 import akka.util.Timeout;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
18 import org.opendaylight.controller.remote.rpc.registry.AbstractRoutingTable;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
20 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.Await;
24 import scala.concurrent.Future;
25 import scala.concurrent.duration.FiniteDuration;
27 abstract class AbstractRegistryMXBean<T extends AbstractRoutingTable<T, I>, I> extends AbstractMXBean {
28 static final String LOCAL_CONSTANT = "local";
29 static final String ROUTE_CONSTANT = "route:";
30 static final String NAME_CONSTANT = " | name:";
32 @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
33 protected final Logger log = LoggerFactory.getLogger(getClass());
35 private final BucketStoreAccess bucketAccess;
36 private final FiniteDuration timeout;
38 AbstractRegistryMXBean(final @NonNull String beanName, final @NonNull String beanType,
39 final @NonNull BucketStoreAccess bucketAccess, final @NonNull Timeout timeout) {
40 super(beanName, beanType, null);
41 this.bucketAccess = requireNonNull(bucketAccess);
42 this.timeout = timeout.duration();
46 @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
49 return (T) Await.result((Future) bucketAccess.getLocalData(), timeout);
50 } catch (Exception e) {
51 throw new RuntimeException("getLocalData failed", e);
55 @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
56 final Map<Address, Bucket<T>> remoteBuckets() {
58 return (Map<Address, Bucket<T>>) Await.result((Future)bucketAccess.getRemoteBuckets(), timeout);
59 } catch (Exception e) {
60 throw new RuntimeException("getRemoteBuckets failed", e);
64 @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
65 final String bucketVersions() {
67 return Await.result((Future)bucketAccess.getBucketVersions(), timeout).toString();
68 } catch (Exception e) {
69 throw new RuntimeException("getVersions failed", e);