Bug 7521: Convert DatastoreSnapshot.ShardSnapshot to store Snapshot
[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 com.google.common.base.Preconditions;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16
17 public class CreateTransactionReply extends VersionedExternalizableMessage {
18     private static final long serialVersionUID = 1L;
19
20     private String transactionPath;
21     private TransactionIdentifier transactionId;
22
23     public CreateTransactionReply() {
24     }
25
26     public CreateTransactionReply(final String transactionPath, final TransactionIdentifier transactionId,
27             final short version) {
28         super(version);
29         this.transactionPath = Preconditions.checkNotNull(transactionPath);
30         this.transactionId = Preconditions.checkNotNull(transactionId);
31     }
32
33     public String getTransactionPath() {
34         return transactionPath;
35     }
36
37     public TransactionIdentifier getTransactionId() {
38         return transactionId;
39     }
40
41     @Override
42     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
43         super.readExternal(in);
44         transactionId = TransactionIdentifier.readFrom(in);
45         transactionPath = in.readUTF();
46     }
47
48     @Override
49     public void writeExternal(ObjectOutput out) throws IOException {
50         super.writeExternal(out);
51         transactionId.writeTo(out);
52         out.writeUTF(transactionPath);
53     }
54
55     @Override
56     public String toString() {
57         StringBuilder builder = new StringBuilder();
58         builder.append("CreateTransactionReply [transactionPath=").append(transactionPath).append(", transactionId=")
59                 .append(transactionId).append(", version=").append(getVersion()).append("]");
60         return builder.toString();
61     }
62
63     public static CreateTransactionReply fromSerializable(Object serializable) {
64         Preconditions.checkNotNull(serializable instanceof CreateTransactionReply);
65         return (CreateTransactionReply)serializable;
66     }
67
68     public static boolean isSerializedType(Object message) {
69         return message instanceof CreateTransactionReply;
70     }
71 }