示例#1
0
 @Override
 public Set<String> getSuspendedCassandraHosts() {
   Set<CassandraHost> hosts = connectionManager.getSuspendedCassandraHosts();
   Set<String> hostsStr = new HashSet<String>();
   for (CassandraHost host : hosts) {
     hostsStr.add(host.getName());
   }
   return hostsStr;
 }
 /**
  * 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;
   }
 }
  private CassandraConnectionHandle waitForConnection() {
    CassandraConnectionHandle conn = null;
    numBlocked.incrementAndGet();

    // blocked take on the queue if we are configured to wait forever
    if (log.isDebugEnabled()) {
      log.debug("blocking on queue - current block count {}", numBlocked.get());
    }

    try {
      // wait and catch, creating a new one if the counts have changed. Infinite wait should just
      // recurse.
      if (maxWaitTimeWhenExhausted == 0) {

        while (conn == null && active.get()) {
          try {
            conn = availableConnectionQueue.poll(100, TimeUnit.MILLISECONDS);
          } catch (InterruptedException ie) {
            log.error("InterruptedException poll operation on retry forever", ie);
            break;
          }
        }

      } else {

        try {
          conn = availableConnectionQueue.poll(maxWaitTimeWhenExhausted, TimeUnit.MILLISECONDS);
          if (conn == null) {
            throw new HPoolExhaustedException(
                String.format(
                    "maxWaitTimeWhenExhausted exceeded for thread %s on host %s",
                    new Object[] {Thread.currentThread().getName(), cassandraHost.getName()}));
          }
        } catch (InterruptedException ie) {
          // monitor.incCounter(Counter.POOL_EXHAUSTED);
          log.error("Cassandra client acquisition interrupted", ie);
        }
      }
    } finally {
      numBlocked.decrementAndGet();
    }

    return conn;
  }
 @Override
 public String getName() {
   return String.format("<ConcurrentCassandraClientPoolByHost>:{%s}", cassandraHost.getName());
 }