public ConcurrentHClientPool(HClientFactory clientFactory, CassandraHost host, CassandraClientMonitor monitor) { this.clientFactory = clientFactory; this.cassandraHost = host; this.monitor = monitor; availableClientQueue = new ArrayBlockingQueue<HClient>(cassandraHost.getMaxActive(), true); // This counter can be offset by as much as the number of threads. activeClientsCount = new AtomicInteger(0); realActiveClientsCount = new AtomicInteger(0); exhaustedStartTime = new AtomicLong(-1); numBlocked = new AtomicInteger(); active = new AtomicBoolean(true); maxWaitTimeWhenExhausted = cassandraHost.getMaxWaitTimeWhenExhausted() < 0 ? 0 : cassandraHost.getMaxWaitTimeWhenExhausted(); for (int i = 0; i < cassandraHost.getMaxActive() / 3; i++) { availableClientQueue.add(createClient()); } if ( log.isDebugEnabled() ) { log.debug("Concurrent Host pool started with {} active clients; max: {} exhausted wait: {}", new Object[]{getNumIdle(), cassandraHost.getMaxActive(), maxWaitTimeWhenExhausted}); } }
public ConcurrentHClientPool(HClientFactory clientFactory, CassandraHost host) { this.clientFactory = clientFactory; this.cassandraHost = host; availableClientQueue = new ArrayBlockingQueue<HClient>(cassandraHost.getMaxActive(), true); // This counter can be offset by as much as the number of threads. activeClientsCount = new AtomicInteger(0); realActiveClientsCount = new AtomicInteger(0); numBlocked = new AtomicInteger(); active = new AtomicBoolean(true); maxWaitTimeWhenExhausted = cassandraHost.getMaxWaitTimeWhenExhausted() < 0 ? 0 : cassandraHost.getMaxWaitTimeWhenExhausted(); for (int i = 0; i < cassandraHost.getMaxActive() / 3; i++) { availableClientQueue.add(createClient()); } if ( log.isDebugEnabled() ) { log.debug("Concurrent Host pool started with {} active clients; max: {} exhausted wait: {}", new Object[]{getNumIdle(), cassandraHost.getMaxActive(), maxWaitTimeWhenExhausted}); } }
public ConcurrentHClientPool(HClientFactory clientFactory, CassandraHost host, CassandraClientMonitor monitor) { this.clientFactory = clientFactory; this.cassandraHost = host; this.monitor = monitor; availableClientQueue = new ArrayBlockingQueue<HClient>(cassandraHost.getMaxActive(), true); // This counter can be offset by as much as the number of threads. activeClientsCount = new AtomicInteger(0); realActiveClientsCount = new AtomicInteger(0); exhaustedStartTime = new AtomicLong(-1); numBlocked = new AtomicInteger(); active = new AtomicBoolean(true); maxWaitTimeWhenExhausted = cassandraHost.getMaxWaitTimeWhenExhausted() < 0 ? 0 : cassandraHost.getMaxWaitTimeWhenExhausted(); for (int i = 0; i < cassandraHost.getMaxActive() / 3; i++) { availableClientQueue.add(createClient()); } if ( log.isDebugEnabled() ) { log.debug("Concurrent Host pool started with {} active clients; max: {} exhausted wait: {}", new Object[]{getNumIdle(), cassandraHost.getMaxActive(), maxWaitTimeWhenExhausted}); } }
@Test public void testConfigValuesPropogated() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170,localhost:9171,localhost:9172"); cassandraHostConfigurator.setMaxActive(20); cassandraHostConfigurator.setCassandraThriftSocketTimeout(3000); cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(4000); cassandraHostConfigurator.setMaxExhaustedTimeBeforeMarkingAsDown(5000); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); // no need to test all, just a smattering assertEquals(20, cassandraHosts[1].getMaxActive()); assertEquals(20, cassandraHosts[0].getMaxActive()); assertEquals(4000, cassandraHosts[1].getMaxWaitTimeWhenExhausted()); assertEquals(5000, cassandraHosts[0].getMaxExhaustedTimeBeforeMarkingAsDown()); assertEquals(3000, cassandraHosts[2].getCassandraThriftSocketTimeout()); assertEquals(3000, cassandraHosts[0].getCassandraThriftSocketTimeout()); }