if (!needSet[i])
continue;
String path = paths.get(i);
T record = records.get(i);
cbList[i] = new SetDataCallbackHandler();
_zkClient.asyncSetData(path, record, -1, cbList[i]);
}
boolean failOnNoNode = false;
for (int i = 0; i < cbList.length; i++) {
SetDataCallbackHandler cb = cbList[i];
cb.waitForSuccess();
Code rc = Code.get(cb.getRc());
switch (rc) {
case OK:
setStats.set(i, cb.getStat());
needSet[i] = false;
break;
case NONODE:
// if fail on NoNode, try create the node
failOnNoNode = true;
break;
default:
// if fail on error other than NoNode, give up
needSet[i] = false;
break;
}
}
// if failOnNoNode, try create
if (failOnNoNode) {
boolean[] needCreate = Arrays.copyOf(needSet, needSet.length);
createCbList = create(paths, records, needCreate, pathsCreated, options);
for (int i = 0; i < createCbList.length; i++) {
CreateCallbackHandler createCb = createCbList[i];
if (createCb == null) {
continue;
}
Code rc = Code.get(createCb.getRc());
switch (rc) {
case OK:
setStats.set(i, ZNode.ZERO_STAT);
needSet[i] = false;
break;
case NODEEXISTS:
retry = true;
break;
default:
// if creation fails on error other than NodeExists
// no need to retry set
needSet[i] = false;
break;
}
}
}
} while (retry);
// construct return results
for (int i = 0; i < cbList.length; i++) {
SetDataCallbackHandler cb = cbList[i];
Code rc = Code.get(cb.getRc());
if (rc == Code.OK) {
success[i] = true;
} else if (rc == Code.NONODE) {
CreateCallbackHandler createCb = createCbList[i];
if (Code.get(createCb.getRc()) == Code.OK) {