in modules/core/src/main/java/org/apache/fluo/core/util/CuratorUtil.java [118:155]
public static boolean putData(CuratorFramework curator, String zPath, byte[] data,
NodeExistsPolicy policy) throws KeeperException, InterruptedException {
if (policy == null) {
policy = NodeExistsPolicy.FAIL;
}
while (true) {
try {
curator.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(zPath,
data);
return true;
} catch (Exception nee) {
if (nee instanceof KeeperException.NodeExistsException) {
switch (policy) {
case SKIP:
return false;
case OVERWRITE:
try {
curator.setData().withVersion(-1).forPath(zPath, data);
return true;
} catch (Exception nne) {
if (nne instanceof KeeperException.NoNodeException) {
// node delete between create call and set data, so try create call again
continue;
} else {
throw new RuntimeException(nne);
}
}
default:
throw (KeeperException.NodeExistsException) nee;
}
} else {
throw new RuntimeException(nee);
}
}
}
}