*/
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.base.Preconditions;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
-import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig;
+import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig;
import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes;
import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes;
-import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints;
import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
+import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreActor;
+import org.opendaylight.controller.remote.rpc.registry.mbeans.RemoteRpcRegistryMXBeanImpl;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
/**
* Registry to look up cluster nodes that have registered for a given RPC.
*/
public class RpcRegistry extends BucketStoreActor<RoutingTable> {
private final ActorRef rpcRegistrar;
+ private final RemoteRpcRegistryMXBeanImpl mxBean;
- public RpcRegistry(final RemoteRpcProviderConfig config, final ActorRef rpcInvoker, final ActorRef rpcRegistrar) {
+ 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.rpcRegistrar = requireNonNull(rpcRegistrar);
+ this.mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
+ config.getAskDuration()), config.getAskDuration());
}
/**
* @param rpcInvoker Actor handling RPC invocation requests from remote nodes
* @return A new {@link Props} instance
*/
- public static Props props(final RemoteRpcProviderConfig config, final ActorRef rpcInvoker,
- final ActorRef rpcRegistrar) {
+ public static Props props(final RemoteOpsProviderConfig config, final ActorRef rpcInvoker,
+ final ActorRef rpcRegistrar) {
return Props.create(RpcRegistry.class, config, rpcInvoker, rpcRegistrar);
}
+ @Override
+ public void postStop() throws Exception {
+ super.postStop();
+ this.mxBean.unregister();
+ }
+
@Override
protected void handleCommand(final Object message) throws Exception {
if (message instanceof AddOrUpdateRoutes) {
@Override
protected void onBucketRemoved(final Address address, final Bucket<RoutingTable> bucket) {
- rpcRegistrar.tell(new UpdateRemoteEndpoints(ImmutableMap.of(address, Optional.empty())), ActorRef.noSender());
+ rpcRegistrar.tell(new Messages.UpdateRemoteEndpoints(ImmutableMap.of(address, Optional.empty())),
+ ActorRef.noSender());
}
@Override
for (Entry<Address, Bucket<RoutingTable>> e : buckets.entrySet()) {
final RoutingTable table = e.getValue().getData();
- final Collection<DOMRpcIdentifier> rpcs = table.getRoutes();
+ final Collection<DOMRpcIdentifier> rpcs = table.getItems();
endpoints.put(e.getKey(), rpcs.isEmpty() ? Optional.empty()
- : Optional.of(new RemoteRpcEndpoint(table.getRpcInvoker(), rpcs)));
+ : Optional.of(new RemoteRpcEndpoint(table.getInvoker(), rpcs)));
}
if (!endpoints.isEmpty()) {
- rpcRegistrar.tell(new UpdateRemoteEndpoints(endpoints), ActorRef.noSender());
+ rpcRegistrar.tell(new Messages.UpdateRemoteEndpoints(endpoints), ActorRef.noSender());
}
}
private final Set<DOMRpcIdentifier> rpcs;
private final ActorRef router;
- RemoteRpcEndpoint(final ActorRef router, final Collection<DOMRpcIdentifier> rpcs) {
- this.router = Preconditions.checkNotNull(router);
+ @VisibleForTesting
+ public RemoteRpcEndpoint(final ActorRef router, final Collection<DOMRpcIdentifier> rpcs) {
+ this.router = requireNonNull(router);
this.rpcs = ImmutableSet.copyOf(rpcs);
}
*/
public static class Messages {
abstract static class AbstractRouteMessage {
- final List<DOMRpcIdentifier> routeIdentifiers;
+ final List<DOMRpcIdentifier> rpcRouteIdentifiers;
- AbstractRouteMessage(final Collection<DOMRpcIdentifier> routeIdentifiers) {
- Preconditions.checkArgument(routeIdentifiers != null && !routeIdentifiers.isEmpty(),
+ AbstractRouteMessage(final Collection<DOMRpcIdentifier> rpcRouteIdentifiers) {
+ checkArgument(rpcRouteIdentifiers != null && !rpcRouteIdentifiers.isEmpty(),
"Route Identifiers must be supplied");
- this.routeIdentifiers = ImmutableList.copyOf(routeIdentifiers);
+ this.rpcRouteIdentifiers = ImmutableList.copyOf(rpcRouteIdentifiers);
}
List<DOMRpcIdentifier> getRouteIdentifiers() {
- return this.routeIdentifiers;
+ return this.rpcRouteIdentifiers;
}
@Override
public String toString() {
- return "ContainsRoute{" + "routeIdentifiers=" + routeIdentifiers + '}';
+ return "ContainsRoute{" + "routeIdentifiers=" + rpcRouteIdentifiers + '}';
}
}
- public static final class AddOrUpdateRoutes extends AbstractRouteMessage {
- public AddOrUpdateRoutes(final Collection<DOMRpcIdentifier> routeIdentifiers) {
- super(routeIdentifiers);
+ public static final class AddOrUpdateRoutes extends Messages.AbstractRouteMessage {
+ public AddOrUpdateRoutes(final Collection<DOMRpcIdentifier> rpcRouteIdentifiers) {
+ super(rpcRouteIdentifiers);
}
+
}
public static final class RemoveRoutes extends AbstractRouteMessage {
- public RemoveRoutes(final Collection<DOMRpcIdentifier> routeIdentifiers) {
- super(routeIdentifiers);
+ public RemoveRoutes(final Collection<DOMRpcIdentifier> rpcRouteIdentifiers) {
+ super(rpcRouteIdentifiers);
}
}
public static final class UpdateRemoteEndpoints {
- private final Map<Address, Optional<RemoteRpcEndpoint>> endpoints;
+ private final Map<Address, Optional<RemoteRpcEndpoint>> rpcEndpoints;
+
- UpdateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> endpoints) {
- this.endpoints = ImmutableMap.copyOf(endpoints);
+ @VisibleForTesting
+ public UpdateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> rpcEndpoints) {
+ this.rpcEndpoints = ImmutableMap.copyOf(rpcEndpoints);
}
- public Map<Address, Optional<RemoteRpcEndpoint>> getEndpoints() {
- return endpoints;
+ public Map<Address, Optional<RemoteRpcEndpoint>> getRpcEndpoints() {
+ return rpcEndpoints;
}
}
}