Follow-up to protobuff deprecation
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CanCommitTransaction.java
index 526d60fc75b2571616b9c911d218faaba612b8f2..e0bf4489b48e9a151313d29617472fb1fbe9e3f1 100644 (file)
@@ -8,5 +8,37 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-public class CanCommitTransaction {
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
+import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
+
+public class CanCommitTransaction extends AbstractThreePhaseCommitMessage {
+    private static final long serialVersionUID = 1L;
+
+    public CanCommitTransaction() {
+    }
+
+    public CanCommitTransaction(String transactionID, final short version) {
+        super(transactionID, version);
+    }
+
+    @Deprecated
+    @Override
+    protected Object newLegacySerializedInstance() {
+        return ThreePhaseCommitCohortMessages.CanCommitTransaction.newBuilder().
+                setTransactionId(getTransactionID()).build();
+    }
+
+    public static CanCommitTransaction fromSerializable(Object serializable) {
+        if(serializable instanceof CanCommitTransaction) {
+            return (CanCommitTransaction)serializable;
+        } else {
+            return new CanCommitTransaction(((ThreePhaseCommitCohortMessages.CanCommitTransaction)serializable).
+                    getTransactionId(), DataStoreVersions.LITHIUM_VERSION);
+        }
+    }
+
+    public static boolean isSerializedType(Object message) {
+        return message instanceof CanCommitTransaction ||
+                message instanceof ThreePhaseCommitCohortMessages.CanCommitTransaction;
+    }
 }