X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2FRpcRegistry.java;h=8d66ed8ccb163abc56891009bfe09cfdae29add6;hb=HEAD;hp=68fead4407781f534b0f9b4aee3ae7e2b012f908;hpb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;p=controller.git 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 68fead4407..8d66ed8ccb 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 @@ -7,11 +7,13 @@ */ package org.opendaylight.controller.remote.rpc.registry; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + import akka.actor.ActorRef; import akka.actor.Address; import akka.actor.Props; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -40,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 = Preconditions.checkNotNull(rpcRegistrar); - this.mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(), - config.getAskDuration()), config.getAskDuration()); + this.rpcRegistrar = requireNonNull(rpcRegistrar); + } /** @@ -63,17 +64,27 @@ public class RpcRegistry extends BucketStoreActor { } @Override - public void postStop() { + 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 protected void handleCommand(final Object message) throws Exception { - if (message instanceof AddOrUpdateRoutes) { - receiveAddRoutes((AddOrUpdateRoutes) message); - } else if (message instanceof RemoveRoutes) { - receiveRemoveRoutes((RemoveRoutes) message); + if (message instanceof AddOrUpdateRoutes addRoutes) { + receiveAddRoutes(addRoutes); + } else if (message instanceof RemoveRoutes removeRoutes) { + receiveRemoveRoutes(removeRoutes); } else { super.handleCommand(message); } @@ -123,7 +134,7 @@ public class RpcRegistry extends BucketStoreActor { @VisibleForTesting public RemoteRpcEndpoint(final ActorRef router, final Collection rpcs) { - this.router = Preconditions.checkNotNull(router); + this.router = requireNonNull(router); this.rpcs = ImmutableSet.copyOf(rpcs); } @@ -144,13 +155,13 @@ public class RpcRegistry extends BucketStoreActor { final List rpcRouteIdentifiers; AbstractRouteMessage(final Collection rpcRouteIdentifiers) { - Preconditions.checkArgument(rpcRouteIdentifiers != null && !rpcRouteIdentifiers.isEmpty(), + checkArgument(rpcRouteIdentifiers != null && !rpcRouteIdentifiers.isEmpty(), "Route Identifiers must be supplied"); this.rpcRouteIdentifiers = ImmutableList.copyOf(rpcRouteIdentifiers); } List getRouteIdentifiers() { - return this.rpcRouteIdentifiers; + return rpcRouteIdentifiers; } @Override