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