Binding2 runtime - API #6 22/58322/4
authorMartin Ciglan <martin.ciglan@pantheon.tech>
Wed, 24 May 2017 13:09:53 +0000 (15:09 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Tue, 6 Jun 2017 17:48:30 +0000 (17:48 +0000)
- DataTreeCommitCohortRegistry & its relatives
- Javadocs provided

Change-Id: I86f5771140f7c151dfad78b0066cc8d0b8790625
Signed-off-by: Martin Ciglan <martin.ciglan@pantheon.tech>
(cherry picked from commit 99f29efb2f2f675ae6c6632cd35fcab1d0d14518)

binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohort.java [new file with mode: 0644]
binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohortRegistry.java [new file with mode: 0644]

diff --git a/binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohort.java b/binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohort.java
new file mode 100644 (file)
index 0000000..25063fa
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.api;
+
+import com.google.common.annotations.Beta;
+import java.util.function.BiConsumer;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+import org.opendaylight.mdsal.common.api.DataValidationFailedException;
+import org.opendaylight.mdsal.common.api.PostCanCommitStep;
+
+/**
+ * Commit cohort participating in commit of data modification, which can validate data tree
+ * modifications, with option to reject supplied modification, and with callbacks describing state
+ * of commit.
+ *
+ * <h2>Performance implications</h2>
+ *
+ * {@link DataTreeCommitCohort}s are hooked up into commit of data tree changes and MAY
+ * negatively affect performance of data broker / store.
+ *
+ * <p>
+ * Implementations of this interface are discouraged, unless you really need ability to veto data
+ * tree changes, or to provide external state change in sync with visibility of commited data.
+ *
+ * <h2>Implementation requirements</h2>
+ *
+ * <h3>Correctness assumptions</h3> Implementation SHOULD use only provided
+ * {@link DataTreeModification} for validation purposes.
+ *
+ * <p>
+ * Use of any other external mutable state is discouraged, implementation MUST NOT use any
+ * transaction related APIs on same data broker / data store instance during invocation of
+ * callbacks, except ones provided as argument. Note that this MAY BE enforced by some
+ * implementations of {@link DataBroker} or Commit coordinator
+ *
+ * <p>
+ * Note that this may be enforced by some implementations of {@link DataTreeCommitCohortRegistry}
+ * and such calls may fail.
+ *
+ * <h3>DataTreeCandidate assumptions</h3> Implementation SHOULD NOT make any assumptions on
+ * {@link DataTreeModification} being successfully committed until associated
+ * {@link PostCanCommitStep#preCommit()} and
+ * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} callback was invoked.
+ *
+ * <h2>Usage patterns</h2>
+ *
+ * <h3>Data Tree Validator</h3>
+ *
+ * <p>
+ * Validator is implementation, which only validates {@link DataTreeModification} and does not
+ * retain any state derived from edited data - does not care if {@link DataTreeModification} was
+ * rejected afterwards or transaction was cancelled.
+ *
+ * <p>
+ * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
+ * callbacks by returning {@link PostCanCommitStep#NOOP}.
+ */
+@Beta
+public interface DataTreeCommitCohort<T extends TreeNode> {
+    /**
+     * Performs canCommit? message in three-phase commit algorithm.
+     *
+     * @param txId Transaction identifier
+     * @param modification modification of data tree
+     * @param callback result callback
+     */
+    void canCommit(Object txId, DataTreeModification<T> modification,
+        BiConsumer<DataValidationFailedException, PostCanCommitStep> callback);
+}
diff --git a/binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohortRegistry.java b/binding2/mdsal-binding2-api/src/main/java/org/opendaylight/mdsal/binding/javav2/api/DataTreeCommitCohortRegistry.java
new file mode 100644 (file)
index 0000000..a632b27
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.api;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+
+/**
+ * Commit Cohort registry.
+ *
+ * <p>
+ * See {@link DataTreeCommitCohort} for more details.
+ *
+ */
+@Beta
+public interface DataTreeCommitCohortRegistry {
+
+    /**
+     * Register commit cohort which will participate in three-phase commit protocols of write
+     * transaction in data broker associated with this instance of extension.
+     *
+     * @param subtree Subtree path on which commit cohort operates.
+     * @param cohort Commit cohort
+     * @param <D> data type
+     * @param <T> cohort type
+     * @return Registration object for DOM Data Three Commit cohort.
+     */
+    <D extends TreeNode, T extends DataTreeCommitCohort<D>> ObjectRegistration<T> registerCommitCohort(
+        DataTreeIdentifier<D> subtree, T cohort);
+}