Search in sources :

Example 1 with ServerAddressSelector

use of com.mongodb.selector.ServerAddressSelector in project mongo-java-driver by mongodb.

the class ServerHelper method waitForLastRelease.

public static void waitForLastRelease(final ServerAddress address, final Cluster cluster) {
    DefaultServer server = (DefaultServer) cluster.selectServer(new ServerAddressSelector(address));
    DefaultConnectionPool connectionProvider = (DefaultConnectionPool) server.getConnectionPool();
    ConcurrentPool<UsageTrackingInternalConnection> pool = connectionProvider.getPool();
    long startTime = System.currentTimeMillis();
    while (pool.getInUseCount() > 0) {
        try {
            sleep(10);
            if (System.currentTimeMillis() > startTime + ClusterFixture.TIMEOUT * 1000) {
                throw new MongoTimeoutException("Timed out waiting for pool in use count to drop to 0.  Now at: " + pool.getInUseCount());
            }
        } catch (InterruptedException e) {
            throw new MongoInterruptedException("Interrupted", e);
        }
    }
}
Also used : ServerAddressSelector(com.mongodb.selector.ServerAddressSelector) MongoInterruptedException(com.mongodb.MongoInterruptedException) MongoTimeoutException(com.mongodb.MongoTimeoutException) MongoInterruptedException(com.mongodb.MongoInterruptedException)

Aggregations

MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoTimeoutException (com.mongodb.MongoTimeoutException)1 ServerAddressSelector (com.mongodb.selector.ServerAddressSelector)1