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.base.MoreObjects.ToStringHelper;
14 import java.io.IOException;
15 import java.io.ObjectInputStream;
16 import java.io.ObjectOutputStream;
17 import java.io.ObjectStreamException;
18 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
25 * Request to commit a local transaction. Since local transactions do not introduce state on the backend until they
26 * are ready, this message carries a complete set of modifications.
28 public final class CommitLocalTransactionRequest
29 extends AbstractLocalTransactionRequest<CommitLocalTransactionRequest> {
31 private static final long serialVersionUID = 1L;
33 private final DataTreeModification mod;
34 private final Exception delayedFailure;
35 private final boolean coordinated;
37 public CommitLocalTransactionRequest(final @NonNull TransactionIdentifier identifier, final long sequence,
38 final @NonNull ActorRef replyTo, final @NonNull DataTreeModification mod,
39 final @Nullable Exception delayedFailure, final boolean coordinated) {
40 super(identifier, sequence, replyTo);
41 this.mod = requireNonNull(mod);
42 this.delayedFailure = delayedFailure;
43 this.coordinated = coordinated;
47 * Return the delayed error detected on the frontend. If this error is present, it will be reported as the result
48 * of the first step of the commit process.
50 * @return Delayed failure, if present.
52 public Optional<Exception> getDelayedFailure() {
53 return Optional.ofNullable(delayedFailure);
56 public DataTreeModification getModification() {
61 * Indicate if this is a coordinated, multi-backend request. If this method returns true, the backend must
62 * act as a cohort participating in the three-phase commit (3PC) protocol to commit this transaction. If this
63 * method returns false, the backend should proceed to commit the transaction and respond once the commit completes
64 * or fails to complete.
66 * @return Indication of coordinated commit.
68 public boolean isCoordinated() {
73 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
74 return super.addToStringAttributes(toStringHelper).add("coordinated", coordinated)
75 .add("delayedError", delayedFailure);
79 private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
84 private void readObjectNoData() throws ObjectStreamException {
89 private void writeObject(final ObjectOutputStream stream) throws IOException {