in curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java [397:445]
private void createNode() {
if (!isActive()) {
return;
}
if (debugCreateNodeLatch != null) {
try {
debugCreateNodeLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
try {
String existingPath = nodePath.get(), createPath;
if (existingPath != null && !useProtection) {
createPath = existingPath;
} else if (existingPath != null && mode.isSequential()) {
createPath = basePath + ZKPaths.extractSequentialSuffix(existingPath);
} else {
createPath = basePath;
}
CreateModable<ACLBackgroundPathAndBytesable<String>> localCreateMethod = createMethod.get();
if (localCreateMethod == null) {
CreateBuilderMain createBuilder = mode.isTTL() ? client.create().withTtl(ttl) : client.create();
CreateModable<ACLBackgroundPathAndBytesable<String>> tempCreateMethod;
if (useParentCreation) {
tempCreateMethod = useProtection
? createBuilder.creatingParentContainersIfNeeded().withProtection()
: createBuilder.creatingParentContainersIfNeeded();
} else {
tempCreateMethod = useProtection ? createBuilder.withProtection() : createBuilder;
}
createMethod.compareAndSet(null, tempCreateMethod);
localCreateMethod = createMethod.get();
}
localCreateMethod
.withMode(getCreateMode(existingPath != null))
.inBackground(backgroundCallback)
.forPath(createPath, data.get());
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
throw new RuntimeException(
"Creating node. BasePath: " + basePath,
e); // should never happen unless there's a programming error - so throw RuntimeException
}
}