Search in sources :

Example 1 with AsyncReadBinding

use of com.mongodb.internal.binding.AsyncReadBinding 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 2 with AsyncReadBinding

use of com.mongodb.internal.binding.AsyncReadBinding in project mongo-java-driver by mongodb.

the class ListCollectionsOperation 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, databaseName, 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(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSecondaryOk(), false, false, false, false, false, new BsonDocumentCodec(), binding.getRequestContext(), new SingleResultCallback<QueryResult<BsonDocument>>() {

                    @Override
                    public void onResult(final QueryResult<BsonDocument> result, final Throwable t) {
                        if (t != null) {
                            releasingCallback.onResult(null, t);
                        } else {
                            releasingCallback.onResult(new ProjectingAsyncBatchCursor(new AsyncQueryBatchCursor<BsonDocument>(result, 0, batchSize, 0, new BsonDocumentCodec(), source, connection)), null);
                        }
                    }
                });
            }
        });
    }).whenComplete(binding::release);
    asyncRead.get(errorHandlingCallback(callback, LOGGER));
}
Also used : AsyncReadBinding(com.mongodb.internal.binding.AsyncReadBinding) ServerDescription(com.mongodb.connection.ServerDescription) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) ConnectionDescription(com.mongodb.connection.ConnectionDescription) Arrays.asList(java.util.Arrays.asList) BsonArray(org.bson.BsonArray) CursorHelper.getCursorDocumentFromBatchSize(com.mongodb.internal.operation.CursorHelper.getCursorDocumentFromBatchSize) OperationHelper.canRetryRead(com.mongodb.internal.operation.OperationHelper.canRetryRead) QueryResult(com.mongodb.internal.connection.QueryResult) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) ConnectionSource(com.mongodb.internal.binding.ConnectionSource) 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) String.format(java.lang.String.format) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) Decoder(org.bson.codecs.Decoder) CommandReadTransformerAsync(com.mongodb.internal.operation.CommandOperationHelper.CommandReadTransformerAsync) RetryState(com.mongodb.internal.async.function.RetryState) List(java.util.List) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) BsonDocumentReader(org.bson.BsonDocumentReader) Codec(org.bson.codecs.Codec) ReadPreference.primary(com.mongodb.ReadPreference.primary) OperationHelper.createEmptyAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyAsyncBatchCursor) ReadPreference(com.mongodb.ReadPreference) CommandOperationHelper.logRetryExecute(com.mongodb.internal.operation.CommandOperationHelper.logRetryExecute) CommandCreator(com.mongodb.internal.operation.CommandOperationHelper.CommandCreator) OperationHelper.cursorDocumentToBatchCursor(com.mongodb.internal.operation.OperationHelper.cursorDocumentToBatchCursor) BsonBoolean(org.bson.BsonBoolean) MongoCommandException(com.mongodb.MongoCommandException) ServerCursor(com.mongodb.ServerCursor) 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) ArrayList(java.util.ArrayList) 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) DecoderContext(org.bson.codecs.DecoderContext) CommandOperationHelper.isNamespaceError(com.mongodb.internal.operation.CommandOperationHelper.isNamespaceError) ServerAddress(com.mongodb.ServerAddress) OperationHelper.createEmptyBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyBatchCursor) MongoNamespace(com.mongodb.MongoNamespace) CommandOperationHelper.createReadCommandAndExecute(com.mongodb.internal.operation.CommandOperationHelper.createReadCommandAndExecute) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) CommandOperationHelper.decorateReadWithRetries(com.mongodb.internal.operation.CommandOperationHelper.decorateReadWithRetries) TimeUnit(java.util.concurrent.TimeUnit) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) BsonInt32(org.bson.BsonInt32) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) ServerVersionHelper.serverIsAtLeastVersionThreeDotZero(com.mongodb.internal.operation.ServerVersionHelper.serverIsAtLeastVersionThreeDotZero) BsonRegularExpression(org.bson.BsonRegularExpression) OperationHelper.cursorDocumentToAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.cursorDocumentToAsyncBatchCursor) OperationHelper.createEmptyAsyncBatchCursor(com.mongodb.internal.operation.OperationHelper.createEmptyAsyncBatchCursor) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) QueryResult(com.mongodb.internal.connection.QueryResult) BsonDocument(org.bson.BsonDocument) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) RetryState(com.mongodb.internal.async.function.RetryState)

Example 3 with AsyncReadBinding

