Uploaded image for project: 'controller'
  1. controller
  2. CONTROLLER-624

Usability enhancement to WriteTransaction commit method

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Resolution: Done
    • Helium
    • None
    • mdsal
    • None
    • Operating System: All
      Platform: All

    Description

      The current WrteTransaction commit method returns RpcResult<TransactionStatus>:

      ListenableFuture<RpcResult<TransactionStatus>> commit();

      Typical client usage is to use a Futures.addCallback:

      Futures.addCallback( commitFuture,
      new FutureCallback<RpcResult<TransactionStatus>>() {
      @Override
      public void onSuccess( RpcResult<TransactionStatus> result ) {
      if( result.getResult() == TransactionStatus.COMMITED )

      { // succeeded }

      else

      { // failed }

      }

      @Override
      public void onFailure( Throwable ex )

      { // failed }

      } );

      Notice that the client has to handle failure conditions in 2 places and in 2 different ways (by checking TransactionStatus and in onFailure).

      Also the onSuccess method may be a bit misleading as it might not have been successful depending on the TransactionStatus.

      Also at this point the TransactionStatus could only be COMMITED or FAILURE which is really redundant with RpcResult#isSuccessful.

      I propose changing the commit method to:

      CheckedFuture<Void,TransactionCommitFailedException> ready();

      This method removes the RpcResult entirely and all errors conditions are conveyed via one path, via TransactionCommitFailedException. Nothing need be returned for a successful commit.

      The RpcResult allows for rich error info to be conveyed via RpcError. We can add RpcErrors to TransactionCommitFailedException for clients that are interested (eg restconf).

      The CheckedFuture explicitly conveys that clients can expect only TransactionCommitFailedExceptions.

      Client code then becomes:

      Futures.addCallback( commitFuture, new FutureCallback<Void>() {
      @Override
      public void onSuccess( Void result )

      { // Success }

      @Override
      public void onFailure( Throwable ex )

      { // Failed - e is instance of TransactionCommitFailedException }

      } );

      which is cleaner.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tpantelis Tom Pantelis
            tpantelis Tom Pantelis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: