Search in sources :

Example 1 with SingleResultCallback

use of com.mongodb.internal.async.SingleResultCallback in project mongo-java-driver by mongodb.

the class CommandOperationHelper method executeRetryableWriteAsync.

static <T, R> void executeRetryableWriteAsync(final AsyncWriteBinding binding, final String database, final ReadPreference readPreference, final FieldNameValidator fieldNameValidator, final Decoder<T> commandResultDecoder, final CommandCreator commandCreator, final CommandWriteTransformerAsync<T, R> transformer, final Function<BsonDocument, BsonDocument> retryCommandModifier, final SingleResultCallback<R> callback) {
    RetryState retryState = initialRetryState(true);
    binding.retain();
    AsyncCallbackSupplier<R> asyncWrite = CommandOperationHelper.<R>decorateWriteWithRetries(retryState, funcCallback -> {
        logRetryExecute(retryState);
        boolean firstAttempt = retryState.isFirstAttempt();
        if (!firstAttempt && binding.getSessionContext().hasActiveTransaction()) {
            binding.getSessionContext().clearTransactionContext();
        }
        withAsyncSourceAndConnection(binding::getWriteConnectionSource, true, funcCallback, (source, connection, releasingCallback) -> {
            int maxWireVersion = connection.getDescription().getMaxWireVersion();
            SingleResultCallback<R> addingRetryableLabelCallback = firstAttempt ? releasingCallback : addingRetryableLabelCallback(releasingCallback, maxWireVersion);
            if (retryState.breakAndCompleteIfRetryAnd(() -> !canRetryWrite(source.getServerDescription(), connection.getDescription(), binding.getSessionContext()), addingRetryableLabelCallback)) {
                return;
            }
            BsonDocument command;
            try {
                command = retryState.attachment(AttachmentKeys.command()).map(previousAttemptCommand -> {
                    assertFalse(firstAttempt);
                    return retryCommandModifier.apply(previousAttemptCommand);
                }).orElseGet(() -> commandCreator.create(source.getServerDescription(), connection.getDescription()));
                // attach `maxWireVersion`, `retryableCommandFlag` ASAP because they are used to check whether we should retry
                retryState.attach(AttachmentKeys.maxWireVersion(), maxWireVersion, true).attach(AttachmentKeys.retryableCommandFlag(), isRetryWritesEnabled(command), true).attach(AttachmentKeys.commandDescriptionSupplier(), command::getFirstKey, true).attach(AttachmentKeys.command(), command, false);
                logRetryExecute(retryState);
            } catch (Throwable t) {
                addingRetryableLabelCallback.onResult(null, t);
                return;
            }
            connection.commandAsync(database, command, fieldNameValidator, readPreference, commandResultDecoder, binding.getSessionContext(), binding.getServerApi(), binding.getRequestContext(), transformingWriteCallback(transformer, connection, addingRetryableLabelCallback));
        });
    }).whenComplete(binding::release);
    asyncWrite.get(exceptionTransformingCallback(errorHandlingCallback(callback, LOGGER)));
}
Also used : AsyncReadBinding(com.mongodb.internal.binding.AsyncReadBinding) ServerDescription(com.mongodb.connection.ServerDescription) MongoClientException(com.mongodb.MongoClientException) Function(com.mongodb.Function) MongoSocketException(com.mongodb.MongoSocketException) ConnectionDescription(com.mongodb.connection.ConnectionDescription) Arrays.asList(java.util.Arrays.asList) MongoNotPrimaryException(com.mongodb.MongoNotPrimaryException) OperationHelper.canRetryRead(com.mongodb.internal.operation.OperationHelper.canRetryRead) MongoNodeIsRecoveringException(com.mongodb.MongoNodeIsRecoveringException) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) MongoException(com.mongodb.MongoException) ConnectionSource(com.mongodb.internal.binding.ConnectionSource) AsyncCallbackSupplier(com.mongodb.internal.async.function.AsyncCallbackSupplier) ReadBinding(com.mongodb.internal.binding.ReadBinding) Assertions.assertFalse(com.mongodb.assertions.Assertions.assertFalse) MongoServerException(com.mongodb.MongoServerException) String.format(java.lang.String.format) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) Decoder(org.bson.codecs.Decoder) PRIVATE(com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE) RetryState(com.mongodb.internal.async.function.RetryState) List(java.util.List) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) ResourceSupplierInternalException(com.mongodb.internal.operation.OperationHelper.ResourceSupplierInternalException) ReadPreference.primary(com.mongodb.ReadPreference.primary) RetryingSyncSupplier(com.mongodb.internal.async.function.RetryingSyncSupplier) ReadPreference(com.mongodb.ReadPreference) RetryingAsyncCallbackSupplier(com.mongodb.internal.async.function.RetryingAsyncCallbackSupplier) MongoCommandException(com.mongodb.MongoCommandException) ErrorHandlingResultCallback.errorHandlingCallback(com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback) Supplier(java.util.function.Supplier) BsonDocument(org.bson.BsonDocument) LOGGER(com.mongodb.internal.operation.OperationHelper.LOGGER) Connection(com.mongodb.internal.connection.Connection) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) WriteBinding(com.mongodb.internal.binding.WriteBinding) Assertions(com.mongodb.assertions.Assertions) MongoConnectionPoolClearedException(com.mongodb.MongoConnectionPoolClearedException) VisibleForTesting(com.mongodb.internal.VisibleForTesting) AsyncWriteBinding(com.mongodb.internal.binding.AsyncWriteBinding) AsyncConnectionSource(com.mongodb.internal.binding.AsyncConnectionSource) FieldNameValidator(org.bson.FieldNameValidator) OperationHelper.canRetryWrite(com.mongodb.internal.operation.OperationHelper.canRetryWrite) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) Nullable(com.mongodb.lang.Nullable) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) AttachmentKeys(com.mongodb.internal.operation.retry.AttachmentKeys) LOGGER(com.mongodb.internal.operation.OperationHelper.LOGGER) BsonDocument(org.bson.BsonDocument) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) RetryState(com.mongodb.internal.async.function.RetryState)

