Interface CommitCallback

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CommitCallback
Defines a callback which is notified when a pending transaction has finished. To be effective, the callback must be attached prior to committing the transaction. If an exception is thrown by the initial commit invocation, the callback isn't invoked.

A pending transaction is one which is replicated, and it uses the NO_SYNC or NO_FLUSH durability mode. A replicated transaction which uses the SYNC durability mode blocks the committing thread until replication is confirmed, and the callback isn't invoked.

A unique callback instance can be allocated per transaction, or an instance can be shared for multiple transactions. When the callback is shared, thread safety must be taken into consideration.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    finished(long txnId, Object status)
    Called when a pending transaction has committed or rolled back.
    default void
    pending(long txnId)
    Called when a transaction is moving to the pending state.
  • Method Details

    • finished

      void finished(long txnId, Object status)
      Called when a pending transaction has committed or rolled back. When committed, the status is null. When rolled back, the status is an object which can be converted to a string to get a meaningful message.

      The callback is invoked from a limited set of threads, and so the implementation should avoid performing any blocking operations. Otherwise, pending transactions can pile up in an unfinished state.

      Parameters:
      txnId - non-zero transaction id
      status - null if committed, or else non-null if rolled back
    • pending

      default void pending(long txnId)
      Called when a transaction is moving to the pending state. By default this method does nothing, but it can be overridden to verify that pending transactions are being created.