Search in sources :

Example 1 with FailoverRequestBalancingStrategy

use of org.infinispan.client.hotrod.FailoverRequestBalancingStrategy in project infinispan by infinispan.

the class ChannelFactory method fetchChannelAndInvoke.

public <T extends ChannelOperation> T fetchChannelAndInvoke(Set<SocketAddress> failedServers, byte[] cacheName, T operation) {
    SocketAddress server;
    // Need the write lock because FailoverRequestBalancingStrategy is not thread-safe
    lock.writeLock().lock();
    try {
        if (failedServers != null) {
            CompletableFuture<Void> switchStage = this.clusterSwitchStage;
            if (switchStage != null) {
                switchStage.whenComplete((__, t) -> fetchChannelAndInvoke(failedServers, cacheName, operation));
                return operation;
            }
        }
        CacheInfo cacheInfo = topologyInfo.getCacheInfo(wrapBytes(cacheName));
        FailoverRequestBalancingStrategy balancer = cacheInfo.getBalancer();
        server = balancer.nextServer(failedServers);
    } finally {
        lock.writeLock().unlock();
    }
    return fetchChannelAndInvoke(server, operation);
}
Also used : SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) FailoverRequestBalancingStrategy(org.infinispan.client.hotrod.FailoverRequestBalancingStrategy) CacheInfo(org.infinispan.client.hotrod.impl.topology.CacheInfo)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 FailoverRequestBalancingStrategy (org.infinispan.client.hotrod.FailoverRequestBalancingStrategy)1 CacheInfo (org.infinispan.client.hotrod.impl.topology.CacheInfo)1