Example 2 with SingleResultCallback

use of com.mongodb.internal.async.SingleResultCallback in project mongo-java-driver by mongodb.

the class FindOperation method exceptionTransformingCallback.

private static <T> SingleResultCallback<T> exceptionTransformingCallback(final SingleResultCallback<T> callback) {
    return new SingleResultCallback<T>() {

        @Override
        public void onResult(final T result, final Throwable t) {
            if (t != null) {
                if (t instanceof MongoCommandException) {
                    MongoCommandException commandException = (MongoCommandException) t;
                    callback.onResult(result, new MongoQueryException(commandException.getServerAddress(), commandException.getErrorCode(), commandException.getErrorMessage()));
                } else {
                    callback.onResult(result, t);
                }
            } else {
                callback.onResult(result, null);
            }
        }
    };
}
Also used : MongoCommandException(com.mongodb.MongoCommandException) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) MongoQueryException(com.mongodb.MongoQueryException)

Example 3 with SingleResultCallback

use of com.mongodb.internal.async.SingleResultCallback in project mongo-java-driver by mongodb.

the class ListIndexesOperation method executeAsync.

@Override
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<AsyncBatchCursor<T>> callback) {
    RetryState retryState = initialRetryState(retryReads);
    binding.retain();
    AsyncCallbackSupplier<AsyncBatchCursor<T>> asyncRead = CommandOperationHelper.<AsyncBatchCursor<T>>decorateReadWithRetries(retryState, funcCallback -> {
        logRetryExecute(retryState);
        withAsyncSourceAndConnection(binding::getReadConnectionSource, false, funcCallback, (source, connection, releasingCallback) -> {
            if (retryState.breakAndCompleteIfRetryAnd(() -> !canRetryRead(source.getServerDescription(), connection.getDescription(), binding.getSessionContext()), releasingCallback)) {
                return;
            }
            if (serverIsAtLeastVersionThreeDotZero(connection.getDescription())) {
                createReadCommandAndExecuteAsync(retryState, binding, source, namespace.getDatabaseName(), getCommandCreator(), createCommandDecoder(), asyncTransformer(), connection, (result, t) -> {
                    if (t != null && !isNamespaceError(t)) {
                        releasingCallback.onResult(null, t);
                    } else {
                        releasingCallback.onResult(result != null ? result : emptyAsyncCursor(source), null);
                    }
                });
            } else {
                retryState.markAsLastAttempt();
                connection.queryAsync(getIndexNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSecondaryOk(), false, false, false, false, false, decoder, binding.getRequestContext(), new SingleResultCallback<QueryResult<T>>() {

                    @Override
                    public void onResult(final QueryResult<T> result, final Throwable t) {
                        if (t != null) {
                            releasingCallback.onResult(null, t);
                        } else {
                            releasingCallback.onResult(new AsyncQueryBatchCursor<T>(result, 0, batchSize, 0, decoder, source, connection), null);
                        }
                    }
                });
            }
        });
    }).whenComplete(binding::release);
    asyncRead.get(errorHandlingCallback(callback, LOGGER));
}
Also used : ReadPreference(com.mongodb.ReadPreference) AsyncReadBinding(com.mongodb.internal.binding.AsyncReadBinding) ServerDescription(com.mongodb.connection.ServerDescription) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) CommandOperationHelper.logRetryExecute(com.mongodb.internal.operation.CommandOperationHelper.logRetryExecute) CommandCreator(com.mongodb.internal.operation.CommandOperationHelper.CommandCreator) OperationHelper.cursorDocumentToBatchCursor(com.mongodb.internal.operation.OperationHelper.cursorDocumentToBatchCursor) MongoCommandException(com.mongodb.MongoCommandException) ErrorHandlingResultCallback.errorHandlingCallback(com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback) CommandReadTransformer(com.mongodb.internal.operation.CommandOperationHelper.CommandReadTransformer) BsonString(org.bson.BsonString) CommandOperationHelper.createReadCommandAndExecuteAsync(com.mongodb.internal.operation.CommandOperationHelper.createReadCommandAndExecuteAsync) Supplier(java.util.function.Supplier) BsonDocument(org.bson.BsonDocument) ConnectionDescription(com.mongodb.connection.ConnectionDescription) LOGGER(com.mongodb.internal.operation.OperationHelper.LOGGER) Connection(com.mongodb.internal.connection.Connection) SHARD_ROUTER(com.mongodb.connection.ServerType.SHARD_ROUTER) BsonInt64(org.bson.BsonInt64) AsyncConnectionSource(com.mongodb.internal.binding.AsyncConnectionSource) CommandOperationHelper.isNamespaceError(com.mongodb.internal.operation.CommandOperationHelper.isNamespaceError) CursorHelper.getCursorDocumentFromBatchSize(com.mongodb.internal.operation.CursorHelper.getCursorDocumentFromBatchSize) OperationHelper.canRetryRead(com.mongodb.internal.operation.OperationHelper.canRetryRead) OperationHelper.createEmptyBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyBatchCursor) QueryResult(com.mongodb.internal.connection.QueryResult) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) MongoNamespace(com.mongodb.MongoNamespace) ConnectionSource(com.mongodb.internal.binding.ConnectionSource) CommandOperationHelper.createReadCommandAndExecute(com.mongodb.internal.operation.CommandOperationHelper.createReadCommandAndExecute) ReadBinding(com.mongodb.internal.binding.ReadBinding) AsyncCallbackSupplier(com.mongodb.internal.async.function.AsyncCallbackSupplier) OperationHelper.cursorDocumentToAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.cursorDocumentToAsyncBatchCursor) CommandOperationHelper.rethrowIfNotNamespaceError(com.mongodb.internal.operation.CommandOperationHelper.rethrowIfNotNamespaceError) CommandOperationHelper.decorateReadWithRetries(com.mongodb.internal.operation.CommandOperationHelper.decorateReadWithRetries) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) Decoder(org.bson.codecs.Decoder) TimeUnit(java.util.concurrent.TimeUnit) CommandReadTransformerAsync(com.mongodb.internal.operation.CommandOperationHelper.CommandReadTransformerAsync) RetryState(com.mongodb.internal.async.function.RetryState) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) Codec(org.bson.codecs.Codec) ReadPreference.primary(com.mongodb.ReadPreference.primary) OperationHelper.createEmptyAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyAsyncBatchCursor) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) ServerVersionHelper.serverIsAtLeastVersionThreeDotZero(com.mongodb.internal.operation.ServerVersionHelper.serverIsAtLeastVersionThreeDotZero) QueryResult(com.mongodb.internal.connection.QueryResult) OperationHelper.cursorDocumentToAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.cursorDocumentToAsyncBatchCursor) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) OperationHelper.createEmptyAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyAsyncBatchCursor) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) RetryState(com.mongodb.internal.async.function.RetryState)

