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=40600d091e16345a61c9dbb9ecfe9096d89b6040;hb=refs%2Fchanges%2F68%2F54368%2F10;hp=54f76132090bc58da3ade977d5e4344416dec0c0;hpb=d04b71990a802071a786fe8f0df57bc4adbdec3f;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 54f7613209..40600d091e 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 @@ -10,10 +10,11 @@ package org.opendaylight.controller.remote.rpc.registry; 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; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -23,27 +24,24 @@ 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.RouteIdentifierImpl; 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.BucketStore; -import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreActor; /** * Registry to look up cluster nodes that have registered for a given RPC. * *

- * It uses {@link org.opendaylight.controller.remote.rpc.registry.gossip.BucketStore} to maintain this + * It uses {@link org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreActor} to maintain this * cluster wide information. */ -public class RpcRegistry extends BucketStore { +public class RpcRegistry extends BucketStoreActor { private final ActorRef rpcRegistrar; public RpcRegistry(final RemoteRpcProviderConfig config, final ActorRef rpcInvoker, final ActorRef rpcRegistrar) { - super(config, config.getRpcRegistryPersistenceId(), new RoutingTable(rpcInvoker)); + super(config, config.getRpcRegistryPersistenceId(), new RoutingTable(rpcInvoker, ImmutableSet.of())); this.rpcRegistrar = Preconditions.checkNotNull(rpcRegistrar); } @@ -98,16 +96,7 @@ public class RpcRegistry extends BucketStore { for (Entry> e : buckets.entrySet()) { final RoutingTable table = e.getValue().getData(); - final List rpcs = new ArrayList<>(table.getRoutes().size()); - for (RouteIdentifier ri : table.getRoutes()) { - if (ri instanceof RouteIdentifierImpl) { - final RouteIdentifierImpl id = (RouteIdentifierImpl) ri; - rpcs.add(DOMRpcIdentifier.create(SchemaPath.create(true, id.getType()), id.getRoute())); - } else { - LOG.warn("Skipping unsupported route {} from {}", ri, e.getKey()); - } - } - + final Collection rpcs = table.getRoutes(); endpoints.put(e.getKey(), rpcs.isEmpty() ? Optional.empty() : Optional.of(new RemoteRpcEndpoint(table.getRpcInvoker(), rpcs))); } @@ -121,7 +110,8 @@ public class RpcRegistry extends BucketStore { private final Set rpcs; private final ActorRef router; - RemoteRpcEndpoint(final ActorRef router, final Collection rpcs) { + @VisibleForTesting + public RemoteRpcEndpoint(final ActorRef router, final Collection rpcs) { this.router = Preconditions.checkNotNull(router); this.rpcs = ImmutableSet.copyOf(rpcs); } @@ -140,15 +130,15 @@ public class RpcRegistry extends BucketStore { */ public static class Messages { abstract static class AbstractRouteMessage { - final List> routeIdentifiers; + final List routeIdentifiers; - AbstractRouteMessage(final List> routeIdentifiers) { + AbstractRouteMessage(final Collection routeIdentifiers) { Preconditions.checkArgument(routeIdentifiers != null && !routeIdentifiers.isEmpty(), "Route Identifiers must be supplied"); - this.routeIdentifiers = routeIdentifiers; + this.routeIdentifiers = ImmutableList.copyOf(routeIdentifiers); } - List> getRouteIdentifiers() { + List getRouteIdentifiers() { return this.routeIdentifiers; } @@ -159,13 +149,13 @@ public class RpcRegistry extends BucketStore { } public static final class AddOrUpdateRoutes extends AbstractRouteMessage { - public AddOrUpdateRoutes(final List> routeIdentifiers) { + public AddOrUpdateRoutes(final Collection routeIdentifiers) { super(routeIdentifiers); } } public static final class RemoveRoutes extends AbstractRouteMessage { - public RemoveRoutes(final List> routeIdentifiers) { + public RemoveRoutes(final Collection routeIdentifiers) { super(routeIdentifiers); } } @@ -173,7 +163,8 @@ public class RpcRegistry extends BucketStore { public static final class UpdateRemoteEndpoints { private final Map> endpoints; - UpdateRemoteEndpoints(final Map> endpoints) { + @VisibleForTesting + public UpdateRemoteEndpoints(final Map> endpoints) { this.endpoints = ImmutableMap.copyOf(endpoints); }