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 f95473f..a4b9d4c 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 c3746e0..d7e8959 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 98bc970..e1e968c 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 1cf45ce..c9797b5 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 1df8e97..4a63666 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());

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.