Deprecate 3PC protobuff messages
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / AbortTransaction.java
index 4515bd70427a6eca892bb61115817941684d0a1c..e70ced86e3f9f8ab989a528e4906fc725c73d1a2 100644 (file)
@@ -8,13 +8,36 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
 
-public class AbortTransaction implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.AbortTransaction.class;
+public class AbortTransaction extends AbstractThreePhaseCommitMessage {
+    private static final long serialVersionUID = 1L;
 
-  @Override
-  public Object toSerializable() {
-    return ThreePhaseCommitCohortMessages.AbortTransaction.newBuilder().build();
-  }
+    public AbortTransaction() {
+    }
+
+    public AbortTransaction(String transactionID, final short version) {
+        super(transactionID, version);
+    }
+
+    @Override
+    protected Object newLegacySerializedInstance() {
+        return ThreePhaseCommitCohortMessages.AbortTransaction.newBuilder().
+                setTransactionId(getTransactionID()).build();
+    }
+
+    public static AbortTransaction fromSerializable(Object serializable) {
+        if(serializable instanceof AbortTransaction) {
+            return (AbortTransaction)serializable;
+        } else {
+            return new AbortTransaction(((ThreePhaseCommitCohortMessages.AbortTransaction)serializable).
+                    getTransactionId(), DataStoreVersions.LITHIUM_VERSION);
+        }
+    }
+
+    public static boolean isSerializedType(Object message) {
+        return message instanceof AbortTransaction ||
+                message instanceof ThreePhaseCommitCohortMessages.AbortTransaction;
+    }
 }