Register MXBean only during start 57/85057/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Oct 2019 12:32:14 +0000 (14:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Oct 2019 12:32:14 +0000 (14:32 +0200)
We should not be registering resources until we are started, this
fixes an exception seen in Genius UT.

Change-Id: I550b586f905ec95a06cc9aaec167eb584592ba46
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java

index 8e0b9c5..2c89f14 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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.