String[] hostList = hosts.split(",");
ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
for (String host : hostList) {
int colon = host.indexOf(':');
if (colon >= 0) {
addrs.add(new ServerAddress(host.substring(0, colon), Integer.parseInt(host.substring(colon + 1))));
} else {
addrs.add(new ServerAddress(host));
}
}
if (repl != null || addrs.size() > 1) {
addChild(new ReplSetNode(repl, addrs, mongo.getMongoClientOptions(), shardName));
} else {
addChild(new ServerNode(addrs.get(0), mongo.getMongoClientOptions(), false, false));
}
} catch (Exception e) {
getLogger().log(Level.WARNING, null, e);
}
}
// add config servers
try {
res = mongo.getDB("admin").command("getCmdLineOpts");
String configStr = (String) ((BasicDBObject) res.get("parsed")).get("configdb");
String[] configsvrs = configStr.split(",");
for (String host : configsvrs) {
int colon = host.indexOf(':');
ServerAddress addr;
if (colon >= 0) {
addr = new ServerAddress(host.substring(0, colon), Integer.parseInt(host.substring(colon + 1)));
} else {
addr = new ServerAddress(host);
}
addChild(new ServerNode(addr, mongo.getMongoClientOptions(), false, true));
}
} catch (Exception e) {
getLogger().log(Level.WARNING, null, e);