Example 4 with SingleResultCallback

use of com.mongodb.internal.async.SingleResultCallback in project mongo-java-driver by mongodb.

the class MixedBulkWriteOperation method executeAsync.

public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<BulkWriteResult> callback) {
    // see the comment in `execute(WriteBinding)` explaining the manual tracking of attempts
    RetryState retryState = new RetryState();
    BulkWriteTracker.attachNew(retryState, retryWrites);
    binding.retain();
    AsyncCallbackSupplier<BulkWriteResult> retryingBulkWrite = this.<BulkWriteResult>decorateWriteWithRetries(retryState, funcCallback -> {
        logRetryExecute(retryState);
        withAsyncSourceAndConnection(binding::getWriteConnectionSource, true, funcCallback, (source, connection, releasingCallback) -> {
            ConnectionDescription connectionDescription = connection.getDescription();
            int maxWireVersion = connectionDescription.getMaxWireVersion();
            // attach `maxWireVersion` ASAP because it is used to check whether we can retry
            retryState.attach(AttachmentKeys.maxWireVersion(), maxWireVersion, true);
            BulkWriteTracker bulkWriteTracker = retryState.attachment(AttachmentKeys.bulkWriteTracker()).orElseThrow(Assertions::fail);
            SessionContext sessionContext = binding.getSessionContext();
            WriteConcern writeConcern = getAppliedWriteConcern(sessionContext);
            if (!retryState.isFirstAttempt() && !isRetryableWrite(retryWrites, writeConcern, source.getServerDescription(), connectionDescription, sessionContext)) {
                Throwable prospectiveFailedResult = retryState.exception().orElse(null);
                if (retryState.breakAndCompleteIfRetryAnd(() -> !(prospectiveFailedResult instanceof MongoWriteConcernWithResponseException), releasingCallback)) {
                    return;
                }
                bulkWriteTracker.batch().ifPresent(bulkWriteBatch -> {
                    assertTrue(prospectiveFailedResult instanceof MongoWriteConcernWithResponseException);
                    bulkWriteBatch.addResult((BsonDocument) ((MongoWriteConcernWithResponseException) prospectiveFailedResult).getResponse());
                    BulkWriteTracker.attachNext(retryState, bulkWriteBatch);
                });
            }
            if (validateWriteRequestsAndCompleteIfInvalid(connectionDescription, bypassDocumentValidation, writeRequests, writeConcern, releasingCallback)) {
                return;
            }
            if (writeConcern.isAcknowledged() || serverIsAtLeastVersionThreeDotSix(connectionDescription)) {
                try {
                    if (!bulkWriteTracker.batch().isPresent()) {
                        BulkWriteTracker.attachNew(retryState, BulkWriteBatch.createBulkWriteBatch(namespace, source.getServerDescription(), connectionDescription, ordered, writeConcern, bypassDocumentValidation, retryWrites, writeRequests, sessionContext));
                    }
                } catch (Throwable t) {
                    releasingCallback.onResult(null, t);
                    return;
                }
                logRetryExecute(retryState);
                executeBulkWriteBatchAsync(retryState, binding, connection, maxWireVersion, releasingCallback);
            } else {
                retryState.markAsLastAttempt();
                executeLegacyBatchesAsync(binding, connection, releasingCallback);
            }
        });
    }).whenComplete(binding::release);
    retryingBulkWrite.get(exceptionTransformingCallback(errorHandlingCallback(callback, LOGGER)));
}
Also used : LoopState(com.mongodb.internal.async.function.LoopState) WriteRequest(com.mongodb.internal.bulk.WriteRequest) CommandOperationHelper.addRetryableWriteErrorLabel(com.mongodb.internal.operation.CommandOperationHelper.addRetryableWriteErrorLabel) MongoBulkWriteException(com.mongodb.MongoBulkWriteException) MongoWriteConcernWithResponseException(com.mongodb.internal.connection.MongoWriteConcernWithResponseException) ProtocolHelper(com.mongodb.internal.connection.ProtocolHelper) ConnectionDescription(com.mongodb.connection.ConnectionDescription) BsonArray(org.bson.BsonArray) OperationHelper.validateWriteRequests(com.mongodb.internal.operation.OperationHelper.validateWriteRequests) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) MongoException(com.mongodb.MongoException) AsyncCallbackSupplier(com.mongodb.internal.async.function.AsyncCallbackSupplier) Set(java.util.Set) Collectors(java.util.stream.Collectors) AsyncCallbackRunnable(com.mongodb.internal.async.function.AsyncCallbackRunnable) ServerVersionHelper.serverIsAtLeastVersionThreeDotSix(com.mongodb.internal.operation.ServerVersionHelper.serverIsAtLeastVersionThreeDotSix) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) REPLACE(com.mongodb.internal.bulk.WriteRequest.Type.REPLACE) RetryState(com.mongodb.internal.async.function.RetryState) List(java.util.List) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) Optional(java.util.Optional) RetryingSyncSupplier(com.mongodb.internal.async.function.RetryingSyncSupplier) InsertRequest(com.mongodb.internal.bulk.InsertRequest) RetryingAsyncCallbackSupplier(com.mongodb.internal.async.function.RetryingAsyncCallbackSupplier) CommandOperationHelper.logRetryExecute(com.mongodb.internal.operation.CommandOperationHelper.logRetryExecute) CommandOperationHelper.exceptionTransformingCallback(com.mongodb.internal.operation.CommandOperationHelper.exceptionTransformingCallback) ErrorHandlingResultCallback.errorHandlingCallback(com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback) BsonString(org.bson.BsonString) Supplier(java.util.function.Supplier) BsonDocument(org.bson.BsonDocument) LOGGER(com.mongodb.internal.operation.OperationHelper.LOGGER) Connection(com.mongodb.internal.connection.Connection) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) WriteBinding(com.mongodb.internal.binding.WriteBinding) Assertions(com.mongodb.assertions.Assertions) WriteConcernResult(com.mongodb.WriteConcernResult) AsyncCallbackLoop(com.mongodb.internal.async.function.AsyncCallbackLoop) AsyncWriteBinding(com.mongodb.internal.binding.AsyncWriteBinding) DeleteRequest(com.mongodb.internal.bulk.DeleteRequest) SessionContext(com.mongodb.internal.session.SessionContext) FieldNameValidator(org.bson.FieldNameValidator) OperationHelper.validateWriteRequestsAndCompleteIfInvalid(com.mongodb.internal.operation.OperationHelper.validateWriteRequestsAndCompleteIfInvalid) INSERT(com.mongodb.internal.bulk.WriteRequest.Type.INSERT) MongoNamespace(com.mongodb.MongoNamespace) UpdateRequest(com.mongodb.internal.bulk.UpdateRequest) OperationHelper.isRetryableWrite(com.mongodb.internal.operation.OperationHelper.isRetryableWrite) CommandOperationHelper.transformWriteException(com.mongodb.internal.operation.CommandOperationHelper.transformWriteException) Assertions.isTrueArgument(com.mongodb.assertions.Assertions.isTrueArgument) Assertions.assertTrue(com.mongodb.assertions.Assertions.assertTrue) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) Nullable(com.mongodb.lang.Nullable) WriteConcern(com.mongodb.WriteConcern) UPDATE(com.mongodb.internal.bulk.WriteRequest.Type.UPDATE) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) AttachmentKeys(com.mongodb.internal.operation.retry.AttachmentKeys) ConnectionDescription(com.mongodb.connection.ConnectionDescription) MongoWriteConcernWithResponseException(com.mongodb.internal.connection.MongoWriteConcernWithResponseException) BsonDocument(org.bson.BsonDocument) WriteConcern(com.mongodb.WriteConcern) SessionContext(com.mongodb.internal.session.SessionContext) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) RetryState(com.mongodb.internal.async.function.RetryState)

