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=9e69fa66df463c25f0c9c29562c9d1f015e642a8;hp=c25aa523e2e0823769a28e9dc01b32da711b0ae5;hb=e9fce74e37472296faa2faf1acbd110b74196032;hpb=ee146664ac8ae45439c14a84fe769633c3ebf847 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 c25aa523e2..9e69fa66df 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,76 +8,70 @@ package org.opendaylight.controller.remote.rpc.registry; import akka.actor.ActorRef; -import akka.japi.Option; -import akka.japi.Pair; -import org.opendaylight.controller.remote.rpc.registry.gossip.Copier; -import org.opendaylight.controller.sal.connector.api.RpcRouter; - +import com.google.common.base.Preconditions; import java.io.Serializable; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +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; +import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; -public class RoutingTable implements Copier, Serializable { +public class RoutingTable implements BucketData, Serializable { + private static final long serialVersionUID = 5592610415175278760L; - private Map, Long> table = new HashMap<>(); - private ActorRef router; + private final Map, Long> table; + private final ActorRef router; - @Override - public RoutingTable copy() { - RoutingTable copy = new RoutingTable(); - copy.setTable(Collections.unmodifiableMap(table)); - copy.setRouter(this.getRouter()); + private RoutingTable(final ActorRef router, final Map, Long> table) { + this.router = Preconditions.checkNotNull(router); + this.table = Preconditions.checkNotNull(table); + } - return copy; + RoutingTable(final ActorRef router) { + this(router, new HashMap<>()); } - public Option> getRouterFor(RpcRouter.RouteIdentifier routeId){ - Long updatedTime = table.get(routeId); + RoutingTable copy() { + return new RoutingTable(router, new HashMap<>(table)); + } - if (updatedTime == null || router == null) - return Option.none(); - else - return Option.option(new Pair<>(router, updatedTime)); + @Override + public Optional getWatchActor() { + return Optional.of(router); + } + + public Set> getRoutes() { + return table.keySet(); } - public void addRoute(RpcRouter.RouteIdentifier routeId){ + public void addRoute(final RpcRouter.RouteIdentifier routeId) { table.put(routeId, System.currentTimeMillis()); } - public void removeRoute(RpcRouter.RouteIdentifier routeId){ + public void removeRoute(final RpcRouter.RouteIdentifier routeId) { table.remove(routeId); } - public Boolean contains(RpcRouter.RouteIdentifier routeId){ + public boolean contains(final RpcRouter.RouteIdentifier routeId) { return table.containsKey(routeId); } - /// - /// Getter, Setters - /// - //TODO: Remove public - public Map, Long> getTable() { - return table; + public boolean isEmpty() { + return table.isEmpty(); } - void setTable(Map, Long> table) { - this.table = table; + public int size() { + return table.size(); } public ActorRef getRouter() { return router; } - public void setRouter(ActorRef router) { - this.router = router; - } - @Override public String toString() { - return "RoutingTable{" + - "table=" + table + - ", router=" + router + - '}'; + return "RoutingTable{" + "table=" + table + ", router=" + router + '}'; } }