@Override public int getMaxActive() { return cassandraHost.getMaxActive(); }
@Override public int getNumBeforeExhausted() { return cassandraHost.getMaxActive() - realActiveClientsCount.get(); }
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}); } }
@Override public void releaseClient(HClient client) throws HectorException { if ( cassandraHost.getMaxActive() == 0 ) { client.close();
if (currentActiveClients <= cassandraHost.getMaxActive()) { cassandraClient = createClient(); } else {
@Override public int getMaxActive() { return cassandraHost.getMaxActive(); }
@Override public int getMaxActive() { return cassandraHost.getMaxActive(); }
@Override public int getNumBeforeExhausted() { return cassandraHost.getMaxActive() - realActiveClientsCount.get(); }
@Override public int getNumBeforeExhausted() { return cassandraHost.getMaxActive() - realActiveClientsCount.get(); }
@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()); }
@Test public void testApplyConfig() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); cassandraHostConfigurator.setMaxActive(15); cassandraHostConfigurator.setMaxConnectTimeMillis(30000); cassandraHostConfigurator.setMaxLastSuccessTimeMillis(40000); CassandraHost extraHost = new CassandraHost("localhost:9171"); cassandraHostConfigurator.applyConfig(extraHost); assertEquals(15, extraHost.getMaxActive()); assertEquals(30000, extraHost.getMaxConnectTimeMillis()); assertEquals(40000, extraHost.getMaxLastSuccessTimeMillis()); }
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}); } }
@Override public HClient borrowClient() throws HectorException { if ( !active.get() ) { throw new HInactivePoolException("Attempt to borrow on in-active pool: " + getName()); } HClient cassandraClient = availableClientQueue.poll(); int currentActiveClients = activeClientsCount.incrementAndGet(); try { if ( cassandraClient == null ) { if (currentActiveClients <= cassandraHost.getMaxActive()) { cassandraClient = createClient(); } else { // We can't grow so let's wait for a connection to become available. cassandraClient = waitForConnection(); } } if ( cassandraClient == null ) { throw new HectorException("HConnectionManager returned a null client after aquisition - are we shutting down?"); } } catch (RuntimeException e) { activeClientsCount.decrementAndGet(); throw e; } realActiveClientsCount.incrementAndGet(); return cassandraClient; }
@Override public void releaseClient(HClient client) throws HectorException { if ( cassandraHost.getMaxActive() == 0 ) { client.close();
if (currentActiveClients <= cassandraHost.getMaxActive()) { cassandraClient = createClient(); } else {