Example 5 with SingleResultCallback

use of com.mongodb.internal.async.SingleResultCallback in project mongo-java-driver by mongodb.

the class MixedBulkWriteOperation method executeLegacyBatchesAsync.

private void executeLegacyBatchesAsync(final AsyncWriteBinding binding, final AsyncConnection connection, final SingleResultCallback<BulkWriteResult> callback) {
    List<? extends WriteRequest> writeRequests = getWriteRequests();
    LoopState loopState = new LoopState();
    AsyncCallbackRunnable loop = new AsyncCallbackLoop(loopState, iterationCallback -> {
        int i = loopState.iteration();
        if (loopState.breakAndCompleteIf(() -> i == writeRequests.size(), iterationCallback)) {
            return;
        }
        WriteRequest writeRequest = writeRequests.get(i);
        SingleResultCallback<WriteConcernResult> commandCallback = (ignored, t) -> iterationCallback.onResult(null, t);
        if (writeRequest.getType() == INSERT) {
            connection.insertAsync(getNamespace(), isOrdered(), (InsertRequest) writeRequest, binding.getRequestContext(), commandCallback);
        } else if (writeRequest.getType() == UPDATE || writeRequest.getType() == REPLACE) {
            connection.updateAsync(getNamespace(), isOrdered(), (UpdateRequest) writeRequest, binding.getRequestContext(), commandCallback);
        } else {
            connection.deleteAsync(getNamespace(), isOrdered(), (DeleteRequest) writeRequest, binding.getRequestContext(), commandCallback);
        }
    });
    loop.run((voidResult, t) -> {
        if (t != null) {
            callback.onResult(null, t);
        } else {
            callback.onResult(BulkWriteResult.unacknowledged(), null);
        }
    });
}
Also used : LoopState(com.mongodb.internal.async.function.LoopState) AsyncCallbackRunnable(com.mongodb.internal.async.function.AsyncCallbackRunnable) LoopState(com.mongodb.internal.async.function.LoopState) WriteRequest(com.mongodb.internal.bulk.WriteRequest) CommandOperationHelper.addRetryableWriteErrorLabel(com.mongodb.internal.operation.CommandOperationHelper.addRetryableWriteErrorLabel) MongoBulkWriteException(com.mongodb.MongoBulkWriteException) MongoWriteConcernWithResponseException(com.mongodb.internal.connection.MongoWriteConcernWithResponseException) ProtocolHelper(com.mongodb.internal.connection.ProtocolHelper) ConnectionDescription(com.mongodb.connection.ConnectionDescription) BsonArray(org.bson.BsonArray) OperationHelper.validateWriteRequests(com.mongodb.internal.operation.OperationHelper.validateWriteRequests) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) MongoException(com.mongodb.MongoException) AsyncCallbackSupplier(com.mongodb.internal.async.function.AsyncCallbackSupplier) Set(java.util.Set) Collectors(java.util.stream.Collectors) AsyncCallbackRunnable(com.mongodb.internal.async.function.AsyncCallbackRunnable) ServerVersionHelper.serverIsAtLeastVersionThreeDotSix(com.mongodb.internal.operation.ServerVersionHelper.serverIsAtLeastVersionThreeDotSix) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) REPLACE(com.mongodb.internal.bulk.WriteRequest.Type.REPLACE) RetryState(com.mongodb.internal.async.function.RetryState) List(java.util.List) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) Optional(java.util.Optional) RetryingSyncSupplier(com.mongodb.internal.async.function.RetryingSyncSupplier) InsertRequest(com.mongodb.internal.bulk.InsertRequest) RetryingAsyncCallbackSupplier(com.mongodb.internal.async.function.RetryingAsyncCallbackSupplier) CommandOperationHelper.logRetryExecute(com.mongodb.internal.operation.CommandOperationHelper.logRetryExecute) CommandOperationHelper.exceptionTransformingCallback(com.mongodb.internal.operation.CommandOperationHelper.exceptionTransformingCallback) ErrorHandlingResultCallback.errorHandlingCallback(com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback) BsonString(org.bson.BsonString) Supplier(java.util.function.Supplier) BsonDocument(org.bson.BsonDocument) LOGGER(com.mongodb.internal.operation.OperationHelper.LOGGER) Connection(com.mongodb.internal.connection.Connection) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) WriteBinding(com.mongodb.internal.binding.WriteBinding) Assertions(com.mongodb.assertions.Assertions) WriteConcernResult(com.mongodb.WriteConcernResult) AsyncCallbackLoop(com.mongodb.internal.async.function.AsyncCallbackLoop) AsyncWriteBinding(com.mongodb.internal.binding.AsyncWriteBinding) DeleteRequest(com.mongodb.internal.bulk.DeleteRequest) SessionContext(com.mongodb.internal.session.SessionContext) FieldNameValidator(org.bson.FieldNameValidator) OperationHelper.validateWriteRequestsAndCompleteIfInvalid(com.mongodb.internal.operation.OperationHelper.validateWriteRequestsAndCompleteIfInvalid) INSERT(com.mongodb.internal.bulk.WriteRequest.Type.INSERT) MongoNamespace(com.mongodb.MongoNamespace) UpdateRequest(com.mongodb.internal.bulk.UpdateRequest) OperationHelper.isRetryableWrite(com.mongodb.internal.operation.OperationHelper.isRetryableWrite) CommandOperationHelper.transformWriteException(com.mongodb.internal.operation.CommandOperationHelper.transformWriteException) Assertions.isTrueArgument(com.mongodb.assertions.Assertions.isTrueArgument) Assertions.assertTrue(com.mongodb.assertions.Assertions.assertTrue) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) Nullable(com.mongodb.lang.Nullable) WriteConcern(com.mongodb.WriteConcern) UPDATE(com.mongodb.internal.bulk.WriteRequest.Type.UPDATE) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) AttachmentKeys(com.mongodb.internal.operation.retry.AttachmentKeys) WriteConcernResult(com.mongodb.WriteConcernResult) UpdateRequest(com.mongodb.internal.bulk.UpdateRequest) WriteRequest(com.mongodb.internal.bulk.WriteRequest) AsyncCallbackLoop(com.mongodb.internal.async.function.AsyncCallbackLoop) DeleteRequest(com.mongodb.internal.bulk.DeleteRequest)

