/**
   * Copy constructor.
   *
   * @param cfg Configuration to be copied.
   */
  public GridClientConfiguration(GridClientConfiguration cfg) {
    // Preserve alphabetical order for maintenance;
    autoFetchAttrs = cfg.isAutoFetchAttributes();
    autoFetchMetrics = cfg.isAutoFetchMetrics();
    balancer = cfg.getBalancer();
    connectTimeout = cfg.getConnectTimeout();
    credProvider = cfg.getSecurityCredentialsProvider();
    enableAttrsCache = cfg.isEnableAttributesCache();
    enableMetricsCache = cfg.isEnableMetricsCache();
    executor = cfg.getExecutorService();
    marshaller = cfg.getMarshaller();
    maxConnIdleTime = cfg.getMaxConnectionIdleTime();
    pingInterval = cfg.getPingInterval();
    pingTimeout = cfg.getPingTimeout();
    proto = cfg.getProtocol();
    routers = cfg.getRouters();
    srvs = cfg.getServers();
    sslCtxFactory = cfg.getSslContextFactory();
    tcpNoDelay = cfg.isTcpNoDelay();
    topRefreshFreq = cfg.getTopologyRefreshFrequency();
    daemon = cfg.isDaemon();
    marshaller = cfg.getMarshaller();

    setDataConfigurations(cfg.getDataConfigurations());
  }
  /** {@inheritDoc} */
  @SuppressWarnings("BusyWait")
  @Override
  public void init(Collection<InetSocketAddress> srvs)
      throws GridClientException, InterruptedException {
    init0();

    GridClientException firstEx = null;

    for (int i = 0; i < INIT_RETRY_CNT; i++) {
      Collection<InetSocketAddress> srvsCp = new ArrayList<>(srvs);

      while (!srvsCp.isEmpty()) {
        GridClientConnection conn = null;

        try {
          conn = connect(null, srvsCp);

          conn.topology(cfg.isAutoFetchAttributes(), cfg.isAutoFetchMetrics(), null).get();

          return;
        } catch (GridServerUnreachableException e) {
          // No connection could be opened to any of initial addresses - exit to retry loop.
          assert conn == null
              : "GridClientConnectionResetException was thrown from GridClientConnection#topology";

          if (firstEx == null) firstEx = e;

          break;
        } catch (GridClientConnectionResetException e) {
          // Connection was established but topology update failed -
          // trying other initial addresses if any.
          assert conn != null : "GridClientConnectionResetException was thrown from connect()";

          if (firstEx == null) firstEx = e;

          if (!srvsCp.remove(conn.serverAddress()))
            // We have misbehaving collection or equals - just exit to avoid infinite loop.
            break;
        }
      }

      Thread.sleep(INIT_RETRY_INTERVAL);
    }

    for (GridClientConnection c : conns.values()) {
      conns.remove(c.serverAddress(), c);

      c.close(FAILED, false);
    }

    throw firstEx;
  }