Register MXBean only during start
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / RpcRegistry.java
index 8e0b9c51eab5a4f646ec0ae568271fc3994119c8..2c89f1426072a6e945de5ed107fd3b07a53ef7df 100644 (file)
@@ -42,13 +42,12 @@ import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
  */
 public class RpcRegistry extends BucketStoreActor<RoutingTable> {
     private final ActorRef rpcRegistrar;
-    private final RemoteRpcRegistryMXBeanImpl mxBean;
+    private RemoteRpcRegistryMXBeanImpl mxBean;
 
     public RpcRegistry(final RemoteOpsProviderConfig config, final ActorRef rpcInvoker, final ActorRef rpcRegistrar) {
         super(config, config.getRpcRegistryPersistenceId(), new RoutingTable(rpcInvoker, ImmutableSet.of()));
         this.rpcRegistrar = requireNonNull(rpcRegistrar);
-        this.mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
-                config.getAskDuration()), config.getAskDuration());
+
     }
 
     /**
@@ -64,10 +63,20 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
         return Props.create(RpcRegistry.class, config, rpcInvoker, rpcRegistrar);
     }
 
+    @Override
+    public void preStart() {
+        super.preStart();
+        mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
+            getConfig().getAskDuration()), getConfig().getAskDuration());
+    }
+
     @Override
     public void postStop() throws Exception {
+        if (mxBean != null) {
+            mxBean.unregister();
+            mxBean = null;
+        }
         super.postStop();
-        this.mxBean.unregister();
     }
 
     @Override