Merge changes I114cbac1,I45c2e7cd
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ReadyTransactionReply.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 ReadyTransactionReply extends VersionedExternalizableMessage {
18     private static final long serialVersionUID = 1L;
19
20     public static final Class<ShardTransactionMessages.ReadyTransactionReply> SERIALIZABLE_CLASS =
21             ShardTransactionMessages.ReadyTransactionReply.class;
22
23     private String cohortPath;
24
25     public ReadyTransactionReply() {
26     }
27
28     public ReadyTransactionReply(String cohortPath) {
29         this(cohortPath, DataStoreVersions.CURRENT_VERSION);
30     }
31
32     public ReadyTransactionReply(String cohortPath, short version) {
33         super(version);
34         this.cohortPath = cohortPath;
35     }
36
37     public String getCohortPath() {
38         return cohortPath;
39     }
40
41     @Override
42     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
43         super.readExternal(in);
44         cohortPath = in.readUTF();
45     }
46
47     @Override
48     public void writeExternal(ObjectOutput out) throws IOException {
49         super.writeExternal(out);
50         out.writeUTF(cohortPath);
51     }
52
53     @Override
54     public Object toSerializable() {
55         if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
56             return this;
57         } else {
58             return ShardTransactionMessages.ReadyTransactionReply.newBuilder().setActorPath(cohortPath).build();
59         }
60     }
61
62     public static ReadyTransactionReply fromSerializable(Object serializable) {
63         if(serializable instanceof ReadyTransactionReply) {
64             return (ReadyTransactionReply)serializable;
65         } else {
66             ShardTransactionMessages.ReadyTransactionReply o =
67                     (ShardTransactionMessages.ReadyTransactionReply) serializable;
68             return new ReadyTransactionReply(o.getActorPath(), DataStoreVersions.HELIUM_2_VERSION);
69         }
70     }
71
72     public static boolean isSerializedType(Object message) {
73         return message instanceof ReadyTransactionReply ||
74                message instanceof ShardTransactionMessages.ReadyTransactionReply;
75     }
76 }