X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fconfig%2FPrefixShardConfiguration.java;h=c387fe4ba247ae22ec9bb4350ebba945c7169c5d;hb=a7da626a1de6eaa413cb33211d6aaccaaf1d57ab;hp=6b79d548f91dfbc0a848fe9c63607c719bb17bcd;hpb=c1336f9b497bc6867536a24f629c3f0b002ccb2f;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java index 6b79d548f9..c387fe4ba2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java @@ -8,19 +8,68 @@ package org.opendaylight.controller.cluster.datastore.config; -import akka.cluster.ddata.ReplicatedData; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; /** * Configuration for prefix based shards. */ -public class PrefixShardConfiguration implements ReplicatedData, Serializable { +public class PrefixShardConfiguration implements Serializable { + private static final class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; + + private PrefixShardConfiguration prefixShardConfiguration; + + // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't + // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection. + @SuppressWarnings("checkstyle:RedundantModifier") + public Proxy() { + } + + Proxy(final PrefixShardConfiguration prefixShardConfiguration) { + this.prefixShardConfiguration = prefixShardConfiguration; + } + + @Override + public void writeExternal(final ObjectOutput objectOutput) throws IOException { + objectOutput.writeObject(prefixShardConfiguration.getPrefix()); + objectOutput.writeObject(prefixShardConfiguration.getShardStrategyName()); + + objectOutput.writeInt(prefixShardConfiguration.getShardMemberNames().size()); + for (MemberName name : prefixShardConfiguration.getShardMemberNames()) { + name.writeTo(objectOutput); + } + } + + @Override + public void readExternal(final ObjectInput objectInput) throws IOException, ClassNotFoundException { + final DOMDataTreeIdentifier localPrefix = (DOMDataTreeIdentifier) objectInput.readObject(); + final String localStrategyName = (String) objectInput.readObject(); + + final int size = objectInput.readInt(); + final Collection localShardMemberNames = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + localShardMemberNames.add(MemberName.readFrom(objectInput)); + } + + prefixShardConfiguration = new PrefixShardConfiguration(localPrefix, localStrategyName, + localShardMemberNames); + } + + private Object readResolve() { + return prefixShardConfiguration; + } + } + private static final long serialVersionUID = 1L; private final DOMDataTreeIdentifier prefix; @@ -57,23 +106,7 @@ public class PrefixShardConfiguration implements ReplicatedData, Serializable { + '}'; } - public String toDataMapKey() { - return "prefix=" + prefix; - } - - @Override - public ReplicatedData merge(final ReplicatedData replicatedData) { - if (!(replicatedData instanceof PrefixShardConfiguration)) { - throw new IllegalStateException("replicatedData expected to be instance of PrefixShardConfiguration"); - } - final PrefixShardConfiguration entry = (PrefixShardConfiguration) replicatedData; - if (!entry.getPrefix().equals(prefix)) { - // this should never happen since the key is the prefix - // if it does just return current? - return this; - } - final HashSet members = new HashSet<>(shardMemberNames); - members.addAll(entry.getShardMemberNames()); - return new PrefixShardConfiguration(prefix, shardStrategyName, members); + private Object writeReplace() { + return new Proxy(this); } }