BUG-5280: remove support for talking to pre-Boron clients
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CanCommitTransactionReply.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.datastore.DataStoreVersions;
16
17 public class CanCommitTransactionReply extends VersionedExternalizableMessage {
18     private static final CanCommitTransactionReply YES =
19             new CanCommitTransactionReply(true, DataStoreVersions.CURRENT_VERSION);
20     private static final CanCommitTransactionReply NO =
21             new CanCommitTransactionReply(false, DataStoreVersions.CURRENT_VERSION);
22
23     private boolean canCommit;
24
25     public CanCommitTransactionReply() {
26     }
27
28     private CanCommitTransactionReply(final boolean canCommit, final short version) {
29         super(version);
30         this.canCommit = canCommit;
31     }
32
33     public boolean getCanCommit() {
34         return canCommit;
35     }
36
37     @Override
38     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
39         super.readExternal(in);
40         canCommit = in.readBoolean();
41     }
42
43     @Override
44     public void writeExternal(ObjectOutput out) throws IOException {
45         super.writeExternal(out);
46         out.writeBoolean(canCommit);
47     }
48
49     @Override
50     public String toString() {
51         return "CanCommitTransactionReply [canCommit=" + canCommit + ", version=" + getVersion() + "]";
52     }
53
54     public static CanCommitTransactionReply yes(short version) {
55         return version == DataStoreVersions.CURRENT_VERSION ? YES : new CanCommitTransactionReply(true, version);
56     }
57
58     public static CanCommitTransactionReply no(short version) {
59         return version == DataStoreVersions.CURRENT_VERSION ? NO : new CanCommitTransactionReply(false, version);
60     }
61
62     public static CanCommitTransactionReply fromSerializable(final Object serializable) {
63         Preconditions.checkArgument(serializable instanceof CanCommitTransactionReply);
64         return (CanCommitTransactionReply)serializable;
65     }
66
67     public static boolean isSerializedType(Object message) {
68         return message instanceof CanCommitTransactionReply;
69     }
70 }