@Override public void releaseClient(CassandraConnectionHandle conn) throws SQLException { boolean open; try { open = !conn.isClosed(); } catch (SQLException e) { // Tight to Cassandra Driver implementation. It should not happen. open = false; } if (open) { if (active.get()) { addClientToPoolGently(conn); } else { log.info("Open client released to in-active pool for host {}. Closing.", cassandraHost); closeConnection(conn); } } else { try { addClientToPoolGently(createConnection()); } catch (SQLException e) { log.info("Unable to reopen a connection. Bad server. Message: " + e.getMessage()); } } realActiveConnectionCount.decrementAndGet(); activeConnectionCount.decrementAndGet(); if (log.isDebugEnabled()) { log.debug("Status of releaseClient {} to queue: {}", cassandraHost.getHost(), open); } }
public ConcurrentHClientPool(CassandraHost host) throws SQLException { this.cassandraHost = host; ds = new CassandraDataSource( cassandraHost.getHost(), cassandraHost.getPort(), cassandraHost.getKeyspaceName(), cassandraHost.getUser(), cassandraHost.getPassword()); availableConnectionQueue = new ArrayBlockingQueue<CassandraConnectionHandle>(cassandraHost.getMaxActive(), true); // This counter can be offset by as much as the number of threads. activeConnectionCount = new AtomicInteger(0); realActiveConnectionCount = 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++) { availableConnectionQueue.add(createConnection()); } if (log.isDebugEnabled()) { log.debug( "Concurrent Host pool started with {} active clients; max: {} exhausted wait: {}", new Object[] {getNumIdle(), cassandraHost.getMaxActive(), maxWaitTimeWhenExhausted}); } }
private void closeConnection(CassandraConnectionHandle conn) { try { conn.getInternalConnection().close(); } catch (SQLException e) { log.error("Error closgin connection for: " + cassandraHost.getHost()); } }