Follow-up to protobuff deprecation
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / AbortTransaction.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
13
14 public class AbortTransaction extends AbstractThreePhaseCommitMessage {
15     private static final long serialVersionUID = 1L;
16
17     public AbortTransaction() {
18     }
19
20     public AbortTransaction(String transactionID, final short version) {
21         super(transactionID, version);
22     }
23
24     @Deprecated
25     @Override
26     protected Object newLegacySerializedInstance() {
27         return ThreePhaseCommitCohortMessages.AbortTransaction.newBuilder().
28                 setTransactionId(getTransactionID()).build();
29     }
30
31     public static AbortTransaction fromSerializable(Object serializable) {
32         if(serializable instanceof AbortTransaction) {
33             return (AbortTransaction)serializable;
34         } else {
35             return new AbortTransaction(((ThreePhaseCommitCohortMessages.AbortTransaction)serializable).
36                     getTransactionId(), DataStoreVersions.LITHIUM_VERSION);
37         }
38     }
39
40     public static boolean isSerializedType(Object message) {
41         return message instanceof AbortTransaction ||
42                 message instanceof ThreePhaseCommitCohortMessages.AbortTransaction;
43     }
44 }