Bug 2265: Use new NormalizedNode streaming in messages
[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 final boolean canCommit;
21     private final Object serializedMessage;
22
23     private CanCommitTransactionReply(final boolean canCommit) {
24         this.canCommit = canCommit;
25         this.serializedMessage = ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().
26                 setCanCommit(canCommit).build();
27     }
28
29     public boolean getCanCommit() {
30         return canCommit;
31     }
32
33     @Override
34     public Object toSerializable() {
35         return serializedMessage;
36     }
37
38     public static CanCommitTransactionReply fromSerializable(final Object message) {
39         ThreePhaseCommitCohortMessages.CanCommitTransactionReply serialized =
40                 (ThreePhaseCommitCohortMessages.CanCommitTransactionReply) message;
41         return serialized.getCanCommit() ? YES : NO;
42     }
43 }