Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
0
 @Override
 public void process(WatchedEvent event) throws Exception {
   if (event.getType() == EventType.NodeDeleted) {
     createNode();
   } else if (event.getType() == EventType.NodeDataChanged) {
     watchNode();
   }
 }
Exemplo n.º 3
0
 @Override
 public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
   if (event.getResultCode() == KeeperException.Code.NONODE.intValue()) {
     createNode();
   } else {
     boolean isEphemeral = event.getStat().getEphemeralOwner() != 0;
     if (isEphemeral != mode.isEphemeral()) {
       log.warn(
           "Existing node ephemeral state doesn't match requested state. Maybe the node was created outside of PersistentNode? "
               + basePath);
     }
   }
 }
Exemplo n.º 4
0
  /**
   * You must call start() to initiate the persistent node. An attempt to create the node in the
   * background will be started
   */
  public void start() {
    Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Already started");

    client.getConnectionStateListenable().addListener(connectionStateListener);
    createNode();
  }
Exemplo n.º 5
0
 @Override
 public void stateChanged(CuratorFramework client, ConnectionState newState) {
   if (newState == ConnectionState.RECONNECTED) {
     createNode();
   }
 }