Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Remove unneded RoutingTable time tracking
[controller.git]
/
opendaylight
/
md-sal
/
sal-remoterpc-connector
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
remote
/
rpc
/
registry
/
RoutingTable.java
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 f67657f6927801931fae2fd0434481169f2f3de8..0e68eb87096828f89892b338969aaaea24f13954 100644
(file)
--- 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;
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.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
<RoutingTable>, Serializable {
- private static final long serialVersionUID =
5592610415175278760
L;
+public class RoutingTable implements
BucketData
<RoutingTable>, Serializable {
+ private static final long serialVersionUID =
1
L;
- private final
Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table = new HashMap<>()
;
- private
ActorRef rout
er;
+ private final
Set<RouteIdentifier<?, ?, ?>> rpcs
;
+ private
final ActorRef rpcInvok
er;
- @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<RouteIdentifier<?, ?, ?>> table) {
+ this.rpcInvoker = Preconditions.checkNotNull(rpcInvoker);
+ this.rpcs = ImmutableSet.copyOf(table);
}
}
- public Option<Pair<ActorRef, Long>> 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<ActorRef> getWatchActor() {
+ return Optional.of(rpcInvoker);
}
}
- public
void removeRoute(RpcRouter.RouteIdentifier<?, ?, ?> routeId)
{
-
table.remove(routeId)
;
+ public
Set<RouteIdentifier<?, ?, ?>> 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<RouteIdentifier<?, ?, ?>> toAdd) {
+ final Set<RouteIdentifier<?, ?, ?>> newRpcs = new HashSet<>(rpcs);
+ newRpcs.addAll(toAdd);
+ return new RoutingTable(rpcInvoker, newRpcs);
}
}
- public int size() {
- return table.size();
+ RoutingTable removeRpcs(final Collection<RouteIdentifier<?, ?, ?>> toRemove) {
+ final Set<RouteIdentifier<?, ?, ?>> 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() {
}
@Override
public String toString() {
- return "RoutingTable{" +
- "table=" + table +
- ", router=" + router +
- '}';
+ return "RoutingTable{" + "rpcs=" + rpcs + ", rpcInvoker=" + rpcInvoker + '}';
}
}
}
}