Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncWriteTransaction.java
index f12cb88a18860d3fed150d255687b73e115fde82..d51585b826c018f599c773d357b850d98daecded 100644 (file)
@@ -8,10 +8,14 @@
 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 org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 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.
@@ -97,26 +101,24 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
  * @param <D>
  *            Type of data (payload), which represents data payload
  */
+@Deprecated
 public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransaction<P, D> {
     /**
      * Cancels the transaction.
      *
      * <p>
-     * Transactions can only be cancelled if it's status is
-     * {@link TransactionStatus#NEW} or {@link TransactionStatus#SUBMITED}
+     * Transactions can only be cancelled if it's state is new or submitted.
      *
      * <p>
-     * Invoking cancel() on {@link TransactionStatus#FAILED} or
-     * {@link TransactionStatus#CANCELED} will have no effect, and transaction
+     * Invoking cancel() on a failed or cancelled transaction will have no effect, and transaction
      * is considered cancelled.
      *
      * <p>
-     * Invoking cancel() on finished transaction  (future returned by {@link #submit()}
-     * already completed with {@link TransactionStatus#COMMITED}) will always
+     * Invoking cancel() on a finished transaction (future returned by {@link #submit()} already completed will always
      * fail (return false).
      *
-     * @return <tt>false</tt> if the task could not be cancelled, typically because it has already completed normally
-     * <tt>true</tt> otherwise
+     * @return {@code false} if the task could not be cancelled, typically because it has already completed normally
+     *         {@code true} otherwise
      *
      */
     boolean cancel();
@@ -130,7 +132,7 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * @param path
      *            Data object path
      * @throws IllegalStateException
-     *             if the transaction is no longer {@link TransactionStatus#NEW}
+     *             if the transaction as already been submitted or cancelled
      */
     void delete(LogicalDatastoreType store, P path);
 
@@ -149,8 +151,7 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * {@link IllegalStateException}.
      *
      * <p>
-     * The transaction is marked as {@link TransactionStatus#SUBMITED} and
-     * enqueued into the data store back-end for processing.
+     * The transaction is marked as submitted and enqueued into the data store back-end for processing.
      *
      * <p>
      * Whether or not the commit is successful is determined by versioning
@@ -158,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>
@@ -229,7 +229,8 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * which are based on same initial state, Tx 1 completes successfully
      * before Tx 2 is submitted.
      *
-     * <table summary="">
+     * <table>
+     * <caption>Data store state changes</caption>
      * <tr><th>Initial state</th><th>Tx 1</th><th>Tx 2</th><th>Result</th></tr>
      * <tr><td>Empty</td><td>put(A,1)</td><td>put(A,2)</td><td>Tx 2 will fail, state is A=1</td></tr>
      * <tr><td>Empty</td><td>put(A,1)</td><td>merge(A,2)</td><td>A=2</td></tr>
@@ -254,7 +255,8 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * which are based on same initial state, Tx 1 completes successfully
      * before Tx 2 is submitted.
      *
-     * <table summary="">
+     * <table>
+     * <caption>Data store state changes</caption>
      * <tr><th>Initial state</th><th>Tx 1</th><th>Tx 2</th><th>Result</th></tr>
      *
      * <tr><td>Empty</td><td>put(TOP,[])</td><td>put(TOP,[])</td><td>Tx 2 will fail, state is TOP=[]</td></tr>
@@ -335,16 +337,55 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      *         derived from TransactionCommitFailedException.
      *
      * @throws IllegalStateException
-     *             if the transaction is not {@link TransactionStatus#NEW}
+     *             if the transaction is not new
+     * @deprecated Use {@link #commit()} instead.
      */
-    CheckedFuture<Void,TransactionCommitFailedException> submit();
+    @Deprecated
+    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.
+     *
+     * <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.
      *
-     * @deprecated Use {@link #submit()} instead.
+     * <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.
      */
-    @Deprecated
-    ListenableFuture<RpcResult<TransactionStatus>> commit();
+    @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
+    ExceptionMapper<TransactionCommitFailedException> SUBMIT_EXCEPTION_MAPPER =
+        new ExceptionMapper<TransactionCommitFailedException>("submit", TransactionCommitFailedException.class) {
+            @Override
+            protected TransactionCommitFailedException newWithCause(final String message, final Throwable cause) {
+                return new TransactionCommitFailedException(message, cause);
+            }
+        };
 }