/** * Constructor with a ZooKeeper connection string. * * @param zookeeperAddress * e.g. host1:port1,host2:port2,host3:port3... * @throws IOException * when connection failure occurs. */ public Domino(String zookeeperAddress) throws IOException { init(ConfigurationHelper.config(zookeeperAddress)); }
public static Configuration config(String zookeeperAddress){ String[] hosts = zookeeperAddress.split(","); String quarom = ""; int port = 2181;//default for(String h: hosts){ String host = h.trim(); if(host.isEmpty()) continue; if(!quarom.isEmpty()) quarom += ","; int i = host.indexOf(':'); if(i>0){ if(quarom.isEmpty()){//first port port = Integer.parseInt(host.substring(i+1)); } quarom += host.substring(0, i); }else{ quarom += host; } } if(quarom.isEmpty()){ throw new RuntimeException("Invalid argument!"); } return config(quarom, port); }