9068228ee5a75298e84d4d2e33d8552a8b2019c0
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / AbstractThreePhaseCommitMessage.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import com.google.common.base.Preconditions;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15
16 /**
17  * Base class for a 3PC message.
18  *
19  * @author Thomas Pantelis
20  */
21 public abstract class AbstractThreePhaseCommitMessage extends VersionedExternalizableMessage {
22     private static final long serialVersionUID = 1L;
23
24     private TransactionIdentifier transactionID;
25
26     protected AbstractThreePhaseCommitMessage() {
27     }
28
29     protected AbstractThreePhaseCommitMessage(final TransactionIdentifier transactionID, final short version) {
30         super(version);
31         this.transactionID = Preconditions.checkNotNull(transactionID);
32     }
33
34     public TransactionIdentifier getTransactionID() {
35         return transactionID;
36     }
37
38     @Override
39     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
40         super.readExternal(in);
41         transactionID = TransactionIdentifier.readFrom(in);
42     }
43
44     @Override
45     public void writeExternal(ObjectOutput out) throws IOException {
46         super.writeExternal(out);
47         transactionID.writeTo(out);
48     }
49
50     @Override
51     public String toString() {
52         return getClass().getSimpleName() + " [transactionID=" + transactionID + ", version=" + getVersion()
53                 + "]";
54     }
55 }