Esempio n. 1
0
 public Future<RedisConnection> getConnection(InetSocketAddress addr) {
   ClientConnectionsEntry entry = addr2Entry.get(addr);
   if (entry != null) {
     return entries.get(entry);
   }
   RedisConnectionException exception =
       new RedisConnectionException("Can't find entry for " + addr);
   return connectionManager.newFailedFuture(exception);
 }
  public Future<T> get(ClientConnectionsEntry entry) {
    if (((entry.getNodeType() == NodeType.MASTER && entry.getFreezeReason() == FreezeReason.SYSTEM)
            || !entry.isFreezed())
        && tryAcquireConnection(entry)) {
      return connectTo(entry);
    }

    RedisConnectionException exception =
        new RedisConnectionException("Can't aquire connection to " + entry.getClient().getAddr());
    return connectionManager.newFailedFuture(exception);
  }
  private Future<T> promiseFailure(ClientConnectionsEntry entry, T conn) {
    int attempts = entry.incFailedAttempts();
    if (attempts == config.getFailedAttempts()) {
      checkForReconnect(entry);
    } else if (attempts < config.getFailedAttempts()) {
      releaseConnection(entry, conn);
    }

    releaseConnection(entry);

    RedisConnectionException cause = new RedisConnectionException(conn + " is not active!");
    return connectionManager.newFailedFuture(cause);
  }
  public Future<T> get() {
    for (int j = entries.size() - 1; j >= 0; j--) {
      ClientConnectionsEntry entry = getEntry();
      if (!entry.isFreezed() && tryAcquireConnection(entry)) {
        return connectTo(entry);
      }
    }

    List<InetSocketAddress> zeroConnectionsAmount = new LinkedList<InetSocketAddress>();
    List<InetSocketAddress> freezed = new LinkedList<InetSocketAddress>();
    for (ClientConnectionsEntry entry : entries) {
      if (entry.isFreezed()) {
        freezed.add(entry.getClient().getAddr());
      } else {
        zeroConnectionsAmount.add(entry.getClient().getAddr());
      }
    }

    StringBuilder errorMsg;
    if (connectionManager.isClusterMode()) {
      errorMsg =
          new StringBuilder(
              "Connection pool exhausted! for slots: " + masterSlaveEntry.getSlotRanges());
    } else {
      errorMsg = new StringBuilder("Connection pool exhausted! ");
    }
    if (!freezed.isEmpty()) {
      errorMsg.append(" Disconnected hosts: " + freezed);
    }
    if (!zeroConnectionsAmount.isEmpty()) {
      errorMsg.append(" Hosts with fully busy connections: " + zeroConnectionsAmount);
    }

    RedisConnectionException exception = new RedisConnectionException(errorMsg.toString());
    return connectionManager.newFailedFuture(exception);
  }