static <D, T> void executeWrappedCommandProtocolAsync(final AsyncReadBinding binding, final String database, final BsonDocument command, final Decoder<D> decoder, final CommandTransformer<D, T> transformer, final SingleResultCallback<T> callback) { binding.getReadConnectionSource(new CommandProtocolExecutingCallback<D, T>(database, command, new NoOpFieldNameValidator(), decoder, binding.getReadPreference(), transformer, binding.getSessionContext(), errorHandlingCallback(callback, LOGGER))); }
@Override public void close() { wrapped.close(); binding.release(); }
AsyncChangeStreamBatchCursor(final ChangeStreamOperation<T> changeStreamOperation, final AsyncBatchCursor<RawBsonDocument> wrapped, final AsyncReadBinding binding) { changeStreamOperation.startOperationTimeForResume(binding.getSessionContext().getOperationTime()); this.changeStreamOperation = changeStreamOperation; this.resumeToken = changeStreamOperation.getResumeToken(); this.wrapped = wrapped; this.binding = binding; binding.retain(); }
static <T> void executeWrappedCommandProtocolAsync(final AsyncReadBinding binding, final String database, final BsonDocument command, final Decoder<BsonDocument> decoder, final AsyncConnection connection, final CommandTransformer<BsonDocument, T> transformer, final SingleResultCallback<T> callback) { notNull("binding", binding); executeWrappedCommandProtocolAsync(database, command, decoder, connection, binding.getReadPreference(), transformer, binding.getSessionContext(), callback); }
@Override public void call(final AsyncConnection connection, final Throwable t) { SingleResultCallback<Long> errHandlingCallback = errorHandlingCallback(callback, LOGGER); if (t != null) { errHandlingCallback.onResult(null, t); } else { final SingleResultCallback<Long> wrappedCallback = releasingCallback(errHandlingCallback, connection); validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation, new AsyncCallableWithConnection() { @Override public void call(final AsyncConnection connection, final Throwable t) { if (t != null) { wrappedCallback.onResult(null, t); } else { executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), DECODER, connection, transformer(), wrappedCallback); } } }); } } });
static void withConnection(final AsyncReadBinding binding, final AsyncCallableWithConnectionAndSource callable) { binding.getReadConnectionSource(errorHandlingCallback(new AsyncCallableWithConnectionAndSourceCallback(callable), LOGGER)); }
connection.queryAsync(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec(), new SingleResultCallback<QueryResult<BsonDocument>>() { @Override
@Override public void call(final AsyncConnection connection, final Throwable t) { SingleResultCallback<MapReduceAsyncBatchCursor<T>> errHandlingCallback = errorHandlingCallback(callback, LOGGER); if (t != null) { errHandlingCallback.onResult(null, t); } else { final SingleResultCallback<MapReduceAsyncBatchCursor<T>> wrappedCallback = releasingCallback( errHandlingCallback, connection); validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation, new AsyncCallableWithConnection() { @Override public void call(final AsyncConnection connection, final Throwable t) { if (t != null) { wrappedCallback.onResult(null, t); } else { executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, "results"), connection, asyncTransformer(connection), wrappedCallback); } } }); } } });
static <T> void executeWrappedCommandProtocolAsync(final AsyncReadBinding binding, final String database, final BsonDocument command, final Decoder<BsonDocument> decoder, final AsyncConnection connection, final CommandTransformer<BsonDocument, T> transformer, final SingleResultCallback<T> callback) { notNull("binding", binding); executeWrappedCommandProtocolAsync(database, command, decoder, connection, binding.getReadPreference(), transformer, binding.getSessionContext(), callback); }
static void withConnection(final AsyncReadBinding binding, final AsyncCallableWithConnection callable) { binding.getReadConnectionSource(errorHandlingCallback(new AsyncCallableWithConnectionCallback(callable), LOGGER)); }
connection.queryAsync(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec(), new SingleResultCallback<QueryResult<BsonDocument>>() { @Override
static <D, T> void executeWrappedCommandProtocolAsync(final AsyncReadBinding binding, final String database, final BsonDocument command, final Decoder<D> decoder, final CommandTransformer<D, T> transformer, final SingleResultCallback<T> callback) { binding.getReadConnectionSource(new CommandProtocolExecutingCallback<D, T>(database, command, new NoOpFieldNameValidator(), decoder, binding.getReadPreference(), transformer, binding.getSessionContext(), errorHandlingCallback(callback, LOGGER))); }
@Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { SingleResultCallback<AsyncBatchCursor<T>> errHandlingCallback = errorHandlingCallback(callback, LOGGER); if (t != null) { errHandlingCallback.onResult(null, t); } else { final SingleResultCallback<AsyncBatchCursor<T>> wrappedCallback = releasingCallback( errHandlingCallback, source, connection); validateReadConcernAndCollation(source, connection, binding.getSessionContext().getReadConcern(), collation, new AsyncCallableWithConnectionAndSource() { @Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { if (t != null) { wrappedCallback.onResult(null, t); } else { executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), createCommandDecoder(), connection, asyncTransformer(connection.getDescription()), wrappedCallback); } } }); } } });
AsyncChangeStreamBatchCursor(final ChangeStreamOperation<T> changeStreamOperation, final AsyncBatchCursor<RawBsonDocument> wrapped, final AsyncReadBinding binding) { changeStreamOperation.startOperationTimeForResume(binding.getSessionContext().getOperationTime()); this.changeStreamOperation = changeStreamOperation; this.resumeToken = changeStreamOperation.getResumeToken(); this.wrapped = wrapped; this.binding = binding; binding.retain(); }
@Override public void onResult(final AsyncBatchCursor<T> result, final Throwable t) { if (t != null) { callback.onResult(null, t); } else { wrapped = ((AsyncChangeStreamBatchCursor<T>) result).getWrapped(); binding.release(); // release the new change stream batch cursor's reference to the binding resumeableOperation(asyncBlock, callback); } } });
static void withConnection(final AsyncReadBinding binding, final AsyncCallableWithConnection callable) { binding.getReadConnectionSource(errorHandlingCallback(new AsyncCallableWithConnectionCallback(callable), LOGGER)); }
@Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { SingleResultCallback<List<AsyncBatchCursor<T>>> errHandlingCallback = errorHandlingCallback(callback, LOGGER); if (t != null) { errHandlingCallback.onResult(null, t); } else { final SingleResultCallback<List<AsyncBatchCursor<T>>> wrappedCallback = releasingCallback( errHandlingCallback, source, connection); validateReadConcern(source, connection, binding.getSessionContext().getReadConcern(), new AsyncCallableWithConnectionAndSource() { @Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { if (t != null) { wrappedCallback.onResult(null, t); } else { executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, "firstBatch"), connection, asyncTransformer(source, connection), wrappedCallback); } } }); } } });
@Override public void close() { wrapped.close(); binding.release(); }
static void withConnection(final AsyncReadBinding binding, final AsyncCallableWithConnectionAndSource callable) { binding.getReadConnectionSource(errorHandlingCallback(new AsyncCallableWithConnectionAndSourceCallback(callable), LOGGER)); }
@Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { SingleResultCallback<AsyncBatchCursor<T>> errHandlingCallback = errorHandlingCallback(callback, LOGGER); if (t != null) { errHandlingCallback.onResult(null, t); } else { final SingleResultCallback<AsyncBatchCursor<T>> wrappedCallback = releasingCallback(errHandlingCallback, source, connection); validateReadConcernAndCollation(source, connection, binding.getSessionContext().getReadConcern(), collation, new AsyncCallableWithConnectionAndSource() { @Override public void call(final AsyncConnectionSource source, final AsyncConnection connection, final Throwable t) { if (t != null) { wrappedCallback.onResult(null, t); } else { executeWrappedCommandProtocolAsync(binding, namespace.getDatabaseName(), getCommand(connection.getDescription(), binding.getSessionContext()), CommandResultDocumentCodec.create(decoder, FIELD_NAMES_WITH_RESULT), connection, asyncTransformer(source, connection), wrappedCallback); } } }); } } });