use of com.mongodb.internal.binding.AsyncReadBinding in project mongo-java-driver by mongodb.

the class FindOperation 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 (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) {
                final SingleResultCallback<AsyncBatchCursor<T>> wrappedCallback = exceptionTransformingCallback(releasingCallback);
                createReadCommandAndExecuteAsync(retryState, binding, source, namespace.getDatabaseName(), getCommandCreator(binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, FIRST_BATCH), asyncTransformer(), connection, wrappedCallback);
            } else {
                retryState.markAsLastAttempt();
                validateFindOptions(source, connection, binding.getSessionContext().getReadConcern(), collation, allowDiskUse, new AsyncCallableWithConnectionAndSource() {

                    @Override
                    public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) {
                        if (t != null) {
                            releasingCallback.onResult(null, t);
                        } else {
                            connection.queryAsync(namespace, asDocument(connection.getDescription(), binding.getReadPreference()), projection, skip, limit, batchSize, isSecondaryOk() || binding.getReadPreference().isSecondaryOk(), isTailableCursor(), isAwaitData(), isNoCursorTimeout(), isPartial(), isOplogReplay(), 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, limit, batchSize, getMaxTimeForCursor(), decoder, source, connection), null);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        });
    }).whenComplete(binding::release);
    asyncRead.get(errorHandlingCallback(callback, LOGGER));
}
Also used : AsyncReadBinding(com.mongodb.internal.binding.AsyncReadBinding) ServerDescription(com.mongodb.connection.ServerDescription) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) BsonValue(org.bson.BsonValue) DocumentHelper.putIfNotNull(com.mongodb.internal.operation.DocumentHelper.putIfNotNull) ConnectionDescription(com.mongodb.connection.ConnectionDescription) ExplainHelper.asExplainCommand(com.mongodb.internal.operation.ExplainHelper.asExplainCommand) DocumentHelper.putIfNotNullOrEmpty(com.mongodb.internal.operation.DocumentHelper.putIfNotNullOrEmpty) MIN_WIRE_VERSION(com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION) CursorType(com.mongodb.CursorType) AsyncCallableWithConnectionAndSource(com.mongodb.internal.operation.OperationHelper.AsyncCallableWithConnectionAndSource) OperationHelper.validateFindOptions(com.mongodb.internal.operation.OperationHelper.validateFindOptions) OperationHelper.canRetryRead(com.mongodb.internal.operation.OperationHelper.canRetryRead) QueryResult(com.mongodb.internal.connection.QueryResult) OperationHelper.withSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withSourceAndConnection) ConnectionSource(com.mongodb.internal.binding.ConnectionSource) ReadBinding(com.mongodb.internal.binding.ReadBinding) AsyncCallbackSupplier(com.mongodb.internal.async.function.AsyncCallbackSupplier) OperationReadConcernHelper.appendReadConcernToCommand(com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand) NoOpSessionContext(com.mongodb.internal.connection.NoOpSessionContext) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) Decoder(org.bson.codecs.Decoder) RetryState(com.mongodb.internal.async.function.RetryState) CommandReadTransformerAsync(com.mongodb.internal.operation.CommandOperationHelper.CommandReadTransformerAsync) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) ReadPreference.primary(com.mongodb.ReadPreference.primary) ExplainVerbosity(com.mongodb.ExplainVerbosity) ReadPreference(com.mongodb.ReadPreference) CommandOperationHelper.logRetryExecute(com.mongodb.internal.operation.CommandOperationHelper.logRetryExecute) OperationHelper.cursorDocumentToQueryResult(com.mongodb.internal.operation.OperationHelper.cursorDocumentToQueryResult) CommandCreator(com.mongodb.internal.operation.CommandOperationHelper.CommandCreator) BsonBoolean(org.bson.BsonBoolean) 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) MongoQueryException(com.mongodb.MongoQueryException) Supplier(java.util.function.Supplier) BsonDocument(org.bson.BsonDocument) 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) ServerVersionHelper.serverIsAtLeastVersionThreeDotTwo(com.mongodb.internal.operation.ServerVersionHelper.serverIsAtLeastVersionThreeDotTwo) AsyncConnectionSource(com.mongodb.internal.binding.AsyncConnectionSource) SessionContext(com.mongodb.internal.session.SessionContext) Collation(com.mongodb.client.model.Collation) MongoNamespace(com.mongodb.MongoNamespace) CommandOperationHelper.createReadCommandAndExecute(com.mongodb.internal.operation.CommandOperationHelper.createReadCommandAndExecute) CommandOperationHelper.decorateReadWithRetries(com.mongodb.internal.operation.CommandOperationHelper.decorateReadWithRetries) TimeUnit(java.util.concurrent.TimeUnit) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) Assertions.isTrueArgument(com.mongodb.assertions.Assertions.isTrueArgument) OperationHelper.withAsyncSourceAndConnection(com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection) Nullable(com.mongodb.lang.Nullable) BsonInt32(org.bson.BsonInt32) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) AsyncBatchCursor(com.mongodb.internal.async.AsyncBatchCursor) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) QueryResult(com.mongodb.internal.connection.QueryResult) OperationHelper.cursorDocumentToQueryResult(com.mongodb.internal.operation.OperationHelper.cursorDocumentToQueryResult) AsyncConnectionSource(com.mongodb.internal.binding.AsyncConnectionSource) AsyncConnection(com.mongodb.internal.connection.AsyncConnection) AsyncCallableWithConnectionAndSource(com.mongodb.internal.operation.OperationHelper.AsyncCallableWithConnectionAndSource) CommandOperationHelper.initialRetryState(com.mongodb.internal.operation.CommandOperationHelper.initialRetryState) RetryState(com.mongodb.internal.async.function.RetryState)

