*/
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;
*/
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 = Preconditions.checkNotNull(rpcRegistrar);
- this.mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
- config.getAskDuration()), config.getAskDuration());
+ this.rpcRegistrar = requireNonNull(rpcRegistrar);
+
}
/**
}
@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);
}
@VisibleForTesting
public RemoteRpcEndpoint(final ActorRef router, final Collection<DOMRpcIdentifier> rpcs) {
- this.router = Preconditions.checkNotNull(router);
+ this.router = requireNonNull(router);
this.rpcs = ImmutableSet.copyOf(rpcs);
}
final List<DOMRpcIdentifier> rpcRouteIdentifiers;
AbstractRouteMessage(final Collection<DOMRpcIdentifier> rpcRouteIdentifiers) {
- Preconditions.checkArgument(rpcRouteIdentifiers != null && !rpcRouteIdentifiers.isEmpty(),
+ checkArgument(rpcRouteIdentifiers != null && !rpcRouteIdentifiers.isEmpty(),
"Route Identifiers must be supplied");
this.rpcRouteIdentifiers = ImmutableList.copyOf(rpcRouteIdentifiers);
}
List<DOMRpcIdentifier> getRouteIdentifiers() {
- return this.rpcRouteIdentifiers;
+ return rpcRouteIdentifiers;
}
@Override