示例#1
0
  private int reconnect(ConnectionPoolState<CL> prevState) throws DynoException {

    if (!(cpState.compareAndSet(prevState, cpReconnecting))) {
      Logger.info(
          "Reconnect connections already called by someone else, ignoring reconnect connections request");
      return 0;
    }

    int successfullyCreated = 0;

    for (int i = 0; i < cpConfig.getMaxConnsPerHost(); i++) {
      boolean success = createConnectionWithRetries();
      if (success) {
        successfullyCreated++;
      }
    }

    if (successfullyCreated == cpConfig.getMaxConnsPerHost()) {
      if (!(cpState.compareAndSet(cpReconnecting, cpActive))) {
        throw new IllegalStateException("something went wrong with prime connections");
      }
    } else {
      if (!(cpState.compareAndSet(cpReconnecting, cpDown))) {
        throw new IllegalStateException("something went wrong with prime connections");
      }
    }
    return successfullyCreated;
  }
示例#2
0
  @Override
  public int primeConnections() throws DynoException {

    Logger.info(
        "Priming connection pool for host:"
            + host
            + ", with conns:"
            + cpConfig.getMaxConnsPerHost());

    if (cpState.get() != cpNotInited) {
      throw new DynoException(
          "Connection pool has already been inited, cannot prime connections for host:" + host);
    }

    int primedConnectionCount = reconnect(cpNotInited);

    if (primedConnectionCount == 0) {
      Logger.warn("Unable to make any successful connections to host " + host);
      cpState.set(cpNotInited);
      throw new DynoConnectException("Unable to make ANY successful connections to host " + host);
    }

    return primedConnectionCount;
  }
示例#3
0
 @Override
 public int getSocketTimeout() {
   return cpConfig.getSocketTimeout();
 }
示例#4
0
 @Override
 public int getConnectionTimeout() {
   return cpConfig.getConnectTimeout();
 }