public NetworkClient(Settings settings) {
   this(
       settings,
       (!SettingsUtils.hasJobTransportPoolingKey(settings)
           ? new CommonsHttpTransportFactory()
           : PooledTransportManager.getTransportFactory(settings)));
 }
  private boolean selectNextNode() {
    if (nextClient >= nodes.size()) {
      return false;
    }

    if (currentTransport != null) {
      stats.nodeRetries++;
    }

    closeTransport();
    currentNode = nodes.get(nextClient++);
    SettingsUtils.pinNode(settings, currentNode);
    currentTransport = transportFactory.create(settings, currentNode);
    return true;
  }
  public NetworkClient(Settings settings, TransportFactory transportFactory) {
    this.settings = settings.copy();
    this.nodes = SettingsUtils.discoveredOrDeclaredNodes(settings);
    this.transportFactory = transportFactory;

    // shuffle the list of nodes so in case of failures, the fallback is spread
    Collections.shuffle(nodes);

    if (SettingsUtils.hasPinnedNode(settings)) {
      // move pinned node in front to be selected (only once)
      String pinnedNode = SettingsUtils.getPinnedNode(settings);

      if (log.isDebugEnabled()) {
        log.debug("Opening (pinned) network client to " + pinnedNode);
      }

      nodes.remove(pinnedNode);
      nodes.add(0, pinnedNode);
    }

    selectNextNode();

    Assert.notNull(currentTransport, "no node information provided");
  }
  public RestClient(Settings settings) {
    network = new NetworkClient(settings, SettingsUtils.nodes(settings));

    scrollKeepAlive = TimeValue.timeValueMillis(settings.getScrollKeepAlive());
    indexReadMissingAsEmpty = settings.getIndexReadMissingAsEmpty();

    String retryPolicyName = settings.getBatchWriteRetryPolicy();

    if (ConfigurationOptions.ES_BATCH_WRITE_RETRY_POLICY_SIMPLE.equals(retryPolicyName)) {
      retryPolicyName = SimpleHttpRetryPolicy.class.getName();
    } else if (ConfigurationOptions.ES_BATCH_WRITE_RETRY_POLICY_NONE.equals(retryPolicyName)) {
      retryPolicyName = NoHttpRetryPolicy.class.getName();
    }

    retryPolicy = ObjectUtils.instantiate(retryPolicyName, settings);
  }
    @Test
    public void exhaustConnections() throws InterruptedException {
      List<Thread> threads = new ArrayList<>();
      int workerNum = 0;
      for (String jobKey : JOB_KEYS) {
        final Settings workerSettings = SETTINGS.copy();
        if (POOLED) {
          SettingsUtils.setJobTransportPoolingKey(workerSettings, jobKey);
        }
        Thread worker = new Thread(new Exhauster(++workerNum, workerSettings));
        worker.start();
        threads.add(worker);
      }

      for (Thread thread : threads) {
        thread.join();
      }
    }
  static FieldAlias alias(Settings settings) {
    Map<String, String> aliasMap =
        SettingsUtils.aliases(settings.getProperty(HiveConstants.MAPPING_NAMES));

    // add default aliases for serialization (_colX -> mapping name)
    Map<String, String> columnMap = columnMap(settings);

    for (Entry<String, String> entry : columnMap.entrySet()) {
      String columnName = entry.getKey();
      String columnIndex = entry.getValue();

      if (!aliasMap.isEmpty()) {
        String alias = aliasMap.get(columnName);
        if (alias != null) {
          columnName = alias;
        }
      }

      aliasMap.put(columnIndex, columnName);
    }

    return new FieldAlias(aliasMap);
  }
 static FieldAlias alias(Settings settings) {
   return new FieldAlias(SettingsUtils.aliases(settings.getProperty(MAPPING_NAMES), false), false);
 }