public Config getVBucketConfig() {
   Bucket config = configurationProvider.getBucketConfiguration(bucket);
   if (config == null) {
     throw new ConfigurationException(
         "Could not fetch valid configuration " + "from provided nodes. Stopping.");
   } else if (config.isNotUpdating()) {
     LOGGER.warning(
         "Noticed bucket configuration to be disconnected, " + "will attempt to reconnect");
     setConfigurationProvider(new ConfigurationProviderHTTP(storedBaseList, bucket, pass));
   }
   return configurationProvider.getBucketConfiguration(bucket).getConfig();
 }
  /**
   * Reconfigures the connected ViewNodes.
   *
   * <p>When a reconfiguration event happens, new ViewNodes may need to be added or old ones need to
   * be removed from the current configuration. This method takes care that those operations are
   * performed in the correct order and are executed in a thread-safe manner.
   *
   * @param bucket the bucket which has been rebalanced.
   */
  public void reconfigure(Bucket bucket) {
    reconfiguring = true;

    try {
      // get a new collection of addresses from the received config
      HashSet<SocketAddress> newServerAddresses = new HashSet<SocketAddress>();
      List<InetSocketAddress> newServers =
          AddrUtil.getAddressesFromURL(bucket.getConfig().getCouchServers());
      for (InetSocketAddress server : newServers) {
        // add parsed address to our collections
        newServerAddresses.add(server);
      }

      // split current nodes to "odd nodes" and "stay nodes"
      ArrayList<ViewNode> shutdownNodes = new ArrayList<ViewNode>();
      ArrayList<ViewNode> stayNodes = new ArrayList<ViewNode>();
      ArrayList<InetSocketAddress> stayServers = new ArrayList<InetSocketAddress>();

      wlock.lock();
      try {
        for (ViewNode current : couchNodes) {
          if (newServerAddresses.contains(current.getSocketAddress())) {
            stayNodes.add(current);
            stayServers.add((InetSocketAddress) current.getSocketAddress());
          } else {
            shutdownNodes.add(current);
          }
        }

        // prepare a collection of addresses for new nodes
        newServers.removeAll(stayServers);

        // create a collection of new nodes
        List<ViewNode> newNodes = createConnections(newServers);

        // merge stay nodes with new nodes
        List<ViewNode> mergedNodes = new ArrayList<ViewNode>();
        mergedNodes.addAll(stayNodes);
        mergedNodes.addAll(newNodes);

        couchNodes = mergedNodes;
      } finally {
        wlock.unlock();
      }

      // shutdown for the oddNodes
      for (ViewNode qa : shutdownNodes) {
        try {
          qa.shutdown();
        } catch (IOException e) {
          getLogger().error("Error shutting down connection to " + qa.getSocketAddress());
        }
      }

    } catch (IOException e) {
      getLogger().error("Connection reconfiguration failed", e);
    } finally {
      reconfiguring = false;
    }
  }
 /**
  * This method is called when there is a topology change in the cluster.
  *
  * <p>This method is intended for internal use only.
  */
 public void reconfigure(Bucket bucket) {
   reconfiguring = true;
   if (bucket.isNotUpdating()) {
     getLogger()
         .info(
             "Bucket configuration is disconnected from cluster "
                 + "configuration updates, attempting to reconnect.");
     CouchbaseConnectionFactory cbcf = (CouchbaseConnectionFactory) connFactory;
     cbcf.requestConfigReconnect(cbcf.getBucketName(), this);
   }
   try {
     vconn.reconfigure(bucket);
     if (mconn instanceof CouchbaseConnection) {
       CouchbaseConnection cbConn = (CouchbaseConnection) mconn;
       cbConn.reconfigure(bucket);
     } else {
       CouchbaseMemcachedConnection cbMConn = (CouchbaseMemcachedConnection) mconn;
       cbMConn.reconfigure(bucket);
     }
   } catch (IllegalArgumentException ex) {
     getLogger()
         .warn("Failed to reconfigure client, staying with " + "previous configuration.", ex);
   } finally {
     reconfiguring = false;
   }
 }