use of reactor.core.publisher.MonoSink in project mongo-java-driver by mongodb.
the class ClientSessionPublisherImpl method commitTransaction.
@Override
public Publisher<Void> commitTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call commitTransaction after calling abortTransaction");
}
if (transactionState == TransactionState.NONE) {
throw new IllegalStateException("There is no transaction started");
}
if (!messageSentInCurrentTransaction) {
cleanupTransaction(TransactionState.COMMITTED);
return Mono.create(MonoSink::success);
} else {
ReadConcern readConcern = transactionOptions.getReadConcern();
if (readConcern == null) {
throw new MongoInternalException("Invariant violated. Transaction options read concern can not be null");
}
boolean alreadyCommitted = commitInProgress || transactionState == TransactionState.COMMITTED;
commitInProgress = true;
return executor.execute(new CommitTransactionOperation(transactionOptions.getWriteConcern(), alreadyCommitted).recoveryToken(getRecoveryToken()).maxCommitTime(transactionOptions.getMaxCommitTime(MILLISECONDS), MILLISECONDS), readConcern, this).doOnTerminate(() -> {
commitInProgress = false;
transactionState = TransactionState.COMMITTED;
}).doOnError(MongoException.class, this::clearTransactionContextOnError);
}
}
use of reactor.core.publisher.MonoSink in project mongo-java-driver by mongodb.
the class Crypt method fetchKeys.
private void fetchKeys(final MongoCryptContext cryptContext, @Nullable final String databaseName, final MonoSink<RawBsonDocument> sink) {
keyRetriever.find(cryptContext.getMongoOperation()).doOnSuccess(results -> {
for (BsonDocument result : results) {
cryptContext.addMongoOperationResult(result);
}
cryptContext.completeMongoOperation();
executeStateMachineWithSink(cryptContext, databaseName, sink);
}).doOnError(t -> sink.error(MongoException.fromThrowableNonNull(t))).subscribe();
}
use of reactor.core.publisher.MonoSink in project mongo-java-driver by mongodb.
the class ClientSessionPublisherImpl method abortTransaction.
@Override
public Publisher<Void> abortTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call abortTransaction twice");
}
if (transactionState == TransactionState.COMMITTED) {
throw new IllegalStateException("Cannot call abortTransaction after calling commitTransaction");
}
if (transactionState == TransactionState.NONE) {
throw new IllegalStateException("There is no transaction started");
}
if (!messageSentInCurrentTransaction) {
cleanupTransaction(TransactionState.ABORTED);
return Mono.create(MonoSink::success);
} else {
ReadConcern readConcern = transactionOptions.getReadConcern();
if (readConcern == null) {
throw new MongoInternalException("Invariant violated. Transaction options read concern can not be null");
}
return executor.execute(new AbortTransactionOperation(transactionOptions.getWriteConcern()).recoveryToken(getRecoveryToken()), readConcern, this).onErrorResume(Throwable.class, (e) -> Mono.empty()).doOnTerminate(() -> {
clearTransactionContext();
cleanupTransaction(TransactionState.ABORTED);
});
}
}
Aggregations