Register action MXBean only during start
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / ActionRegistry.java
index b90bad26f5a511e1a3662905852627f860dd42d4..96697391485b79f75ccadaa5e148e7d533c5552d 100644 (file)
@@ -37,14 +37,13 @@ import org.opendaylight.mdsal.dom.api.DOMActionInstance;
  */
 public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
     private final ActorRef rpcRegistrar;
-    private final RemoteActionRegistryMXBeanImpl mxBean;
+
+    private RemoteActionRegistryMXBeanImpl mxBean;
 
     public ActionRegistry(final RemoteOpsProviderConfig config, final ActorRef rpcInvoker,
                           final ActorRef rpcRegistrar) {
         super(config, config.getRpcRegistryPersistenceId(), new ActionRoutingTable(rpcInvoker, ImmutableSet.of()));
         this.rpcRegistrar = requireNonNull(rpcRegistrar);
-        this.mxBean = new RemoteActionRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
-                config.getAskDuration()), config.getAskDuration());
     }
 
     /**
@@ -60,10 +59,20 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
         return Props.create(ActionRegistry.class, config, opsInvoker, opsRegistrar);
     }
 
+    @Override
+    public void preStart() {
+        super.preStart();
+        mxBean = new RemoteActionRegistryMXBeanImpl(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