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=702d04571cb2b937386317d781894a2dddc946be;hp=9e69fa66df463c25f0c9c29562c9d1f015e642a8;hb=30e167cac18381b1cadc6eb666faabb2f509ee29;hpb=e9fce74e37472296faa2faf1acbd110b74196032 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 9e69fa66df..702d04571c 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,70 +8,91 @@ package org.opendaylight.controller.remote.rpc.registry; import akka.actor.ActorRef; -import com.google.common.base.Preconditions; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +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.remote.rpc.registry.gossip.BucketData; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; +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; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; -public class RoutingTable implements BucketData, Serializable { - private static final long serialVersionUID = 5592610415175278760L; +public final class RoutingTable extends AbstractRoutingTable { + private static final class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; - private final Map, Long> table; - private final ActorRef router; + @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "We deal with the field in serialization methods.") + private Collection rpcs; + private ActorRef opsInvoker; - private RoutingTable(final ActorRef router, final Map, Long> table) { - this.router = Preconditions.checkNotNull(router); - this.table = Preconditions.checkNotNull(table); - } + // 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 + } - RoutingTable(final ActorRef router) { - this(router, new HashMap<>()); - } + Proxy(final RoutingTable table) { + rpcs = table.getItems(); + opsInvoker = table.getInvoker(); + } - RoutingTable copy() { - return new RoutingTable(router, new HashMap<>(table)); - } + @Override + public void writeExternal(final ObjectOutput out) throws IOException { + out.writeObject(Serialization.serializedActorPath(opsInvoker)); - @Override - public Optional getWatchActor() { - return Optional.of(router); - } + 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(); - } + @Override + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + opsInvoker = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); - public void addRoute(final RpcRouter.RouteIdentifier routeId) { - table.put(routeId, System.currentTimeMillis()); - } + final NormalizedNodeDataInput nnin = NormalizedNodeDataInput.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 void removeRoute(final RpcRouter.RouteIdentifier routeId) { - table.remove(routeId); + private Object readResolve() { + return new RoutingTable(opsInvoker, rpcs); + } } - public boolean contains(final RpcRouter.RouteIdentifier routeId) { - return table.containsKey(routeId); - } + private static final long serialVersionUID = 1L; - public boolean isEmpty() { - return table.isEmpty(); + RoutingTable(final ActorRef invoker, final Collection table) { + super(invoker, table); } - public int size() { - return table.size(); + RoutingTable addRpcs(final Collection toAdd) { + final Set newRpcs = new HashSet<>(getItems()); + newRpcs.addAll(toAdd); + return new RoutingTable(getInvoker(), newRpcs); } - public ActorRef getRouter() { - return 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); } }