use of com.mongodb.diagnostics.logging.Logger in project mongo-java-driver by mongodb.
the class DefaultConnectionPool method getAsync.
@Override
public void getAsync(final SingleResultCallback<InternalConnection> callback) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(format("Asynchronously getting a connection from the pool for server %s", serverId));
}
connectionPoolListener.connectionCheckOutStarted(new ConnectionCheckOutStartedEvent(serverId));
Timeout timeout = Timeout.startNow(settings.getMaxWaitTime(NANOSECONDS));
SingleResultCallback<InternalConnection> eventSendingCallback = (result, failure) -> {
SingleResultCallback<InternalConnection> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
if (failure == null) {
connectionPoolListener.connectionCheckedOut(new ConnectionCheckedOutEvent(getId(result)));
errHandlingCallback.onResult(result, null);
} else {
errHandlingCallback.onResult(null, checkOutFailed(failure));
}
};
try {
stateAndGeneration.throwIfClosedOrPaused();
} catch (RuntimeException e) {
eventSendingCallback.onResult(null, e);
return;
}
asyncWorkManager.enqueue(new Task(timeout, t -> {
if (t != null) {
eventSendingCallback.onResult(null, t);
} else {
PooledConnection connection;
try {
connection = getPooledConnection(timeout);
} catch (RuntimeException e) {
eventSendingCallback.onResult(null, e);
return;
}
if (connection.opened()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(format("Pooled connection %s to server %s is already open", getId(connection), serverId));
}
eventSendingCallback.onResult(connection, null);
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(format("Pooled connection %s to server %s is not yet open", getId(connection), serverId));
}
openConcurrencyLimiter.openAsyncWithConcurrencyLimit(connection, timeout, eventSendingCallback);
}
}
}));
}
Aggregations