use of com.mongodb.operation.AsyncWriteOperation in project mongo-java-driver by mongodb.
the class MongoClientImpl method createOperationExecutor.
private static AsyncOperationExecutor createOperationExecutor(final MongoClientSettings settings, final Cluster cluster) {
return new AsyncOperationExecutor() {
@Override
public <T> void execute(final AsyncReadOperation<T> operation, final ReadPreference readPreference, final SingleResultCallback<T> callback) {
notNull("operation", operation);
notNull("readPreference", readPreference);
notNull("callback", callback);
final SingleResultCallback<T> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
final AsyncReadBinding binding = getReadWriteBinding(readPreference, cluster);
operation.executeAsync(binding, new SingleResultCallback<T>() {
@Override
public void onResult(final T result, final Throwable t) {
try {
errHandlingCallback.onResult(result, t);
} finally {
binding.release();
}
}
});
}
@Override
public <T> void execute(final AsyncWriteOperation<T> operation, final SingleResultCallback<T> callback) {
notNull("operation", operation);
notNull("callback", callback);
final AsyncWriteBinding binding = getReadWriteBinding(ReadPreference.primary(), cluster);
operation.executeAsync(binding, new SingleResultCallback<T>() {
@Override
public void onResult(final T result, final Throwable t) {
try {
errorHandlingCallback(callback, LOGGER).onResult(result, t);
} finally {
binding.release();
}
}
});
}
};
}
Aggregations