X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2FRoutingTable.java;h=0e68eb87096828f89892b338969aaaea24f13954;hp=f67657f6927801931fae2fd0434481169f2f3de8;hb=a884499896d6a146743272b08b4a7e504d9e8b9e;hpb=a9277acea2f63eccc9fa3cb36aa482f596ca41bd diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java index f67657f692..0e68eb8709 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java @@ -8,72 +8,69 @@ package org.opendaylight.controller.remote.rpc.registry; import akka.actor.ActorRef; -import akka.japi.Option; -import akka.japi.Pair; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import org.opendaylight.controller.remote.rpc.registry.gossip.Copier; -import org.opendaylight.controller.sal.connector.api.RpcRouter; +import java.util.Collection; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import org.opendaylight.controller.remote.rpc.registry.gossip.BucketData; +import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; -public class RoutingTable implements Copier, Serializable { - private static final long serialVersionUID = 5592610415175278760L; +public class RoutingTable implements BucketData, Serializable { + private static final long serialVersionUID = 1L; - private final Map, Long> table = new HashMap<>(); - private ActorRef router; + private final Set> rpcs; + private final ActorRef rpcInvoker; - @Override - public RoutingTable copy() { - RoutingTable copy = new RoutingTable(); - copy.table.putAll(table); - copy.setRouter(this.getRouter()); - - return copy; + private RoutingTable(final ActorRef rpcInvoker, final Set> table) { + this.rpcInvoker = Preconditions.checkNotNull(rpcInvoker); + this.rpcs = ImmutableSet.copyOf(table); } - public Option> getRouterFor(RpcRouter.RouteIdentifier routeId){ - Long updatedTime = table.get(routeId); - - if (updatedTime == null || router == null) { - return Option.none(); - } else { - return Option.option(new Pair<>(router, updatedTime)); - } + RoutingTable(final ActorRef rpcInvoker) { + this(rpcInvoker, ImmutableSet.of()); } - public void addRoute(RpcRouter.RouteIdentifier routeId){ - table.put(routeId, System.currentTimeMillis()); + @Override + public Optional getWatchActor() { + return Optional.of(rpcInvoker); } - public void removeRoute(RpcRouter.RouteIdentifier routeId){ - table.remove(routeId); + public Set> getRoutes() { + return rpcs; } - public boolean contains(RpcRouter.RouteIdentifier routeId){ - return table.containsKey(routeId); + ActorRef getRpcInvoker() { + return rpcInvoker; } - public boolean isEmpty(){ - return table.isEmpty(); + RoutingTable addRpcs(final Collection> toAdd) { + final Set> newRpcs = new HashSet<>(rpcs); + newRpcs.addAll(toAdd); + return new RoutingTable(rpcInvoker, newRpcs); } - public int size() { - return table.size(); + RoutingTable removeRpcs(final Collection> toRemove) { + final Set> newRpcs = new HashSet<>(rpcs); + newRpcs.removeAll(toRemove); + return new RoutingTable(rpcInvoker, newRpcs); } - public ActorRef getRouter() { - return router; + @VisibleForTesting + boolean contains(final RouteIdentifier routeId) { + return rpcs.contains(routeId); } - public void setRouter(ActorRef router) { - this.router = router; + @VisibleForTesting + int size() { + return rpcs.size(); } @Override public String toString() { - return "RoutingTable{" + - "table=" + table + - ", router=" + router + - '}'; + return "RoutingTable{" + "rpcs=" + rpcs + ", rpcInvoker=" + rpcInvoker + '}'; } }