X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-common-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fcommon%2Fapi%2Fdata%2FAsyncWriteTransaction.java;h=d51585b826c018f599c773d357b850d98daecded;hp=79f80a3f0577e1ce2fd28486497652a982ee7381;hb=3ec97cd0a86ad1b79f6854dc6924eb7b06e359a3;hpb=84d6864d26fddddd92da32fd00d57c7224d4213d diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java index 79f80a3f05..d51585b826 100644 --- a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java @@ -11,10 +11,11 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; -import javax.annotation.CheckReturnValue; 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.util.concurrent.ExceptionMapper; /** * Write transaction provides mutation capabilities for a data tree. @@ -100,6 +101,7 @@ import org.opendaylight.yangtools.concepts.Path; * @param * Type of data (payload), which represents data payload */ +@Deprecated public interface AsyncWriteTransaction

, D> extends AsyncTransaction { /** * Cancels the transaction. @@ -115,8 +117,8 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * Invoking cancel() on a finished transaction (future returned by {@link #submit()} already completed will always * fail (return false). * - * @return false if the task could not be cancelled, typically because it has already completed normally - * true otherwise + * @return {@code false} if the task could not be cancelled, typically because it has already completed normally + * {@code true} otherwise * */ boolean cancel(); @@ -157,8 +159,7 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * ({@link AsyncConfigurationCommitHandler}) if the transaction changes the data tree. * *

- * 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. * *

Example usage:

@@ -228,7 +229,8 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * which are based on same initial state, Tx 1 completes successfully * before Tx 2 is submitted. * - * + *
+ * * * * @@ -253,7 +255,8 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * which are based on same initial state, Tx 1 completes successfully * before Tx 2 is submitted. * - *

Data store state changes
Initial stateTx 1Tx 2Result
Emptyput(A,1)put(A,2)Tx 2 will fail, state is A=1
Emptyput(A,1)merge(A,2)A=2
+ *
+ * * * * @@ -338,7 +341,10 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * @deprecated Use {@link #commit()} instead. */ @Deprecated - CheckedFuture submit(); + default CheckedFuture submit() { + return MappingCheckedFuture.create(commit().transform(ignored -> null, MoreExecutors.directExecutor()), + SUBMIT_EXCEPTION_MAPPER); + } /** * Submits this transaction to be asynchronously applied to update the logical data tree. The returned @@ -369,9 +375,17 @@ public interface AsyncWriteTransaction

, D> extends AsyncTransa * {@link TransactionCommitFailedException} or an exception derived from TransactionCommitFailedException. * @throws IllegalStateException if the transaction is already committed or was canceled. */ - @CheckReturnValue - default @NonNull FluentFuture commit() { - return FluentFuture.from(submit()).transformAsync(ignored -> CommitInfo.emptyFluentFuture(), - MoreExecutors.directExecutor()); - } + @NonNull FluentFuture commit(); + + /** + * This only exists for reuse by the deprecated {@link #submit} method and is not intended for general use. + */ + @Deprecated + ExceptionMapper SUBMIT_EXCEPTION_MAPPER = + new ExceptionMapper("submit", TransactionCommitFailedException.class) { + @Override + protected TransactionCommitFailedException newWithCause(final String message, final Throwable cause) { + return new TransactionCommitFailedException(message, cause); + } + }; }

Data store state changes
Initial stateTx 1Tx 2Result
Emptyput(TOP,[])put(TOP,[])Tx 2 will fail, state is TOP=[]