Convert DCL tests to use DTCL
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncWriteTransaction.java
index e98d671426e451e1edd7fbf2e29462e9dd66c2dc..852c4e488617a25ef339dc4d58da6d03c4101fad 100644 (file)
@@ -8,10 +8,15 @@
 package org.opendaylight.controller.md.sal.common.api.data;
 
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import com.google.common.util.concurrent.MoreExecutors;
+import javax.annotation.CheckReturnValue;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.concepts.Path;
-import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
 
 /**
  * Write transaction provides mutation capabilities for a data tree.
@@ -154,8 +159,7 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * ({@link AsyncConfigurationCommitHandler}) if the transaction changes the data tree.
      *
      * <p>
-     * The effects of a successful commit of data depends on data change listeners
-     * ({@link AsyncDataChangeListener}) and commit participants
+     * The effects of a successful commit of data depends on data tree change listeners and commit participants
      * ({@link AsyncConfigurationCommitHandler}) that are registered with the data broker.
      *
      * <h3>Example usage:</h3>
@@ -332,16 +336,56 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      *
      * @throws IllegalStateException
      *             if the transaction is not new
+     * @deprecated Use {@link #commit()} instead.
      */
-    CheckedFuture<Void,TransactionCommitFailedException> submit();
+    @Deprecated
+    @CheckReturnValue
+    default CheckedFuture<Void, TransactionCommitFailedException> submit() {
+        return MappingCheckedFuture.create(commit().transform(ignored -> null, MoreExecutors.directExecutor()),
+                SUBMIT_EXCEPTION_MAPPER);
+    }
 
     /**
-     * Deprecated.
+     * Submits this transaction to be asynchronously applied to update the logical data tree. The returned
+     * {@link FluentFuture} conveys the result of applying the data changes.
+     *
+     * <p>
+     * This call logically seals the transaction, which prevents the client from further changing the data tree using
+     * this transaction. Any subsequent calls to <code>put(LogicalDatastoreType, Path, Object)</code>,
+     * <code>merge(LogicalDatastoreType, Path, Object)</code>, <code>delete(LogicalDatastoreType, Path)</code> will fail
+     * with {@link IllegalStateException}. The transaction is marked as submitted and enqueued into the data store
+     * back-end for processing.
      *
-     * @deprecated Use {@link #submit()} instead.
+     * <p>
+     * Whether or not the commit is successful is determined by versioning of the data tree and validation of registered
+     * commit participants if the transaction changes the data tree.
+     *
+     * <p>
+     * The effects of a successful commit of data depends on listeners and commit participants that are registered with
+     * the data broker.
+     *
+     * <p>
+     * A successful commit produces implementation-specific {@link CommitInfo} structure, which is used to communicate
+     * post-condition information to the caller. Such information can contain commit-id, timing information or any
+     * other information the implementation wishes to share.
+     *
+     * @return a FluentFuture containing the result of the commit information. The Future blocks until the commit
+     *         operation is complete. A successful commit returns nothing. On failure, the Future will fail with a
+     *         {@link TransactionCommitFailedException} or an exception derived from TransactionCommitFailedException.
+     * @throws IllegalStateException if the transaction is already committed or was canceled.
+     */
+    @CheckReturnValue
+    @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
+
+    /**
+     * This only exists for reuse by the deprecated {@link #submit} method and is not intended for general use.
      */
     @Deprecated
-    default ListenableFuture<RpcResult<TransactionStatus>> commit() {
-        throw new UnsupportedOperationException("commit() is deprecated, use submit() instead");
-    }
+    ExceptionMapper<TransactionCommitFailedException> SUBMIT_EXCEPTION_MAPPER =
+        new ExceptionMapper<TransactionCommitFailedException>("submit", TransactionCommitFailedException.class) {
+            @Override
+            protected TransactionCommitFailedException newWithCause(String message, Throwable cause) {
+                return new TransactionCommitFailedException(message, cause);
+            }
+        };
 }