register RemoteRpcRegistryMXBean
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / RpcRegistry.java
index 805e47a0dd05e7b52082f705f523b8870cd5bb02..fe43a691d2d685ee0c9fa16f0251c3e925d1c5be 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.remote.rpc.registry;
 import akka.actor.ActorRef;
 import akka.actor.Address;
 import akka.actor.Props;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -28,6 +29,7 @@ import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.Remo
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints;
 import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreActor;
+import org.opendaylight.controller.remote.rpc.registry.mbeans.RemoteRpcRegistryMXBeanImpl;
 
 /**
  * Registry to look up cluster nodes that have registered for a given RPC.
@@ -38,10 +40,12 @@ import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreActor;
  */
 public class RpcRegistry extends BucketStoreActor<RoutingTable> {
     private final ActorRef rpcRegistrar;
+    private final RemoteRpcRegistryMXBeanImpl mxBean;
 
     public RpcRegistry(final RemoteRpcProviderConfig config, final ActorRef rpcInvoker, final ActorRef rpcRegistrar) {
         super(config, config.getRpcRegistryPersistenceId(), new RoutingTable(rpcInvoker, ImmutableSet.of()));
         this.rpcRegistrar = Preconditions.checkNotNull(rpcRegistrar);
+        this.mxBean = new RemoteRpcRegistryMXBeanImpl(this);
     }
 
     /**
@@ -57,6 +61,12 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
         return Props.create(RpcRegistry.class, config, rpcInvoker, rpcRegistrar);
     }
 
+    @Override
+    public void postStop() {
+        super.postStop();
+        this.mxBean.unregister();
+    }
+
     @Override
     protected void handleCommand(final Object message) throws Exception {
         if (message instanceof AddOrUpdateRoutes) {
@@ -109,7 +119,8 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
         private final Set<DOMRpcIdentifier> rpcs;
         private final ActorRef router;
 
-        RemoteRpcEndpoint(final ActorRef router, final Collection<DOMRpcIdentifier> rpcs) {
+        @VisibleForTesting
+        public RemoteRpcEndpoint(final ActorRef router, final Collection<DOMRpcIdentifier> rpcs) {
             this.router = Preconditions.checkNotNull(router);
             this.rpcs = ImmutableSet.copyOf(rpcs);
         }
@@ -161,7 +172,8 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
         public static final class UpdateRemoteEndpoints {
             private final Map<Address, Optional<RemoteRpcEndpoint>> endpoints;
 
-            UpdateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> endpoints) {
+            @VisibleForTesting
+            public UpdateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> endpoints) {
                 this.endpoints = ImmutableMap.copyOf(endpoints);
             }