Fix a few javadoc warnings
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeCommitCohort.java
index 09595c444aaa5543722914f8131a09384e4e0ee3..9760a8e7a30e6d56ae447a10dfcfba6119518a5b 100644 (file)
@@ -7,22 +7,16 @@
  */
 package org.opendaylight.mdsal.dom.api;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.Beta;
-import com.google.common.collect.Iterables;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.ArrayList;
+import com.google.common.util.concurrent.FluentFuture;
 import java.util.Collection;
-import java.util.List;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
-import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.LoggerFactory;
 
 /**
  * Commit cohort participating in commit of data modification, which can validate data tree
@@ -61,7 +55,6 @@ import org.slf4j.LoggerFactory;
  * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
  * callbacks by returning {@link PostCanCommitStep#NOOP}.
  *
- * <p>
  * @author Tony Tkacik
  */
 // TODO: Provide example and describe more usage patterns
@@ -69,82 +62,49 @@ import org.slf4j.LoggerFactory;
 public interface DOMDataTreeCommitCohort {
 
     /**
-     * DO NOT implement or invoke this method. It is deprecated in favor of
-     * {@link #canCommit(Object, Collection, SchemaContext)} and only exists for backwards compatibility. The
-     * default implementation returns {@link PostCanCommitStep#NOOP_SUCCESS_FUTURE} and is invoked by the
-     * default implementation of {@link #canCommit(Object, Collection, SchemaContext)}.
-     *
-     * @deprecated Implement and invoke {@link #canCommit(Object, Collection, SchemaContext)} instead.
-     */
-    @Deprecated
-    @Nonnull
-    default CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(@Nonnull final Object txId,
-            @Nonnull final DOMDataTreeCandidate candidate, @Nonnull final SchemaContext ctx) {
-        LoggerFactory.getLogger(getClass()).error(
-                "The default implementation of DOMDataTreeCommitCohort#canCommit(Object, DOMDataTreeCandidate, "
-                + "SchemaContext) was invoked on {}", getClass());
-        return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
-    }
-
-    /**
-     * Validates supplied data tree candidates and associates cohort-specific steps with data broker
+     * Validates the supplied data tree modifications and associates the cohort-specific steps with data broker
      * transaction.
-     * If {@link DataValidationFailedException} is thrown by implementation, commit of supplied data
-     * will be prevented, with the DataBroker transaction providing the thrown exception as the
-     * cause of failure.
-     * Note the implementations are expected to do validation and processing asynchronous.
-     * Implementations SHOULD do processing fast, and are discouraged SHOULD NOT block on any
-     * external resources.
-     * Implementation MUST NOT access any data transaction related APIs during invocation of
-     * callback. Note that this may be enforced by some implementations of
-     * {@link DOMDataTreeCommitCohortRegistry} and such calls may fail.
+     *
+     * <p>
+     * If {@link DataValidationFailedException} is thrown by implementation, the commit of the supplied data
+     * will be prevented, with the DataBroker transaction providing the thrown exception as the cause of failure.
+     *
+     * <p>
+     * Note the implementations are expected to do validation and processing asynchronous. Implementations SHOULD do
+     * processing fast, and are discouraged from blocking on any external resources. Implementation MUST NOT access
+     * any data transaction related APIs during invocation of the callback. Note that this may be enforced by some
+     * implementations of {@link DOMDataTreeCommitCohortRegistry} and such calls may fail.
+     *
+     * <p>
      * Implementation MAY opt-out from implementing other steps by returning
      * {@link PostCanCommitStep#NOOP}. Otherwise implementation MUST return instance of
      * {@link PostCanCommitStep}, which will be used to invoke
      * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} or
-     * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit
-     * cohorts.
+     * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit cohorts.
      *
      * @param txId Transaction identifier. SHOULD be used only for reporting and correlation.
      *        Implementation MUST NOT use {@code txId} for validation.
      * @param candidates Data Tree candidates to be validated and committed.
      * @param ctx Schema Context to which Data Tree candidate should conform.
-     * @return Checked future which will successfully complete with the user-supplied implementation of
-     *         {@link PostCanCommitStep} if all candidates are valid, or a failed checked future with a
+     * @return a FluentFuture which will successfully complete with the user-supplied implementation of
+     *         {@link PostCanCommitStep} if all candidates are valid, or a failed future with a
      *         {@link DataValidationFailedException} if and only if a provided
      *         {@link DOMDataTreeCandidate} instance did not pass validation. Users are encouraged to use
      *         more specific subclasses of this exception to provide additional information about
      *         validation failure reason.
      */
-    @Nonnull
-    default CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(@Nonnull final Object txId,
-            @Nonnull final Collection<DOMDataTreeCandidate> candidates, @Nonnull final SchemaContext ctx) {
-        LoggerFactory.getLogger(getClass()).warn("DOMDataTreeCommitCohort implementation {} should override "
-                + "canCommit(Object, Collection, SchemaContext)", getClass());
-
-        // For backwards compatibility, the default implementation is to invoke the deprecated
-        // canCommit(Object, DOMDataTreeCandidate, SchemaContext) method for each DOMDataTreeCandidate and return the
-        // last PostCanCommitStep.
-        List<ListenableFuture<PostCanCommitStep>> futures = new ArrayList<>();
-        for (DOMDataTreeCandidate candidate : candidates) {
-            futures.add(canCommit(txId, candidate, ctx));
-        }
-
-        final ListenableFuture<PostCanCommitStep> resultFuture = Futures.transform(Futures.allAsList(futures),
-            input -> input.get(input.size() - 1), MoreExecutors.directExecutor());
-        return MappingCheckedFuture.create(resultFuture, new DataValidationFailedExceptionMapper("canCommit",
-                Iterables.getLast(candidates).getRootPath()));
-    }
+    @NonNull FluentFuture<PostCanCommitStep> canCommit(@NonNull Object txId,
+            @NonNull SchemaContext ctx, @NonNull Collection<DOMDataTreeCandidate> candidates);
 
     /**
      * An ExceptionMapper that translates an Exception to a DataValidationFailedException.
      */
     class DataValidationFailedExceptionMapper extends ExceptionMapper<DataValidationFailedException> {
-        private final DOMDataTreeIdentifier failedTreeId;
+        private final @NonNull DOMDataTreeIdentifier failedTreeId;
 
         public DataValidationFailedExceptionMapper(final String opName, final DOMDataTreeIdentifier failedTreeId) {
             super(opName, DataValidationFailedException.class);
-            this.failedTreeId = failedTreeId;
+            this.failedTreeId = requireNonNull(failedTreeId);
         }
 
         @Override