private void connectAndInitializeClient()

in src/main/java/com/uber/rss/clients/ReplicatedReadClient.java [291:332]


  private void connectAndInitializeClient() {
    List<ExceptionLogInfo> exceptions = null;
    boolean succeeded = false;
    for (; currentClientIndex < clients.length; currentClientIndex++) {
      try {
        logger.info(String.format("Trying to connect to server: %s", clients[currentClientIndex]));
        clients[currentClientIndex].connect();
        clientsInitialized[currentClientIndex] = true;
        resetReadRecords();
        succeeded = true;
        break;
      } catch (Throwable ex) {
        M3Stats.addException(ex, this.getClass().getSimpleName());
        closeClient(currentClientIndex);
        if (exceptions == null) {
          exceptions = new ArrayList<>();
        }
        exceptions.add(new ExceptionLogInfo("Failed to initialize: " + clients[currentClientIndex].toString(), ex));

        if (currentClientIndex >= clients.length - 1) {
          // last client failed, throw out exception
          throw new RssAggregateException(exceptions.stream().map(t -> t.exception).collect(Collectors.toList()));
        }
      }
    }

    if (!succeeded) {
      // not succeeded, throw out exception
      if (exceptions == null || exceptions.isEmpty()) {
        throw new RssInvalidStateException("Invalid read client state: failed to initialized, but no exceptions");
      } else {
        throw new RssAggregateException(exceptions.stream().map(t->t.exception).collect(Collectors.toList()));
      }
    } else {
      // succeeded, log exceptions as warning
      if (exceptions != null) {
        exceptions.forEach(t -> {
          logger.warn(t.logMsg, t.exception);
        });
      }
    }
  }