Class AttemptContextReactive

  • Direct Known Subclasses:
    TestAttemptContextReactive

    public class AttemptContextReactive
    extends java.lang.Object
    Provides methods to allow an application's transaction logic to read, mutate, insert and delete documents, as well as commit or rollback the transaction.

    These methods are asynchronous, and use the Project Reactor library. See AttemptContext for a synchronous version.

    Thread-safety: This class is thread-safe for specific workloads, namely doing batch mutations in a reactive way.

    • Field Detail

      • TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED

        public static int TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
      • TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED

        public static int TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
      • TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK

        public static int TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
      • TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY

        public static int TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
      • STATE_BITS_POSITION_FINAL_ERROR

        public static int STATE_BITS_POSITION_FINAL_ERROR
      • STATE_BITS_MASK_FINAL_ERROR

        public static int STATE_BITS_MASK_FINAL_ERROR
      • STATE_BITS_MASK_BITS

        public static int STATE_BITS_MASK_BITS
      • HOOK_ROLLBACK

        public static java.lang.String HOOK_ROLLBACK
      • HOOK_GET

        public static java.lang.String HOOK_GET
      • HOOK_INSERT

        public static java.lang.String HOOK_INSERT
      • HOOK_REPLACE

        public static java.lang.String HOOK_REPLACE
      • HOOK_REMOVE

        public static java.lang.String HOOK_REMOVE
      • HOOK_BEFORE_COMMIT

        public static java.lang.String HOOK_BEFORE_COMMIT
      • HOOK_ROLLBACK_DOC

        public static java.lang.String HOOK_ROLLBACK_DOC
      • HOOK_DELETE_INSERTED

        public static java.lang.String HOOK_DELETE_INSERTED
      • HOOK_REMOVE_STAGED_INSERT

        public static java.lang.String HOOK_REMOVE_STAGED_INSERT
      • HOOK_CREATE_STAGED_INSERT

        public static java.lang.String HOOK_CREATE_STAGED_INSERT
      • HOOK_REMOVE_DOC

        public static java.lang.String HOOK_REMOVE_DOC
      • HOOK_COMMIT_DOC

        public static java.lang.String HOOK_COMMIT_DOC
      • HOOK_COMMIT_DOC_CHANGED

        public static java.lang.String HOOK_COMMIT_DOC_CHANGED
      • HOOK_STAGING_DOC_CHANGED

        public static java.lang.String HOOK_STAGING_DOC_CHANGED
      • HOOK_ROLLBACK_DOC_CHANGED

        public static java.lang.String HOOK_ROLLBACK_DOC_CHANGED
      • HOOK_QUERY

        public static java.lang.String HOOK_QUERY
      • HOOK_QUERY_BEGIN_WORK

        public static java.lang.String HOOK_QUERY_BEGIN_WORK
      • HOOK_QUERY_COMMIT

        public static java.lang.String HOOK_QUERY_COMMIT
      • HOOK_QUERY_ROLLBACK

        public static java.lang.String HOOK_QUERY_ROLLBACK
      • HOOK_QUERY_KV_GET

        public static java.lang.String HOOK_QUERY_KV_GET
      • HOOK_QUERY_KV_REPLACE

        public static java.lang.String HOOK_QUERY_KV_REPLACE
      • HOOK_QUERY_KV_REMOVE

        public static java.lang.String HOOK_QUERY_KV_REMOVE
      • HOOK_QUERY_KV_INSERT

        public static java.lang.String HOOK_QUERY_KV_INSERT
      • HOOK_BEFORE_RETRY

        public static java.lang.String HOOK_BEFORE_RETRY
      • HOOK_ATR_COMMIT

        public static java.lang.String HOOK_ATR_COMMIT
      • HOOK_ATR_COMMIT_AMBIGUITY_RESOLUTION

        public static java.lang.String HOOK_ATR_COMMIT_AMBIGUITY_RESOLUTION
      • HOOK_ATR_ABORT

        public static java.lang.String HOOK_ATR_ABORT
      • HOOK_ATR_ROLLBACK_COMPLETE

        public static java.lang.String HOOK_ATR_ROLLBACK_COMPLETE
      • HOOK_ATR_PENDING

        public static java.lang.String HOOK_ATR_PENDING
      • HOOK_ATR_COMPLETE

        public static java.lang.String HOOK_ATR_COMPLETE
      • DEFAULT_DELAY_RETRYING_OPERATION

        public static java.time.Duration DEFAULT_DELAY_RETRYING_OPERATION
    • Method Detail

      • attemptId

        public java.lang.String attemptId()
        Returns the globally unique ID of this attempt, which may be useful for debugging and logging purposes.
      • transactionId

        public java.lang.String transactionId()
        Returns the globally unique ID of the overall transaction owning this attempt, which may be useful for debugging and logging purposes.
      • getOptional

        public reactor.core.publisher.Mono<java.util.Optional<TransactionGetResult>> getOptional​(com.couchbase.client.java.ReactiveCollection collection,
                                                                                                 java.lang.String id)
        Gets a document with the specified id and from the specified Couchbase bucket.

        The semantics are the same as AttemptContext.getOptional(com.couchbase.client.java.Collection, java.lang.String), except that the a Mono is returned so the operation can be performed asynchronously.

        Parameters:
        collection - the Couchbase collection the document exists on
        id - the document's ID
        Returns:
        an Optional containing the document, or Optional.empty() if not found
      • get

        public reactor.core.publisher.Mono<TransactionGetResult> get​(com.couchbase.client.java.ReactiveCollection collection,
                                                                     java.lang.String id)
        Gets a document with the specified id and from the specified Couchbase bucket.

        The semantics are the same as AttemptContext.get(Collection, String), except that the a Mono is returned so the operation can be performed asynchronously.

        Parameters:
        collection - the Couchbase collection the document exists on
        id - the document's ID
        Returns:
        a TransactionGetResult containing the document
      • atrId

        public java.util.Optional<java.lang.String> atrId()
      • atrCollection

        public java.util.Optional<com.couchbase.client.java.ReactiveCollection> atrCollection()
      • insert

        public reactor.core.publisher.Mono<TransactionGetResult> insert​(com.couchbase.client.java.ReactiveCollection collection,
                                                                        java.lang.String id,
                                                                        java.lang.Object content)
        Inserts a new document into the specified Couchbase collection.

        The semantics are the same as AttemptContext.insert(Collection, String, Object), except that a Mono is returned so the operation can be performed asynchronously.

        Parameters:
        collection - the Couchbase collection in which to insert the doc
        id - the document's unique ID
        content - the content to insert. Generally this will be a JsonObject
        Returns:
        the doc, updated with its new CAS value and ID, and converted to a TransactionGetResult
      • insert

        public reactor.core.publisher.Mono<TransactionGetResult> insert​(com.couchbase.client.java.ReactiveCollection collection,
                                                                        java.lang.String id,
                                                                        java.lang.Object content,
                                                                        TransactionInsertOptions options)
        Inserts a new document into the specified Couchbase collection.

        The semantics are the same as AttemptContext.insert(Collection, String, Object), except that a Mono is returned so the operation can be performed asynchronously.

        Parameters:
        collection - the Couchbase collection in which to insert the doc
        options - options controlling how the document is inserted. See TransactionInsertOptions for details
        id - the document's unique ID
        content - the content to insert. Generally this will be a JsonObject
        Returns:
        the doc, updated with its new CAS value and ID, and converted to a TransactionGetResult
      • randomAtrIdForVbucket

        protected java.lang.String randomAtrIdForVbucket​(AttemptContextReactive self,
                                                         java.lang.Integer vbucketIdForDoc,
                                                         int numAtrs)
      • commit

        public reactor.core.publisher.Mono<java.lang.Void> commit()
        Commits the transaction. All staged replaces, inserts and removals will be written.

        The semantics are the same as AttemptContext.commit(), except that the a Mono is returned so the operation can be performed asynchronously.

      • rollback

        public reactor.core.publisher.Mono<java.lang.Void> rollback()
        Rolls back the transaction. All staged replaces, inserts and removals will be removed. The transaction will not be retried, so this will be the final attempt.

        The semantics are the same as AttemptContext.rollback(), except that the a Mono is returned so the operation can be performed asynchronously.

      • query

        @Uncommitted
        public reactor.core.publisher.Mono<com.couchbase.client.java.query.ReactiveQueryResult> query​(java.lang.String statement)
        Calls query() with default options.
      • query

        @Uncommitted
        public reactor.core.publisher.Mono<com.couchbase.client.java.query.ReactiveQueryResult> query​(java.lang.String statement,
                                                                                                      TransactionQueryOptions options)
        Runs a N1QL query and returns the result.

        Rows are streamed back asynchronously over the reactive interface, automatically applying backpressure.

        This overload performs a 'scope-level query': that is, one in which a collection may be referenced by name in the query statement, without needing to specify the full bucket.scope.collection syntax.

        Raises CouchbaseException on failure. The application can choose to catch and ignore this error, and the transaction attempt is allowed to continue. This differs from Key-Value operations, whose failure will cause the attempt to fail.

      • query

        @Uncommitted
        public reactor.core.publisher.Mono<com.couchbase.client.java.query.ReactiveQueryResult> query​(com.couchbase.client.java.ReactiveScope scope,
                                                                                                      java.lang.String statement)
        Runs a N1QL query and returns the result, with default parameters.

        Rows are streamed back asynchronously over the reactive interface, automatically applying backpressure.

        Raises CouchbaseException on failure. The application can choose to catch and ignore this error, and the transaction attempt is allowed to continue. This differs from Key-Value operations, whose failure will cause the attempt to fail.

      • query

        @Uncommitted
        public reactor.core.publisher.Mono<com.couchbase.client.java.query.ReactiveQueryResult> query​(com.couchbase.client.java.ReactiveScope scope,
                                                                                                      java.lang.String statement,
                                                                                                      TransactionQueryOptions options)
        Runs a N1QL query and returns the result.

        Rows are streamed back asynchronously over the reactive interface, automatically applying backpressure.

        Raises CouchbaseException on failure. The application can choose to catch and ignore this error, and the transaction attempt is allowed to continue. This differs from Key-Value operations, whose failure will cause the attempt to fail.

      • beforeAtrCommit

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrCommit​(AttemptContextReactive self)
      • beforeAtrCommitAmbiguityResolution

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrCommitAmbiguityResolution​(AttemptContextReactive self)
      • afterAtrCommit

        protected reactor.core.publisher.Mono<java.lang.Integer> afterAtrCommit​(AttemptContextReactive self)
      • beforeDocCommitted

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocCommitted​(AttemptContextReactive self,
                                                                                    java.lang.String id)
      • beforeDocRolledBack

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocRolledBack​(AttemptContextReactive self,
                                                                                     java.lang.String id)
      • afterDocCommittedBeforeSavingCAS

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocCommittedBeforeSavingCAS​(AttemptContextReactive self,
                                                                                                  java.lang.String id)
      • afterDocCommitted

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocCommitted​(AttemptContextReactive self,
                                                                                   java.lang.String id)
      • afterDocsCommitted

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocsCommitted​(AttemptContextReactive self)
      • beforeDocRemoved

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocRemoved​(AttemptContextReactive self,
                                                                                  java.lang.String id)
      • afterDocRemovedPreRetry

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocRemovedPreRetry​(AttemptContextReactive self,
                                                                                         java.lang.String id)
      • afterDocRemovedPostRetry

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocRemovedPostRetry​(AttemptContextReactive self,
                                                                                          java.lang.String id)
      • afterDocsRemoved

        protected reactor.core.publisher.Mono<java.lang.Integer> afterDocsRemoved​(AttemptContextReactive self)
      • beforeAtrPending

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrPending​(AttemptContextReactive self)
      • afterAtrPending

        protected reactor.core.publisher.Mono<java.lang.Integer> afterAtrPending​(AttemptContextReactive self)
      • afterAtrComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> afterAtrComplete​(AttemptContextReactive self)
      • beforeAtrComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrComplete​(AttemptContextReactive self)
      • beforeAtrRolledBack

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrRolledBack​(AttemptContextReactive self)
      • afterGetComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> afterGetComplete​(AttemptContextReactive self,
                                                                                  java.lang.String id)
      • beforeRollbackDeleteInserted

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeRollbackDeleteInserted​(AttemptContextReactive self,
                                                                                              java.lang.String id)
      • afterStagedReplaceComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> afterStagedReplaceComplete​(AttemptContextReactive self,
                                                                                            java.lang.String id)
      • afterStagedRemoveComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> afterStagedRemoveComplete​(AttemptContextReactive self,
                                                                                           java.lang.String id)
      • beforeStagedInsert

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeStagedInsert​(AttemptContextReactive self,
                                                                                    java.lang.String id)
      • beforeStagedRemove

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeStagedRemove​(AttemptContextReactive self,
                                                                                    java.lang.String id)
      • beforeStagedReplace

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeStagedReplace​(AttemptContextReactive self,
                                                                                     java.lang.String id)
      • afterStagedInsertComplete

        protected reactor.core.publisher.Mono<java.lang.Integer> afterStagedInsertComplete​(AttemptContextReactive self,
                                                                                           java.lang.String id)
      • beforeAtrAborted

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeAtrAborted​(AttemptContextReactive self)
      • afterAtrAborted

        protected reactor.core.publisher.Mono<java.lang.Integer> afterAtrAborted​(AttemptContextReactive self)
      • afterAtrRolledBack

        protected reactor.core.publisher.Mono<java.lang.Integer> afterAtrRolledBack​(AttemptContextReactive self)
      • afterRollbackReplaceOrRemove

        protected reactor.core.publisher.Mono<java.lang.Integer> afterRollbackReplaceOrRemove​(AttemptContextReactive self,
                                                                                              java.lang.String id)
      • afterRollbackDeleteInserted

        protected reactor.core.publisher.Mono<java.lang.Integer> afterRollbackDeleteInserted​(AttemptContextReactive self,
                                                                                             java.lang.String id)
      • beforeCheckATREntryForBlockingDoc

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeCheckATREntryForBlockingDoc​(AttemptContextReactive self,
                                                                                                   java.lang.String id)
      • beforeDocGet

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocGet​(AttemptContextReactive self,
                                                                              java.lang.String id)
      • beforeGetDocInExistsDuringStagedInsert

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeGetDocInExistsDuringStagedInsert​(AttemptContextReactive self,
                                                                                                        java.lang.String id)
      • beforeRemoveStagedInsert

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeRemoveStagedInsert​(AttemptContextReactive self,
                                                                                          java.lang.String id)
      • afterRemoveStagedInsert

        protected reactor.core.publisher.Mono<java.lang.Integer> afterRemoveStagedInsert​(AttemptContextReactive self,
                                                                                         java.lang.String id)
      • hasExpiredClientSideHook

        protected java.lang.Boolean hasExpiredClientSideHook​(AttemptContextReactive self,
                                                             java.lang.String place,
                                                             java.util.Optional<java.lang.String> docId)
      • beforeQuery

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeQuery​(AttemptContextReactive self,
                                                                             java.lang.String statement)
      • afterQuery

        protected reactor.core.publisher.Mono<java.lang.Integer> afterQuery​(AttemptContextReactive self,
                                                                            java.lang.String statement)
      • beforeOverwritingStagedInsertRemoval

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeOverwritingStagedInsertRemoval​(AttemptContextReactive self,
                                                                                                      java.lang.String id)
      • beforeUnlockGet

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeUnlockGet​(AttemptContextReactive self,
                                                                                 java.lang.String id)
      • beforeUnlockInsert

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeUnlockInsert​(AttemptContextReactive self,
                                                                                    java.lang.String id)
      • beforeUnlockReplace

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeUnlockReplace​(AttemptContextReactive self,
                                                                                     java.lang.String id)
      • beforeUnlockRemove

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeUnlockRemove​(AttemptContextReactive self,
                                                                                    java.lang.String id)
      • beforeUnlockQuery

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeUnlockQuery​(AttemptContextReactive self,
                                                                                   java.lang.String statement)
      • beforeDocChangedDuringCommit

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocChangedDuringCommit​(AttemptContextReactive self,
                                                                                              java.lang.String id)
      • beforeDocChangedDuringStaging

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocChangedDuringStaging​(AttemptContextReactive self,
                                                                                               java.lang.String id)
      • beforeDocChangedDuringRollback

        protected reactor.core.publisher.Mono<java.lang.Integer> beforeDocChangedDuringRollback​(AttemptContextReactive self,
                                                                                                java.lang.String id)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object