BUG-4869: use odl-lmax feature
[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 org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
12
13 public class CanCommitTransactionReply implements SerializableMessage {
14     public static final Class<ThreePhaseCommitCohortMessages.CanCommitTransactionReply> SERIALIZABLE_CLASS =
15             ThreePhaseCommitCohortMessages.CanCommitTransactionReply.class;
16
17     public static final CanCommitTransactionReply YES = new CanCommitTransactionReply(true);
18     public static final CanCommitTransactionReply NO = new CanCommitTransactionReply(false);
19
20     private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply YES_SERIALIZED =
21             ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(true).build();
22
23     private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply NO_SERIALIZED =
24             ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(false).build();
25
26     private final boolean canCommit;
27
28     private CanCommitTransactionReply(final boolean canCommit) {
29         this.canCommit = canCommit;
30     }
31
32     public boolean getCanCommit() {
33         return canCommit;
34     }
35
36     @Override
37     public Object toSerializable() {
38         return canCommit ? YES_SERIALIZED : NO_SERIALIZED;
39     }
40
41     public static CanCommitTransactionReply fromSerializable(final Object message) {
42         ThreePhaseCommitCohortMessages.CanCommitTransactionReply serialized =
43                 (ThreePhaseCommitCohortMessages.CanCommitTransactionReply) message;
44         return serialized.getCanCommit() ? YES : NO;
45     }
46 }