Improve transaction commit() ease of use

Description

Both WriteTransaction and DOMDataTreeTransaction rely on FluentFuture<? extends CommitInfo> to allow users to post-process commits. We go out of our way to define the semantics here and rely on static analysis to catch users forgetting to hook.

There are also guarantees commit() is making as those are not propagated through ListenableFuture, leading users making their own things, not knowing about ExceptionMapper.

Introduce

 

@NonNullByDefault public interface OnCommitCallback { void onSuccess(CommitInfo commitInfo); void onFailure(TransactionCommitFailedException cause); }

in mdsal-common-api.

 

Then introduce the following to (DOMDataTree)WriteTransaction:

default void commit(final @NonNull OnCommitCallback callback, final @NonNull Executor executor) { // commit().addCallback(...); }

 

This way downstream users can improve their code with:

-        tx.commit().addCallback(new FutureCallback<CommitInfo>() { +        tx.commit(new OnCommitCallback() {              @Override              public void onSuccess(final CommitInfo result) { // ...              }                @Override -            public void onFailure(final Throwable cause) { +            public void onFailure(final TransactionCommitFailedException cause) {                  // ...              }

Specifically:

  • the need for a callback is part of commit() method

  • there is no need to use generics

  • the failure cause is now a well-defined exception, containing at least one RpcError in cause.getErrorList()

It also lays down the API ground work for use with per-datastore API work in scope of MDSAL-358.

 

Activity

Show:
Done

Details

Assignee

Reporter

Labels

Fix versions

Priority

Created August 2, 2024 at 6:04 PM
Updated August 26, 2024 at 11:47 AM
Resolved August 26, 2024 at 11:47 AM