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=f0795a3a42b89fd83fd6e37e6c2141b7c653c977;hp=0e68eb87096828f89892b338969aaaea24f13954;hb=1d0370feb32b84119bf4c570b9e6e9abbe8d9511;hpb=a884499896d6a146743272b08b4a7e504d9e8b9e 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 0e68eb8709..f0795a3a42 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,69 +8,96 @@ package org.opendaylight.controller.remote.rpc.registry; import akka.actor.ActorRef; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import java.io.Serializable; +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.Optional; import java.util.Set; -import org.opendaylight.controller.remote.rpc.registry.gossip.BucketData; -import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; +import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; -public class RoutingTable implements BucketData, Serializable { - private static final long serialVersionUID = 1L; +public final class RoutingTable extends AbstractRoutingTable { + private static final class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; - private final Set> rpcs; - private final ActorRef rpcInvoker; + @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "We deal with the field in serialization methods.") + private Collection rpcs; + private ActorRef opsInvoker; - private RoutingTable(final ActorRef rpcInvoker, final Set> table) { - this.rpcInvoker = Preconditions.checkNotNull(rpcInvoker); - this.rpcs = ImmutableSet.copyOf(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 rpcInvoker) { - this(rpcInvoker, ImmutableSet.of()); - } + Proxy(final RoutingTable table) { + rpcs = table.getItems(); + opsInvoker = table.getInvoker(); + } - @Override - public Optional getWatchActor() { - return Optional.of(rpcInvoker); - } + @Override + public void writeExternal(final ObjectOutput out) throws IOException { + out.writeObject(Serialization.serializedActorPath(opsInvoker)); - public Set> getRoutes() { - return rpcs; - } + try (NormalizedNodeDataOutput nnout = NormalizedNodeStreamVersion.current().newDataOutput(out)) { + nnout.writeInt(rpcs.size()); + for (DOMRpcIdentifier id : rpcs) { + // TODO: we should be able to get by with just a QName + nnout.writeSchemaNodeIdentifier(Absolute.of(id.getType())); + nnout.writeYangInstanceIdentifier(id.getContextReference()); + } + } + } - ActorRef getRpcInvoker() { - return rpcInvoker; - } + @Override + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + opsInvoker = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); - RoutingTable addRpcs(final Collection> toAdd) { - final Set> newRpcs = new HashSet<>(rpcs); - newRpcs.addAll(toAdd); - return new RoutingTable(rpcInvoker, newRpcs); + final NormalizedNodeDataInput nnin = NormalizedNodeDataInput.newDataInput(in); + final int size = nnin.readInt(); + rpcs = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + // TODO: we should be able to get by with just a QName + rpcs.add(DOMRpcIdentifier.create(nnin.readSchemaNodeIdentifier().firstNodeIdentifier(), + nnin.readYangInstanceIdentifier())); + } + } + + private Object readResolve() { + return new RoutingTable(opsInvoker, rpcs); + } } - RoutingTable removeRpcs(final Collection> toRemove) { - final Set> newRpcs = new HashSet<>(rpcs); - newRpcs.removeAll(toRemove); - return new RoutingTable(rpcInvoker, newRpcs); + private static final long serialVersionUID = 1L; + + RoutingTable(final ActorRef invoker, final Collection table) { + super(invoker, table); } - @VisibleForTesting - boolean contains(final RouteIdentifier routeId) { - return rpcs.contains(routeId); + RoutingTable addRpcs(final Collection toAdd) { + final Set newRpcs = new HashSet<>(getItems()); + newRpcs.addAll(toAdd); + return new RoutingTable(getInvoker(), newRpcs); } - @VisibleForTesting - int size() { - return rpcs.size(); + 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{" + "rpcs=" + rpcs + ", rpcInvoker=" + rpcInvoker + '}'; + Object writeReplace() { + return new Proxy(this); } }