Search in sources :

Example 1 with AsyncConnectorExecutor

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

the class Node method createMinConnections.

public final void createMinConnections() {
    // Create sync connections.
    for (Pool pool : connectionPools) {
        if (pool.minSize > 0) {
            createConnections(pool, pool.minSize);
        }
    }
    EventState[] eventState = cluster.eventState;
    if (eventState == null || cluster.asyncMinConnsPerNode <= 0) {
        return;
    }
    // Create async connections.
    final Monitor monitor = new Monitor();
    final AtomicInteger eventLoopCount = new AtomicInteger(eventState.length);
    final int maxConcurrent = 20 / eventState.length + 1;
    for (int i = 0; i < eventState.length; i++) {
        final int minSize = asyncConnectionPools[i].minSize;
        if (minSize > 0) {
            final EventLoop eventLoop = eventState[i].eventLoop;
            final Node node = this;
            eventLoop.execute(new Runnable() {

                public void run() {
                    try {
                        new AsyncConnectorExecutor(eventLoop, cluster, node, minSize, maxConcurrent, monitor, eventLoopCount);
                    } catch (Exception e) {
                        if (Log.warnEnabled()) {
                            Log.warn("AsyncConnectorExecutor failed: " + Util.getErrorMessage(e));
                        }
                    }
                }
            });
        } else {
            AsyncConnectorExecutor.eventLoopComplete(monitor, eventLoopCount);
        }
    }
    // Wait until all async connections are created.
    monitor.waitTillComplete();
}
Also used : EventState(com.aerospike.client.async.EventState) Monitor(com.aerospike.client.async.Monitor) EventLoop(com.aerospike.client.async.EventLoop) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncConnectorExecutor(com.aerospike.client.async.AsyncConnectorExecutor) IOException(java.io.IOException) AerospikeException(com.aerospike.client.AerospikeException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 2 with AsyncConnectorExecutor

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

the class Node method balanceAsyncConnections.

public final void balanceAsyncConnections(EventLoop eventLoop) {
    AsyncPool pool = asyncConnectionPools[eventLoop.getIndex()];
    pool.handleRemove();
    int excess = pool.excess();
    if (excess > 0) {
        closeIdleAsyncConnections(pool, excess);
    } else if (excess < 0 && errorCountWithinLimit()) {
        // Create connection requests sequentially because they will be done in the
        // background and there is no immediate need for them to complete.
        new AsyncConnectorExecutor(eventLoop, cluster, this, -excess, 1, null, null);
    }
}
Also used : AsyncConnectorExecutor(com.aerospike.client.async.AsyncConnectorExecutor)

Aggregations

AsyncConnectorExecutor (com.aerospike.client.async.AsyncConnectorExecutor)2 AerospikeException (com.aerospike.client.AerospikeException)1 EventLoop (com.aerospike.client.async.EventLoop)1 EventState (com.aerospike.client.async.EventState)1 Monitor (com.aerospike.client.async.Monitor)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1