Bump upstream SNAPSHOTS
[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 static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import java.util.SortedSet;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
17 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
18
19 /**
20  * Message notifying the shard leader to apply modifications which have been
21  * prepared locally against its DataTree. This message is not directly serializable,
22  * simply because the leader and sender need to be on the same system. When it needs
23  * to be sent out to a remote system, it needs to be intercepted by {@link ReadyLocalTransactionSerializer}
24  * and turned into {@link BatchedModifications}.
25  */
26 public final class ReadyLocalTransaction {
27     private final DataTreeModification modification;
28     private final TransactionIdentifier transactionId;
29     private final boolean doCommitOnReady;
30     private final @Nullable SortedSet<String> participatingShardNames;
31
32     // The version of the remote system used only when needing to convert to BatchedModifications.
33     private short remoteVersion = DataStoreVersions.CURRENT_VERSION;
34
35     public ReadyLocalTransaction(final TransactionIdentifier transactionId, final DataTreeModification modification,
36             final boolean doCommitOnReady, final Optional<SortedSet<String>> participatingShardNames) {
37         this.transactionId = requireNonNull(transactionId);
38         this.modification = requireNonNull(modification);
39         this.doCommitOnReady = doCommitOnReady;
40         this.participatingShardNames = requireNonNull(participatingShardNames).orElse(null);
41     }
42
43     public TransactionIdentifier getTransactionId() {
44         return transactionId;
45     }
46
47     public DataTreeModification getModification() {
48         return modification;
49     }
50
51     public boolean isDoCommitOnReady() {
52         return doCommitOnReady;
53     }
54
55     public short getRemoteVersion() {
56         return remoteVersion;
57     }
58
59     public void setRemoteVersion(final short remoteVersion) {
60         this.remoteVersion = remoteVersion;
61     }
62
63     public Optional<SortedSet<String>> getParticipatingShardNames() {
64         return Optional.ofNullable(participatingShardNames);
65     }
66 }