Define DataStoreVersions.MAGNESIUM_VERSION
[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 static java.util.Objects.requireNonNull;
11
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16
17 /**
18  * Base class for a 3PC message.
19  *
20  * @author Thomas Pantelis
21  */
22 public abstract class AbstractThreePhaseCommitMessage extends VersionedExternalizableMessage {
23     private static final long serialVersionUID = 1L;
24
25     private TransactionIdentifier transactionId;
26
27     protected AbstractThreePhaseCommitMessage() {
28     }
29
30     protected AbstractThreePhaseCommitMessage(final TransactionIdentifier transactionId, final short version) {
31         super(version);
32         this.transactionId = requireNonNull(transactionId);
33     }
34
35     public TransactionIdentifier getTransactionId() {
36         return transactionId;
37     }
38
39     @Override
40     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
41         super.readExternal(in);
42         transactionId = TransactionIdentifier.readFrom(in);
43     }
44
45     @Override
46     public void writeExternal(final ObjectOutput out) throws IOException {
47         super.writeExternal(out);
48         transactionId.writeTo(out);
49     }
50
51     @Override
52     public String toString() {
53         return getClass().getSimpleName() + " [transactionId=" + transactionId + ", version=" + getVersion() + "]";
54     }
55 }