コード例 #1
0
  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});
    }
  }
コード例 #2
0
 /**
  * Used when we still have room to grow. Return an Connection without having to wait on polling
  * logic. (But still increment all the counters)
  *
  * @return
  * @throws SQLException
  */
 private CassandraConnectionHandle createConnection() throws SQLException {
   if (log.isDebugEnabled()) {
     log.debug("Creation of new connection");
   }
   try {
     return new CassandraConnectionHandle(
         ds.getConnection(cassandraHost.getUser(), cassandraHost.getPassword()), cassandraHost);
   } catch (SQLException e) {
     log.debug("Unable to open transport to " + cassandraHost.getName());
     throw e;
   }
 }