2 * Copyright (c) 2016 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.access.commands;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.ActorRef;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
23 * Request to commit a local transaction. Since local transactions do not introduce state on the backend until they
24 * are ready, this message carries a complete set of modifications.
26 * @author Robert Varga
29 public final class CommitLocalTransactionRequest
30 extends AbstractLocalTransactionRequest<CommitLocalTransactionRequest> {
31 private static final long serialVersionUID = 1L;
33 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
34 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
35 + "aren't serialized. FindBugs does not recognize this.")
36 private final DataTreeModification mod;
37 private final Exception delayedFailure;
38 private final boolean coordinated;
40 public CommitLocalTransactionRequest(final @NonNull TransactionIdentifier identifier, final long sequence,
41 final @NonNull ActorRef replyTo, final @NonNull DataTreeModification mod,
42 final @Nullable Exception delayedFailure, final boolean coordinated) {
43 super(identifier, sequence, replyTo);
44 this.mod = requireNonNull(mod);
45 this.delayedFailure = delayedFailure;
46 this.coordinated = coordinated;
50 * Return the delayed error detected on the frontend. If this error is present, it will be reported as the result
51 * of the first step of the commit process.
53 * @return Delayed failure, if present.
55 public Optional<Exception> getDelayedFailure() {
56 return Optional.ofNullable(delayedFailure);
59 public DataTreeModification getModification() {
64 * Indicate if this is a coordinated, multi-backend request. If this method returns true, the backend must
65 * act as a cohort participating in the three-phase commit (3PC) protocol to commit this transaction. If this
66 * method returns false, the backend should proceed to commit the transaction and respond once the commit completes
67 * or fails to complete.
69 * @return Indication of coordinated commit.
71 public boolean isCoordinated() {
76 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
77 return super.addToStringAttributes(toStringHelper).add("coordinated", coordinated)
78 .add("delayedError", delayedFailure);