Example usage for org.apache.zookeeper.client ConnectStringParser ConnectStringParser

List of usage examples for org.apache.zookeeper.client ConnectStringParser ConnectStringParser

Introduction

In this page you can find the example usage for org.apache.zookeeper.client ConnectStringParser ConnectStringParser.

Prototype

public ConnectStringParser(String connectString) 

Source Link

Document

Parse host and port by spliting client connectString with support for IPv6 literals

Usage

From source file:com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx.java

License:Apache License

public void configMutliCluster(ZooKeeper zk) {
    if (_servers.size() == 1) {
        return;/* w  ww  .j  a  v a2s.c  om*/
    }
    String cluster1 = _servers.get(0);
    try {
        if (_servers.size() > 1) {
            // accessible
            ReflectionUtils.makeAccessible(clientCnxnField);
            ReflectionUtils.makeAccessible(hostProviderField);
            ReflectionUtils.makeAccessible(serverAddressesField);

            // 
            for (int i = 1; i < _servers.size(); i++) {
                String cluster = _servers.get(i);
                // ?zk??
                ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
                HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
                List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils
                        .getField(serverAddressesField, hostProvider);
                // 
                serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
            }
        }
    } catch (Exception e) {
        try {
            if (zk != null) {
                zk.close();
            }
        } catch (InterruptedException ie) {
            // ignore interrupt
        }
        throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
    }

}

From source file:org.apache.samza.zk.ZkCoordinationServiceFactory.java

License:Apache License

/**
 * if ZkConnectString contains namespace path at the end, but it does not exist we should fail
 * @param zkConnect - connect string/* w  w  w  . java2 s  .  c o  m*/
 * @param zkClient - zkClient object to talk to the ZK
 */
public static void validateZkNameSpace(String zkConnect, ZkClient zkClient) {
    ConnectStringParser parser = new ConnectStringParser(zkConnect);

    String path = parser.getChrootPath();
    if (Strings.isNullOrEmpty(path)) {
        return; // no namespace path
    }

    LOG.info("connectString = " + zkConnect + "; path =" + path);

    // if namespace specified (path above) but "/" does not exists, we will fail
    if (!zkClient.exists("/")) {
        throw new SamzaException("Zookeeper namespace: " + path + " does not exist for zk at " + zkConnect);
    }
}