Deprecate CloseTransactionChain protobuff message
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CloseTransactionChain.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 java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages;
16
17 public class CloseTransactionChain extends VersionedExternalizableMessage {
18     private static final long serialVersionUID = 1L;
19
20     private String transactionChainId;
21
22     public CloseTransactionChain() {
23     }
24
25     public CloseTransactionChain(final String transactionChainId, final short version) {
26         super(version);
27         this.transactionChainId = transactionChainId;
28     }
29
30     public String getTransactionChainId() {
31         return transactionChainId;
32     }
33
34     @Override
35     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
36         super.readExternal(in);
37         transactionChainId = in.readUTF();
38     }
39
40     @Override
41     public void writeExternal(ObjectOutput out) throws IOException {
42         super.writeExternal(out);
43         out.writeUTF(transactionChainId);
44     }
45
46     @Override
47     public Object toSerializable() {
48         if(getVersion() >= DataStoreVersions.BORON_VERSION) {
49             return this;
50         } else {
51             return ShardTransactionChainMessages.CloseTransactionChain.newBuilder()
52                 .setTransactionChainId(transactionChainId).build();
53         }
54     }
55
56     public static CloseTransactionChain fromSerializable(final Object serializable){
57         if(serializable instanceof CloseTransactionChain) {
58             return (CloseTransactionChain)serializable;
59         } else {
60             ShardTransactionChainMessages.CloseTransactionChain closeTransactionChain =
61                     (ShardTransactionChainMessages.CloseTransactionChain) serializable;
62             return new CloseTransactionChain(closeTransactionChain.getTransactionChainId(),
63                     DataStoreVersions.LITHIUM_VERSION);
64         }
65     }
66
67     public static boolean isSerializedType(Object message) {
68         return message instanceof CloseTransactionChain ||
69                 message instanceof ShardTransactionChainMessages.CloseTransactionChain;
70     }
71 }