Example 4 with AsyncReadBinding

use of com.mongodb.internal.binding.AsyncReadBinding in project mongo-java-driver by mongodb.

the class CommandOperationHelper method executeRetryableReadAsync.

static <D, T> void executeRetryableReadAsync(final AsyncReadBinding binding, final AsyncCallbackSupplier<AsyncConnectionSource> sourceAsyncSupplier, final String database, final CommandCreator commandCreator, final Decoder<D> decoder, final CommandReadTransformerAsync<D, T> transformer, final boolean retryReads, final SingleResultCallback<T> callback) {
    RetryState retryState = initialRetryState(retryReads);
    binding.retain();
    AsyncCallbackSupplier<T> asyncRead = CommandOperationHelper.<T>decorateReadWithRetries(retryState, funcCallback -> {
        logRetryExecute(retryState);
        withAsyncSourceAndConnection(sourceAsyncSupplier, false, funcCallback, (source, connection, releasingCallback) -> {
            if (retryState.breakAndCompleteIfRetryAnd(() -> !canRetryRead(source.getServerDescription(), connection.getDescription(), binding.getSessionContext()), releasingCallback)) {
                return;
            }
            createReadCommandAndExecuteAsync(retryState, binding, source, database, commandCreator, decoder, transformer, connection, releasingCallback);
        });
    }).whenComplete(binding::release);
    asyncRead.get(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) RetryState(com.mongodb.internal.async.function.RetryState)

Aggregations

MongoCommandException (com.mongodb.MongoCommandException)4 ReadPreference (com.mongodb.ReadPreference)4 ReadPreference.primary (com.mongodb.ReadPreference.primary)4 Assertions.notNull (com.mongodb.assertions.Assertions.notNull)4 ConnectionDescription (com.mongodb.connection.ConnectionDescription)4 ServerDescription (com.mongodb.connection.ServerDescription)4 ErrorHandlingResultCallback.errorHandlingCallback (com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback)4 SingleResultCallback (com.mongodb.internal.async.SingleResultCallback)4 AsyncCallbackSupplier (com.mongodb.internal.async.function.AsyncCallbackSupplier)4 RetryState (com.mongodb.internal.async.function.RetryState)4 AsyncConnectionSource (com.mongodb.internal.binding.AsyncConnectionSource)4 AsyncReadBinding (com.mongodb.internal.binding.AsyncReadBinding)4 ConnectionSource (com.mongodb.internal.binding.ConnectionSource)4 ReadBinding (com.mongodb.internal.binding.ReadBinding)4 AsyncConnection (com.mongodb.internal.connection.AsyncConnection)4 Connection (com.mongodb.internal.connection.Connection)4 LOGGER (com.mongodb.internal.operation.OperationHelper.LOGGER)4 OperationHelper.canRetryRead (com.mongodb.internal.operation.OperationHelper.canRetryRead)4 OperationHelper.withAsyncSourceAndConnection (com.mongodb.internal.operation.OperationHelper.withAsyncSourceAndConnection)4 OperationHelper.withSourceAndConnection (com.mongodb.internal.operation.OperationHelper.withSourceAndConnection)4