Deprecate CreateTransaction protobuff message
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CreateTransactionReply.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.ShardTransactionMessages;
16
17 public class CreateTransactionReply extends VersionedExternalizableMessage {
18     private static final long serialVersionUID = 1L;
19
20     private String transactionPath;
21     private String transactionId;
22
23     public CreateTransactionReply() {
24     }
25
26     public CreateTransactionReply(final String transactionPath, final String transactionId, final short version) {
27         super(version);
28         this.transactionPath = transactionPath;
29         this.transactionId = transactionId;
30     }
31
32     public String getTransactionPath() {
33         return transactionPath;
34     }
35
36     public String getTransactionId() {
37         return transactionId;
38     }
39
40     @Override
41     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
42         super.readExternal(in);
43         transactionId = in.readUTF();
44         transactionPath = in.readUTF();
45     }
46
47     @Override
48     public void writeExternal(ObjectOutput out) throws IOException {
49         super.writeExternal(out);
50         out.writeUTF(transactionId);
51         out.writeUTF(transactionPath);
52     }
53
54     @Override
55     public Object toSerializable() {
56         if(getVersion() >= DataStoreVersions.BORON_VERSION) {
57             return this;
58         } else {
59             return ShardTransactionMessages.CreateTransactionReply.newBuilder().setTransactionActorPath(transactionPath)
60                     .setTransactionId(transactionId).setMessageVersion(getVersion()).build();
61         }
62     }
63
64     @Override
65     public String toString() {
66         StringBuilder builder = new StringBuilder();
67         builder.append("CreateTransactionReply [transactionPath=").append(transactionPath).append(", transactionId=")
68                 .append(transactionId).append(", version=").append(getVersion()).append("]");
69         return builder.toString();
70     }
71
72     public static CreateTransactionReply fromSerializable(Object serializable) {
73         if(serializable instanceof CreateTransactionReply) {
74             return (CreateTransactionReply)serializable;
75         } else {
76             ShardTransactionMessages.CreateTransactionReply o =
77                     (ShardTransactionMessages.CreateTransactionReply) serializable;
78             return new CreateTransactionReply(o.getTransactionActorPath(), o.getTransactionId(),
79                     (short)o.getMessageVersion());
80         }
81     }
82
83     public static boolean isSerializedType(Object message) {
84         return message instanceof CreateTransactionReply ||
85                 message instanceof ShardTransactionMessages.CreateTransactionReply;
86     }
87 }