Change BatchedModifications to extend VersionedExternalizableMessage 97/35097/8
authorTom Pantelis <tpanteli@brocade.com>
Fri, 19 Feb 2016 13:23:07 +0000 (08:23 -0500)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 23 Feb 2016 11:08:40 +0000 (06:08 -0500)
To be consistent with other transaction messages, changed
BatchedModifications to extend VersionedExternalizableMessage
via MutableCompositeModification.

Change-Id: I7dbf39f59b0e6263c38a062826eb6341b7cb16d1
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/BatchedModifications.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/CompositeModificationByteStringPayloadTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/BatchedModificationsTest.java

index f95473f8a6b3edbdd5ed6cfb5dbe7ad789f55593..a4b9d4c8becbefea8aeff012bd9805fbb287a4cb 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.controller.cluster.datastore.modification.MutableComposi
  *
  * @author Thomas Pantelis
  */
-public class BatchedModifications extends MutableCompositeModification implements SerializableMessage {
+public class BatchedModifications extends MutableCompositeModification {
     private static final long serialVersionUID = 1L;
 
     private boolean ready;
@@ -88,11 +88,6 @@ public class BatchedModifications extends MutableCompositeModification implement
         out.writeBoolean(doCommitOnReady);
     }
 
-    @Override
-    public Object toSerializable() {
-        return this;
-    }
-
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
index c3746e03d27ceb1924feb2268a4828f0983badc8..d7e89597e2950473d056f0c806d8af3ca7b114c5 100644 (file)
@@ -14,6 +14,7 @@ import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
+import org.opendaylight.controller.cluster.datastore.messages.VersionedExternalizableMessage;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
@@ -25,18 +26,17 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification
  * MutableCompositeModification is just a mutable version of a
  * CompositeModification {@link org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification#addModification(Modification)}
  */
-public class MutableCompositeModification implements CompositeModification {
+public class MutableCompositeModification extends VersionedExternalizableMessage implements CompositeModification {
     private static final long serialVersionUID = 1L;
 
     private final List<Modification> modifications = new ArrayList<>();
-    private short version;
 
     public MutableCompositeModification() {
         this(DataStoreVersions.CURRENT_VERSION);
     }
 
     public MutableCompositeModification(short version) {
-        this.version = version;
+        super(version);
     }
 
     @Override
@@ -58,14 +58,6 @@ public class MutableCompositeModification implements CompositeModification {
         return COMPOSITE;
     }
 
-    public short getVersion() {
-        return version;
-    }
-
-    public void setVersion(short version) {
-        this.version = version;
-    }
-
     /**
      * Add a new Modification to the list of Modifications represented by this
      * composite
@@ -83,7 +75,7 @@ public class MutableCompositeModification implements CompositeModification {
 
     @Override
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        version = in.readShort();
+        super.readExternal(in);
 
         int size = in.readInt();
 
@@ -96,15 +88,15 @@ public class MutableCompositeModification implements CompositeModification {
                 byte type = in.readByte();
                 switch(type) {
                 case Modification.WRITE:
-                    modifications.add(WriteModification.fromStream(in, version));
+                    modifications.add(WriteModification.fromStream(in, getVersion()));
                     break;
 
                 case Modification.MERGE:
-                    modifications.add(MergeModification.fromStream(in, version));
+                    modifications.add(MergeModification.fromStream(in, getVersion()));
                     break;
 
                 case Modification.DELETE:
-                    modifications.add(DeleteModification.fromStream(in, version));
+                    modifications.add(DeleteModification.fromStream(in, getVersion()));
                     break;
                 }
             }
@@ -115,7 +107,7 @@ public class MutableCompositeModification implements CompositeModification {
 
     @Override
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeShort(version);
+        super.writeExternal(out);
 
         out.writeInt(modifications.size());
 
@@ -135,17 +127,21 @@ public class MutableCompositeModification implements CompositeModification {
 
     @Override
     @Deprecated
-    public Object toSerializable() {
-        PersistentMessages.CompositeModification.Builder builder =
-                PersistentMessages.CompositeModification.newBuilder();
+    protected Object newLegacySerializedInstance() {
+        if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
+            return this;
+        } else {
+            PersistentMessages.CompositeModification.Builder builder =
+                    PersistentMessages.CompositeModification.newBuilder();
 
-        builder.setTimeStamp(System.nanoTime());
+            builder.setTimeStamp(System.nanoTime());
 
-        for (Modification m : modifications) {
-            builder.addModification((PersistentMessages.Modification) m.toSerializable());
-        }
+            for (Modification m : modifications) {
+                builder.addModification((PersistentMessages.Modification) m.toSerializable());
+            }
 
-        return builder.build();
+            return builder.build();
+        }
     }
 
     public static MutableCompositeModification fromSerializable(Object serializable) {
@@ -156,6 +152,7 @@ public class MutableCompositeModification implements CompositeModification {
         }
     }
 
+    @Deprecated
     private static MutableCompositeModification fromLegacySerializable(Object serializable) {
         PersistentMessages.CompositeModification o = (PersistentMessages.CompositeModification) serializable;
         MutableCompositeModification compositeModification = new MutableCompositeModification();
index 98bc9706fbf201d1f3cb266159a2e209f0542735..e1e968c02c2a233a6bafbc900b50a75507042026 100644 (file)
@@ -27,7 +27,7 @@ public class CompositeModificationByteStringPayloadTest {
                         .containerNode(TestModel.TEST_QNAME));
 
         MutableCompositeModification compositeModification =
-                new MutableCompositeModification();
+                new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
 
         compositeModification.addModification(writeModification);
 
index 1cf45cef01e888504af95dbe4675dcb67d3f858a..c9797b5414589018b83baeffeb307b5fec81585f 100644 (file)
@@ -16,6 +16,7 @@ import java.util.HashSet;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.cluster.datastore.Shard;
 import org.opendaylight.controller.cluster.datastore.ShardTestKit;
 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
@@ -49,7 +50,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFac
 public class PreLithiumShardTest extends AbstractShardTest {
 
     private static CompositeModificationPayload newLegacyPayload(final Modification... mods) {
-        MutableCompositeModification compMod = new MutableCompositeModification();
+        MutableCompositeModification compMod = new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
         for(Modification mod: mods) {
             compMod.addModification(mod);
         }
@@ -58,7 +59,7 @@ public class PreLithiumShardTest extends AbstractShardTest {
     }
 
     private static CompositeModificationByteStringPayload newLegacyByteStringPayload(final Modification... mods) {
-        MutableCompositeModification compMod = new MutableCompositeModification();
+        MutableCompositeModification compMod = new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
         for(Modification mod: mods) {
             compMod.addModification(mod);
         }
index 1df8e9775b89219439f31cbafbec69e675a353d8..4a63666e7ce2c17f180325a48721d475dce0c1f2 100644 (file)
@@ -75,11 +75,11 @@ public class BatchedModificationsTest {
 
         // Test with different params.
 
-        batched = new BatchedModifications("tx2", (short)10, null);
+        batched = new BatchedModifications("tx2", (short)10000, null);
 
         clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());
 
-        assertEquals("getVersion", 10, clone.getVersion());
+        assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
         assertEquals("getTransactionID", "tx2", clone.getTransactionID());
         assertEquals("getTransactionChainID", "", clone.getTransactionChainID());
         assertEquals("isReady", false, clone.isReady());