code: static boolean grabTicket(ZooKeeper zookeeper, String lockNode, String ticket)
              throws InterruptedException, KeeperException {
          try {
              zookeeper.create(lockNode + "/" + ticket, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
          } catch (KeeperException e) {
              if (e.code() == KeeperException.Code.NODEEXISTS) {
                  // It is possible that two processes try to grab the exact same ticket at the same time.
                  // This is common for the locking ticket.
                  logger.debug("Failed to claim ticket {}.", ticket);
                  return false;
              } else {
                  throw e;
              }
          }
          logger.debug("Claimed ticket {}.", ticket);
          return true;
      }
docs: Grab a ticket in the queue.
  
  @param zookeeper ZooKeeper connection to use.
  @param lockNode Path to the znode representing the locking queue.
  @param ticket Name of the ticket to attempt to grab.
  @return True on success, false if the ticket was already grabbed by another process.