Remove deprecated MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / config / PrefixShardConfiguration.java
index 6b79d548f91dfbc0a848fe9c63607c719bb17bcd..dc6db2c6beeca669de540c1e2fa91ab4ac88844c 100644 (file)
@@ -5,22 +5,71 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore.config;
 
-import akka.cluster.ddata.ReplicatedData;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 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<MemberName> 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;
@@ -30,8 +79,8 @@ public class PrefixShardConfiguration implements ReplicatedData, Serializable {
     public PrefixShardConfiguration(final DOMDataTreeIdentifier prefix,
                                     final String shardStrategyName,
                                     final Collection<MemberName> shardMemberNames) {
-        this.prefix = Preconditions.checkNotNull(prefix);
-        this.shardStrategyName = Preconditions.checkNotNull(shardStrategyName);
+        this.prefix = requireNonNull(prefix);
+        this.shardStrategyName = requireNonNull(shardStrategyName);
         this.shardMemberNames = ImmutableSet.copyOf(shardMemberNames);
     }
 
@@ -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<MemberName> members = new HashSet<>(shardMemberNames);
-        members.addAll(entry.getShardMemberNames());
-        return new PrefixShardConfiguration(prefix, shardStrategyName, members);
+    private Object writeReplace() {
+        return new Proxy(this);
     }
 }