use of com.mongodb.async.SingleResultCallback in project mongo-java-driver by mongodb.
the class InternalStreamConnectionInitializer method initializeConnectionDescriptionAsync.
private void initializeConnectionDescriptionAsync(final InternalConnection internalConnection, final SingleResultCallback<ConnectionDescription> callback) {
executeCommandAsync("admin", createIsMasterCommand(), internalConnection, new SingleResultCallback<BsonDocument>() {
@Override
public void onResult(final BsonDocument isMasterResult, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
executeCommandAsync("admin", new BsonDocument("buildinfo", new BsonInt32(1)), internalConnection, new SingleResultCallback<BsonDocument>() {
@Override
public void onResult(final BsonDocument buildInfoResult, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
ConnectionId connectionId = internalConnection.getDescription().getConnectionId();
callback.onResult(createConnectionDescription(connectionId, isMasterResult, buildInfoResult), null);
}
}
});
}
}
});
}
use of com.mongodb.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);
}
}
};
}
use of com.mongodb.async.SingleResultCallback in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method delete.
@Override
public void delete(final BsonValue id, final SingleResultCallback<Void> callback) {
notNull("id", id);
notNull("callback", callback);
final SingleResultCallback<Void> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
filesCollection.deleteOne(new BsonDocument("_id", id), new SingleResultCallback<DeleteResult>() {
@Override
public void onResult(final DeleteResult filesResult, final Throwable t) {
if (t != null) {
errHandlingCallback.onResult(null, t);
} else {
chunksCollection.deleteMany(new BsonDocument("files_id", id), new SingleResultCallback<DeleteResult>() {
@Override
public void onResult(final DeleteResult chunksResult, final Throwable t) {
if (t != null) {
errHandlingCallback.onResult(null, t);
} else if (filesResult.wasAcknowledged() && filesResult.getDeletedCount() == 0) {
errHandlingCallback.onResult(null, new MongoGridFSException(format("No file found with the ObjectId: %s", id)));
} else {
errHandlingCallback.onResult(null, null);
}
}
});
}
}
});
}
use of com.mongodb.async.SingleResultCallback in project mongo-java-driver by mongodb.
the class InternalStreamConnection method openAsync.
@Override
public void openAsync(final SingleResultCallback<Void> callback) {
isTrue("Open already called", stream == null, callback);
try {
stream = streamFactory.create(serverId.getAddress());
} catch (Throwable t) {
callback.onResult(null, t);
return;
}
stream.openAsync(new AsyncCompletionHandler<Void>() {
@Override
public void completed(final Void aVoid) {
connectionInitializer.initializeAsync(InternalStreamConnection.this, new SingleResultCallback<ConnectionDescription>() {
@Override
public void onResult(final ConnectionDescription result, final Throwable t) {
if (t != null) {
close();
callback.onResult(null, t);
} else {
description = result;
opened.set(true);
connectionListener.connectionOpened(new ConnectionOpenedEvent(getId()));
if (LOGGER.isInfoEnabled()) {
LOGGER.info(format("Opened connection [%s] to %s", getId(), serverId.getAddress()));
}
callback.onResult(null, null);
}
}
});
}
@Override
public void failed(final Throwable t) {
callback.onResult(null, t);
}
});
}
use of com.mongodb.async.SingleResultCallback in project mongo-java-driver by mongodb.
the class MixedBulkWriteOperation method executeAsync.
@Override
public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<BulkWriteResult> callback) {
withConnection(binding, new AsyncCallableWithConnection() {
@Override
public void call(final AsyncConnection connection, final Throwable t) {
final SingleResultCallback<BulkWriteResult> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
if (t != null) {
errHandlingCallback.onResult(null, t);
} else {
validateWriteRequests(connection, bypassDocumentValidation, writeRequests, writeConcern, new AsyncCallableWithConnection() {
@Override
public void call(final AsyncConnection connection, final Throwable t) {
if (t != null) {
releasingCallback(errHandlingCallback, connection).onResult(null, t);
} else {
Iterator<Run> runs = getRunGenerator(connection.getDescription()).iterator();
executeRunsAsync(runs, connection, new BulkWriteBatchCombiner(connection.getDescription().getServerAddress(), ordered, writeConcern), errHandlingCallback);
}
}
});
}
}
});
}
Aggregations