Aggregations

SingleResultCallback (com.mongodb.internal.async.SingleResultCallback)13 ConnectionDescription (com.mongodb.connection.ConnectionDescription)10 Assertions.notNull (com.mongodb.assertions.Assertions.notNull)8 ErrorHandlingResultCallback.errorHandlingCallback (com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback)8 AsyncConnection (com.mongodb.internal.connection.AsyncConnection)8 Connection (com.mongodb.internal.connection.Connection)8 List (java.util.List)8 Supplier (java.util.function.Supplier)8 BsonDocument (org.bson.BsonDocument)8 AsyncCallbackSupplier (com.mongodb.internal.async.function.AsyncCallbackSupplier)7 RetryState (com.mongodb.internal.async.function.RetryState)7 LOGGER (com.mongodb.internal.operation.OperationHelper.LOGGER)7 OperationHelper.withAsyncSourceAndConnection (com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection)7 OperationHelper.withSourceAndConnection (com.mongodb.internal.operation.OperationHelper.withSourceAndConnection)7 Nullable (com.mongodb.lang.Nullable)7 Decoder (org.bson.codecs.Decoder)7 MongoCommandException (com.mongodb.MongoCommandException)6 MongoException (com.mongodb.MongoException)6 MongoNamespace (com.mongodb.MongoNamespace)6 ReadPreference (com.mongodb.ReadPreference)6