Register action MXBean only during start 01/85201/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 18 Oct 2019 10:58:28 +0000 (12:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 18 Oct 2019 10:58:28 +0000 (12:58 +0200)
We should not be registering resources until we are started, this
fixes an exception seen in Genius UT.

Change-Id: I5a95d7e2ddbc71eca23c57843eea64f0c58dfc7c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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;
  */
 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);
 
     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);
     }
 
         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 {
     @Override
     public void postStop() throws Exception {
+        if (mxBean != null) {
+            mxBean.unregister();
+            mxBean = null;
+        }
         super.postStop();
         super.postStop();
-        this.mxBean.unregister();
     }
 
     @Override
     }
 
     @Override