Merge changes I880310f2,I9f437328,I552372db,I587fb203,I05f0bd94, ...
[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 org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
13
14 public class CreateTransactionReply implements SerializableMessage {
15
16     public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.CreateTransactionReply.class;
17     private final String transactionPath;
18     private final String transactionId;
19     private final short version;
20
21     public CreateTransactionReply(String transactionPath, String transactionId) {
22         this(transactionPath, transactionId, DataStoreVersions.CURRENT_VERSION);
23     }
24
25     public CreateTransactionReply(final String transactionPath,
26                                   final String transactionId, final short version) {
27         this.transactionPath = transactionPath;
28         this.transactionId = transactionId;
29         this.version = version;
30     }
31
32
33     public String getTransactionPath() {
34         return transactionPath;
35     }
36
37     public String getTransactionId() {
38         return transactionId;
39     }
40
41     public short getVersion() {
42         return version;
43     }
44
45     @Override
46     public Object toSerializable(){
47         return ShardTransactionMessages.CreateTransactionReply.newBuilder()
48             .setTransactionActorPath(transactionPath)
49             .setTransactionId(transactionId)
50             .setMessageVersion(version)
51             .build();
52     }
53
54     public static CreateTransactionReply fromSerializable(Object serializable){
55         ShardTransactionMessages.CreateTransactionReply o = (ShardTransactionMessages.CreateTransactionReply) serializable;
56         return new CreateTransactionReply(o.getTransactionActorPath(), o.getTransactionId(),
57                 (short)o.getMessageVersion());
58     }
59
60 }