xmlLoad(Resource.getXmlDir(), Resource.File.routerNode, null);
}
@Override
protected void populateChildren() {
CommandResult res = mongo.getDB("admin").command("listShards");
shards = (BasicDBList) res.get("shards");
if (shards == null) {
return;
}
for (Object obj : shards) {
try {
DBObject shard = (DBObject) obj;
String shardName = (String) shard.get("_id");
String hosts = (String) shard.get("host");
String repl = null;
int slash = hosts.indexOf('/');
if (slash >= 0) {
repl = hosts.substring(0, slash);
hosts = hosts.substring(slash + 1);
}
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) {