9556087601fe013ea914d4eb5a65713ebbe22678
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ReadyLocalTransaction.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
12 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
14
15 /**
16  * Message notifying the shard leader to apply modifications which have been
17  * prepared locally against its DataTree. This message is not directly serializable,
18  * simply because the leader and sender need to be on the same system. When it needs
19  * to be sent out to a remote system, it needs to be intercepted by {@link ReadyLocalTransactionSerializer}
20  * and turned into {@link BatchedModifications}.
21  */
22 public final class ReadyLocalTransaction {
23     private final DataTreeModification modification;
24     private final TransactionIdentifier transactionID;
25     private final boolean doCommitOnReady;
26
27     // The version of the remote system used only when needing to convert to BatchedModifications.
28     private short remoteVersion = DataStoreVersions.CURRENT_VERSION;
29
30     public ReadyLocalTransaction(final TransactionIdentifier transactionID, final DataTreeModification modification,
31             final boolean doCommitOnReady) {
32         this.transactionID = Preconditions.checkNotNull(transactionID);
33         this.modification = Preconditions.checkNotNull(modification);
34         this.doCommitOnReady = doCommitOnReady;
35     }
36
37     public TransactionIdentifier getTransactionID() {
38         return transactionID;
39     }
40
41     public DataTreeModification getModification() {
42         return modification;
43     }
44
45     public boolean isDoCommitOnReady() {
46         return doCommitOnReady;
47     }
48
49     public short getRemoteVersion() {
50         return remoteVersion;
51     }
52
53     public void setRemoteVersion(short remoteVersion) {
54         this.remoteVersion = remoteVersion;
55     }
56 }