public RedisPubSubConnection nextPubSubConnection() { clientsEmpty.awaitUninterruptibly(); List<SubscribesConnectionEntry> clientsCopy = new ArrayList<SubscribesConnectionEntry>(clients.values()); while (true) { if (clientsCopy.isEmpty()) { throw new RedisConnectionException("Slave subscribe-connection pool gets exhausted!"); } int index = getIndex(clientsCopy); SubscribesConnectionEntry entry = clientsCopy.get(index); if (entry.isFreezed() || !entry.getSubscribeConnectionsSemaphore().tryAcquire()) { clientsCopy.remove(index); } else { try { RedisPubSubConnection conn = entry.pollFreeSubscribeConnection(); if (conn != null) { return conn; } return entry.connectPubSub(config); } catch (RedisConnectionException e) { entry.getSubscribeConnectionsSemaphore().release(); // TODO connection scoring log.warn("Can't connect to {}, trying next connection!", entry.getClient().getAddr()); clientsCopy.remove(index); } } } }
public RedisConnection nextConnection() { clientsEmpty.awaitUninterruptibly(); List<SubscribesConnectionEntry> clientsCopy = new ArrayList<SubscribesConnectionEntry>(clients.values()); while (true) { if (clientsCopy.isEmpty()) { throw new RedisConnectionException("Slave connection pool gets exhausted!"); } int index = getIndex(clientsCopy); SubscribesConnectionEntry entry = clientsCopy.get(index); RedisConnection conn = retrieveConnection(entry); if (conn == null) { clientsCopy.remove(index); } else { return conn; } } }