Search in sources :

Example 1 with Logger

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);
            }
        }
    }));
}
Also used : SdamIssue(com.mongodb.internal.connection.SdamServerDescriptionManager.SdamIssue) ServerDescription(com.mongodb.connection.ServerDescription) ConcurrentPool.lockUnfair(com.mongodb.internal.connection.ConcurrentPool.lockUnfair) ConnectionPoolCreatedEvent(com.mongodb.event.ConnectionPoolCreatedEvent) ConnectionDescription(com.mongodb.connection.ConnectionDescription) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentPool.sizeToString(com.mongodb.internal.connection.ConcurrentPool.sizeToString) MongoServerUnavailableException(com.mongodb.MongoServerUnavailableException) ConnectionCheckedOutEvent(com.mongodb.event.ConnectionCheckedOutEvent) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Prune(com.mongodb.internal.connection.ConcurrentPool.Prune) MongoException(com.mongodb.MongoException) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) Assertions.assertFalse(com.mongodb.assertions.Assertions.assertFalse) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ConnectionPoolClearedEvent(com.mongodb.event.ConnectionPoolClearedEvent) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) Decoder(org.bson.codecs.Decoder) PRIVATE(com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE) List(java.util.List) Assertions.notNull(com.mongodb.assertions.Assertions.notNull) NonNull(com.mongodb.lang.NonNull) Assertions.fail(com.mongodb.assertions.Assertions.fail) Optional(java.util.Optional) ThreadSafe(com.mongodb.annotations.ThreadSafe) Reason(com.mongodb.event.ConnectionCheckOutFailedEvent.Reason) Queue(java.util.Queue) ConnectionClosedEvent(com.mongodb.event.ConnectionClosedEvent) NotThreadSafe(com.mongodb.annotations.NotThreadSafe) ConnectionPoolSettings(com.mongodb.connection.ConnectionPoolSettings) LongAdder(java.util.concurrent.atomic.LongAdder) ConnectionCheckedInEvent(com.mongodb.event.ConnectionCheckedInEvent) Assertions.assertNotNull(com.mongodb.assertions.Assertions.assertNotNull) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) ErrorHandlingResultCallback.errorHandlingCallback(com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Deque(java.util.Deque) ConcurrentPool.lockInterruptibly(com.mongodb.internal.connection.ConcurrentPool.lockInterruptibly) Supplier(java.util.function.Supplier) INFINITE_SIZE(com.mongodb.internal.connection.ConcurrentPool.INFINITE_SIZE) Assertions.isTrue(com.mongodb.assertions.Assertions.isTrue) MongoConnectionPoolClearedException(com.mongodb.MongoConnectionPoolClearedException) VisibleForTesting(com.mongodb.internal.VisibleForTesting) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SessionContext(com.mongodb.internal.session.SessionContext) ConnectionCreatedEvent(com.mongodb.event.ConnectionCreatedEvent) LinkedList(java.util.LinkedList) Logger(com.mongodb.diagnostics.logging.Logger) ExecutorService(java.util.concurrent.ExecutorService) ConnectionReadyEvent(com.mongodb.event.ConnectionReadyEvent) ByteBuf(org.bson.ByteBuf) MongoInterruptedException(com.mongodb.MongoInterruptedException) ConnectionPoolListener(com.mongodb.event.ConnectionPoolListener) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EventListenerHelper.getConnectionPoolListener(com.mongodb.internal.event.EventListenerHelper.getConnectionPoolListener) ServerId(com.mongodb.connection.ServerId) RequestContext(com.mongodb.RequestContext) Timeout(com.mongodb.internal.Timeout) MongoTimeoutException(com.mongodb.MongoTimeoutException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConnectionPoolClosedEvent(com.mongodb.event.ConnectionPoolClosedEvent) OptionalProvider(com.mongodb.internal.inject.OptionalProvider) ConnectionPoolReadyEvent(com.mongodb.event.ConnectionPoolReadyEvent) Condition(java.util.concurrent.locks.Condition) Lock(java.util.concurrent.locks.Lock) Assertions.assertNull(com.mongodb.assertions.Assertions.assertNull) ConnectionCheckOutStartedEvent(com.mongodb.event.ConnectionCheckOutStartedEvent) Assertions.assertTrue(com.mongodb.assertions.Assertions.assertTrue) Loggers(com.mongodb.diagnostics.logging.Loggers) DaemonThreadFactory(com.mongodb.internal.thread.DaemonThreadFactory) ObjectId(org.bson.types.ObjectId) Nullable(com.mongodb.lang.Nullable) ConnectionId(com.mongodb.connection.ConnectionId) ConnectionCheckOutFailedEvent(com.mongodb.event.ConnectionCheckOutFailedEvent) StampedLock(java.util.concurrent.locks.StampedLock) ConnectionCheckedOutEvent(com.mongodb.event.ConnectionCheckedOutEvent) Timeout(com.mongodb.internal.Timeout) SingleResultCallback(com.mongodb.internal.async.SingleResultCallback) ConnectionCheckOutStartedEvent(com.mongodb.event.ConnectionCheckOutStartedEvent)

Aggregations

MongoConnectionPoolClearedException (com.mongodb.MongoConnectionPoolClearedException)1 MongoException (com.mongodb.MongoException)1 MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoServerUnavailableException (com.mongodb.MongoServerUnavailableException)1 MongoTimeoutException (com.mongodb.MongoTimeoutException)1 RequestContext (com.mongodb.RequestContext)1 NotThreadSafe (com.mongodb.annotations.NotThreadSafe)1 ThreadSafe (com.mongodb.annotations.ThreadSafe)1 Assertions.assertFalse (com.mongodb.assertions.Assertions.assertFalse)1 Assertions.assertNotNull (com.mongodb.assertions.Assertions.assertNotNull)1 Assertions.assertNull (com.mongodb.assertions.Assertions.assertNull)1 Assertions.assertTrue (com.mongodb.assertions.Assertions.assertTrue)1 Assertions.fail (com.mongodb.assertions.Assertions.fail)1 Assertions.isTrue (com.mongodb.assertions.Assertions.isTrue)1 Assertions.notNull (com.mongodb.assertions.Assertions.notNull)1 ConnectionDescription (com.mongodb.connection.ConnectionDescription)1 ConnectionId (com.mongodb.connection.ConnectionId)1 ConnectionPoolSettings (com.mongodb.connection.ConnectionPoolSettings)1 ServerDescription (com.mongodb.connection.ServerDescription)1 ServerId (com.mongodb.connection.ServerId)1