2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Optional;
13 import java.util.SortedSet;
14 import javax.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.api.schema.tree.DataTreeModification;
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}.
26 public final class ReadyLocalTransaction {
27 private final DataTreeModification modification;
28 private final TransactionIdentifier transactionId;
29 private final boolean doCommitOnReady;
31 private final SortedSet<String> participatingShardNames;
33 // The version of the remote system used only when needing to convert to BatchedModifications.
34 private short remoteVersion = DataStoreVersions.CURRENT_VERSION;
36 public ReadyLocalTransaction(final TransactionIdentifier transactionId, final DataTreeModification modification,
37 final boolean doCommitOnReady, Optional<SortedSet<String>> participatingShardNames) {
38 this.transactionId = requireNonNull(transactionId);
39 this.modification = requireNonNull(modification);
40 this.doCommitOnReady = doCommitOnReady;
41 this.participatingShardNames = requireNonNull(participatingShardNames).orElse(null);
44 public TransactionIdentifier getTransactionId() {
48 public DataTreeModification getModification() {
52 public boolean isDoCommitOnReady() {
53 return doCommitOnReady;
56 public short getRemoteVersion() {
60 public void setRemoteVersion(short remoteVersion) {
61 this.remoteVersion = remoteVersion;
64 public Optional<SortedSet<String>> getParticipatingShardNames() {
65 return Optional.ofNullable(participatingShardNames);