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);
}
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--;
}
}
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();
}
}
Aggregations