From 73b088ee110766618a8728eed653b15cef896cf1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 11 Oct 2019 14:32:14 +0200 Subject: [PATCH] Register MXBean only during start 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 --- .../remote/rpc/registry/RpcRegistry.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java index 8e0b9c51ea..2c89f14260 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java @@ -42,13 +42,12 @@ import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; */ public class RpcRegistry extends BucketStoreActor { 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 { 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 -- 2.36.6