Search in sources :

Example 1 with AsyncConnection

use of com.aerospike.client.async.AsyncConnection in project aerospike-client-java by aerospike.

the class Node method getAsyncConnection.

public final AsyncConnection getAsyncConnection(int index, ByteBuffer byteBuffer) {
    AsyncPool pool = asyncConnectionPools[index];
    ArrayDeque<AsyncConnection> queue = pool.queue;
    AsyncConnection conn;
    while ((conn = queue.pollFirst()) != null) {
        if (!cluster.isConnCurrentTran(conn.getLastUsed())) {
            closeAsyncIdleConnection(conn, index);
            continue;
        }
        if (!conn.isValid(byteBuffer)) {
            closeAsyncConnection(conn, index);
            continue;
        }
        return conn;
    }
    if (pool.reserve()) {
        return null;
    }
    throw new AerospikeException.Connection(ResultCode.NO_MORE_CONNECTIONS, "Max async conns reached: " + this + ',' + index + ',' + pool.total + ',' + pool.queue.size() + ',' + pool.maxSize);
}
Also used : AsyncConnection(com.aerospike.client.async.AsyncConnection) AsyncConnection(com.aerospike.client.async.AsyncConnection) NettyConnection(com.aerospike.client.async.NettyConnection)

Example 2 with AsyncConnection

use of com.aerospike.client.async.AsyncConnection in project aerospike-client-java by aerospike.

the class Node method closeIdleAsyncConnections.

private final void closeIdleAsyncConnections(AsyncPool pool, int count) {
    ArrayDeque<AsyncConnection> queue = pool.queue;
    // Oldest connection is at end of queue.
    while (count > 0) {
        AsyncConnection conn = queue.peekLast();
        if (conn == null || cluster.isConnCurrentTrim(conn.getLastUsed())) {
            break;
        }
        // Pop connection from queue.
        queue.pollLast();
        pool.connectionClosed();
        conn.close();
        count--;
    }
}
Also used : AsyncConnection(com.aerospike.client.async.AsyncConnection)

Example 3 with AsyncConnection

use of com.aerospike.client.async.AsyncConnection in project aerospike-client-java by aerospike.

the class Node method closeAsyncConnections.

/**
 * Close asynchronous connections.
 * Must be called from event loop thread.
 */
public final void closeAsyncConnections(int index) {
    AsyncPool pool = asyncConnectionPools[index];
    AsyncConnection conn;
    while ((conn = pool.queue.poll()) != null) {
        conn.close();
    }
}
Also used : AsyncConnection(com.aerospike.client.async.AsyncConnection)

Aggregations

AsyncConnection (com.aerospike.client.async.AsyncConnection)3 NettyConnection (com.aerospike.client.async.NettyConnection)1