@Override public HClientPool getPool(Collection<HClientPool> pools, Set<CassandraHost> excludeHosts) { List<HClientPool> vals = Lists.newArrayList(pools); // shuffle pools to avoid always returning the same one when we are not terribly busy Collections.shuffle(vals); Collections.sort(vals, new ShufflingCompare()); Iterator<HClientPool> iterator = vals.iterator(); HClientPool concurrentHClientPool = iterator.next(); if (excludeHosts != null && excludeHosts.size() > 0) { while (iterator.hasNext()) { if (!excludeHosts.contains(concurrentHClientPool.getCassandraHost())) { break; } concurrentHClientPool = (ConcurrentHClientPool) iterator.next(); } } return concurrentHClientPool; }
public int compare(HClientPool o1, HClientPool o2) { if (log.isDebugEnabled()) { log.debug( "comparing 1: {} and count {} with 2: {} and count {}", new Object[] { o1.getCassandraHost(), o1.getNumActive(), o2.getCassandraHost(), o2.getNumActive() }); } return o1.getNumActive() - o2.getNumActive(); }