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=8d67b3bdd311af7747657274d16717695de0eca1;hp=fa93a3b83f03153d4dd031ceda1f67bb6f3d4929;hb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;hpb=1447e0132075bbd3013aa41b98384a373bd82d1a 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 fa93a3b83f..8d67b3bdd3 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,78 +8,91 @@ package org.opendaylight.controller.remote.rpc.registry; import akka.actor.ActorRef; -import akka.japi.Option; -import akka.japi.Pair; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import akka.serialization.JavaSerializer; +import akka.serialization.Serialization; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.Set; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput; +import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; + +public final class RoutingTable extends AbstractRoutingTable { + private static final class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; + + @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "We deal with the field in serialization methods.") + private Collection rpcs; + private ActorRef opsInvoker; + + // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to + // be able to create instances via reflection. + @SuppressWarnings("checkstyle:RedundantModifier") + public Proxy() { + // For Externalizable + } -import org.opendaylight.controller.remote.rpc.registry.gossip.Copier; -import org.opendaylight.controller.sal.connector.api.RpcRouter; - -public class RoutingTable implements Copier, Serializable { - private static final long serialVersionUID = 5592610415175278760L; - - private final Map, Long> table = new HashMap<>(); - private ActorRef router; - - @Override - public RoutingTable copy() { - RoutingTable copy = new RoutingTable(); - copy.table.putAll(table); - copy.setRouter(this.getRouter()); - - return copy; - } + Proxy(final RoutingTable table) { + rpcs = table.getItems(); + opsInvoker = table.getInvoker(); + } - public Option> getRouterFor(RpcRouter.RouteIdentifier routeId){ - Long updatedTime = table.get(routeId); + @Override + public void writeExternal(final ObjectOutput out) throws IOException { + out.writeObject(Serialization.serializedActorPath(opsInvoker)); - if (updatedTime == null || router == null) { - return Option.none(); - } else { - return Option.option(new Pair<>(router, updatedTime)); + final NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out); + nnout.writeInt(rpcs.size()); + for (DOMRpcIdentifier id : rpcs) { + nnout.writeSchemaPath(id.getType()); + nnout.writeYangInstanceIdentifier(id.getContextReference()); + } } - } - - public Set> getRoutes() { - return table.keySet(); - } - public void addRoute(RpcRouter.RouteIdentifier routeId){ - table.put(routeId, System.currentTimeMillis()); - } + @Override + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + opsInvoker = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); - public void removeRoute(RpcRouter.RouteIdentifier routeId){ - table.remove(routeId); - } + final NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(in); + final int size = nnin.readInt(); + rpcs = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + rpcs.add(DOMRpcIdentifier.create(nnin.readSchemaPath(), nnin.readYangInstanceIdentifier())); + } + } - public boolean contains(RpcRouter.RouteIdentifier routeId){ - return table.containsKey(routeId); + private Object readResolve() { + return new RoutingTable(opsInvoker, rpcs); + } } - public boolean isEmpty(){ - return table.isEmpty(); - } + private static final long serialVersionUID = 1L; - public int size() { - return table.size(); + RoutingTable(final ActorRef invoker, final Collection table) { + super(invoker, table); } - public ActorRef getRouter() { - return router; + RoutingTable addRpcs(final Collection toAdd) { + final Set newRpcs = new HashSet<>(getItems()); + newRpcs.addAll(toAdd); + return new RoutingTable(getInvoker(), newRpcs); } - public void setRouter(ActorRef router) { - this.router = router; + RoutingTable removeRpcs(final Collection toRemove) { + final Set newRpcs = new HashSet<>(getItems()); + newRpcs.removeAll(toRemove); + return new RoutingTable(getInvoker(), newRpcs); } @Override - public String toString() { - return "RoutingTable{" + - "table=" + table + - ", router=" + router + - '}'; + Object writeReplace() { + return new Proxy(this); } }