BUG-5280: introduce base Transaction request/success
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / CommitLocalTransactionRequest.java
diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java
new file mode 100644 (file)
index 0000000..97381cc
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.commands;
+
+import akka.actor.ActorRef;
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+
+/**
+ * Request to commit a local transaction. Since local transactions do not introduce state on the backend until they
+ * are ready, this message carries a complete set of modifications.
+ *
+ * @author Robert Varga
+ */
+@Beta
+public final class CommitLocalTransactionRequest extends AbstractLocalTransactionRequest<CommitLocalTransactionRequest> {
+    private static final long serialVersionUID = 1L;
+    private final DataTreeModification mod;
+    private final boolean coordinated;
+
+    public CommitLocalTransactionRequest(final @Nonnull TransactionIdentifier identifier, final long sequence,
+            final @Nonnull ActorRef replyTo, final @Nonnull DataTreeModification mod, final boolean coordinated) {
+        this(identifier, sequence, 0, replyTo, mod, coordinated);
+    }
+
+    CommitLocalTransactionRequest(final @Nonnull TransactionIdentifier identifier, final long sequence,
+            final long retry, final @Nonnull ActorRef replyTo, final @Nonnull DataTreeModification mod,
+            final boolean coordinated) {
+        super(identifier, sequence, retry, replyTo);
+        this.mod = Preconditions.checkNotNull(mod);
+        this.coordinated = coordinated;
+    }
+
+
+    private CommitLocalTransactionRequest(final CommitLocalTransactionRequest request, final long retry) {
+        super(request, retry);
+        this.mod = request.mod;
+        this.coordinated = request.coordinated;
+    }
+
+    public DataTreeModification getModification() {
+        return mod;
+    }
+
+    /**
+     * Indicate if this is a coordinated, multi-backend request. If this method returns true, the backend must
+     * act as a cohort participating in the three-phase commit (3PC) protocol to commit this transaction.  If this
+     * method returns false, the backend should proceed to commit the transaction and respond once the commit completes
+     * or fails to complete.
+     *
+     * @return Indication of coordinated commit.
+     */
+    public boolean isCoordinated() {
+        return coordinated;
+    }
+
+    @Override
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("coordinated", coordinated);
+    }
+
+    @Override
+    protected CommitLocalTransactionRequest cloneAsRetry(final long retry) {
+        return new CommitLocalTransactionRequest(this, retry);
+    }
+}
\ No newline at end of file