private void pathInBackground()

in curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java [1058:1145]


    private void pathInBackground(final String path, final byte[] data, final String givenPath) {
        final AtomicBoolean firstTime = new AtomicBoolean(true);
        OperationAndData<PathAndBytes> operationAndData =
                new OperationAndData<PathAndBytes>(
                        this,
                        new PathAndBytes(path, data),
                        backgrounding.getCallback(),
                        new OperationAndData.ErrorCallback<PathAndBytes>() {
                            public void retriesExhausted(OperationAndData<PathAndBytes> operationAndData) {
                                if (protectedMode.doProtected()) {
                                    // all retries have failed, findProtectedNodeInForeground(..) included, schedule a
                                    // clean up
                                    new FindAndDeleteProtectedNodeInBackground(
                                                    client,
                                                    ZKPaths.getPathAndNode(path).getPath(),
                                                    protectedMode.protectedId())
                                            .execute();
                                    // assign a new id if this builder is used again later
                                    protectedMode.resetProtectedId();
                                }
                            }
                        },
                        backgrounding.getContext(),
                        null) {
                    @Override
                    void callPerformBackgroundOperation() throws Exception {
                        boolean callSuper = true;
                        boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode;

                        protectedMode.checkSetSessionId(client, createMode);
                        if (!localFirstTime && protectedMode.doProtected()) {
                            debugForceFindProtectedNode = false;
                            String createdPath = null;
                            try {
                                createdPath = findProtectedNodeInForeground(path);
                            } catch (KeeperException.ConnectionLossException e) {
                                sendBackgroundResponse(
                                        KeeperException.Code.CONNECTIONLOSS.intValue(),
                                        path,
                                        backgrounding.getContext(),
                                        null,
                                        null,
                                        this);
                                callSuper = false;
                            }
                            if (createdPath != null) {
                                try {
                                    sendBackgroundResponse(
                                            KeeperException.Code.OK.intValue(),
                                            createdPath,
                                            backgrounding.getContext(),
                                            createdPath,
                                            null,
                                            this);
                                } catch (Exception e) {
                                    ThreadUtils.checkInterrupted(e);
                                    client.logError("Processing protected create for path: " + givenPath, e);
                                }
                                callSuper = false;
                            }
                        }

                        if (failBeforeNextCreateForTesting) {
                            failBeforeNextCreateForTesting = false;
                            throw new KeeperException.ConnectionLossException();
                        }

                        if (failNextCreateForTesting) {
                            failNextCreateForTesting = false;
                            try {
                                // simulate success on server without notification to client
                                // if another error occurs in pathInForeground that isn't NodeExists, this hangs instead
                                // of fully propagating the error. Likely not worth fixing though.
                                pathInForeground(path, data, acling.getAclList(path));
                            } catch (KeeperException.NodeExistsException e) {
                                client.logError(
                                        "NodeExists while injecting failure after create, ignoring: " + givenPath, e);
                            }
                            throw new KeeperException.ConnectionLossException();
                        }

                        if (callSuper) {
                            super.callPerformBackgroundOperation();
                        }
                    }
                };
        client.processBackgroundOperation(operationAndData, null);
    }