private void processBackgroundCallback(CuratorEvent event) throws Exception {
    String path = null;
    boolean nodeExists = false;
    if (event.getResultCode() == KeeperException.Code.NODEEXISTS.intValue()) {
      path = event.getPath();
      nodeExists = true;
    } else if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
      path = event.getName();
    } else if (event.getResultCode() == KeeperException.Code.NOAUTH.intValue()) {
      log.warn("Client does not have authorisation to write node at path {}", event.getPath());
      authFailure.set(true);
      return;
    }
    if (path != null) {
      authFailure.set(false);
      nodePath.set(path);
      watchNode();

      if (nodeExists) {
        client.setData().inBackground(setDataCallback).forPath(getActualPath(), getData());
      } else {
        initialisationComplete();
      }
    } else {
      createNode();
    }
  }
 @Override
 public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
   // If the result is ok then initialisation is complete (if we're still initialising)
   // Don't retry on other errors as the only recoverable cases will be connection loss
   // and the node not existing, both of which are already handled by other watches.
   if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
     // Update is ok, mark initialisation as complete if required.
     initialisationComplete();
   }
 }
  private void processBackgroundCallbackClosedState(CuratorEvent event) {
    String path = null;
    if (event.getResultCode() == KeeperException.Code.NODEEXISTS.intValue()) {
      path = event.getPath();
    } else if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
      path = event.getName();
    }

    if (path != null) {
      try {
        client.delete().guaranteed().inBackground().forPath(path);
      } catch (Exception e) {
        log.error("Could not delete node after close", e);
      }
    }
  }