495a00a10d0a14bbc7184a68271676f21969ca22
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CommitTransaction.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 CommitTransaction extends AbstractThreePhaseCommitMessage {
15     private static final long serialVersionUID = 1L;
16
17     public CommitTransaction() {
18     }
19
20     public CommitTransaction(String transactionID, final short version) {
21         super(transactionID, version);
22     }
23
24     @Override
25     protected Object newLegacySerializedInstance() {
26         return ThreePhaseCommitCohortMessages.CommitTransaction.newBuilder().setTransactionId(
27                 getTransactionID()).build();
28     }
29
30     public static CommitTransaction fromSerializable(Object serializable) {
31         if(serializable instanceof CommitTransaction) {
32             return (CommitTransaction)serializable;
33         } else {
34             return new CommitTransaction(((ThreePhaseCommitCohortMessages.CommitTransaction)serializable).
35                     getTransactionId(), DataStoreVersions.LITHIUM_VERSION);
36         }
37     }
38
39     public static boolean isSerializedType(Object message) {
40         return message instanceof CommitTransaction ||
41                 message instanceof ThreePhaseCommitCohortMessages.CommitTransaction;
42     }
43 }