private byte[] get(final String pathSuffix) throws Exception {
   return RetryLoop.callWithRetry(
       zk.getZookeeperClient(),
       new Callable<byte[]>() {
         @Override
         public byte[] call() throws Exception {
           return zk.getData().forPath(buildZookeeperPath(pathSuffix));
         }
       });
 }
 private void watch(final String pathSuffix, final Watcher callback) throws Exception {
   RetryLoop.callWithRetry(
       zk.getZookeeperClient(),
       new Callable<Void>() {
         @Override
         public Void call() throws Exception {
           zk.checkExists().usingWatcher(callback).forPath(buildZookeeperPath(pathSuffix));
           return null;
         }
       });
 }
  /**
   * Optimistic concurrency scheme for tryAtomicUpdate. Try to update, and keep trying until
   * successful.
   *
   * @param pathSuffix suffix to use to build path in ZooKeeper.
   * @param f function used to initialize the node, or transform the data already there.
   * @throws Exception
   */
  private void atomicUpdate(final String pathSuffix, final NodeFunction f) throws Exception {
    boolean done = false;

    do {
      done =
          RetryLoop.callWithRetry(
              zk.getZookeeperClient(),
              new Callable<Boolean>() {
                @Override
                public Boolean call() throws Exception {
                  return tryAtomicUpdate(pathSuffix, f);
                }
              });
      Thread.sleep(BASE_OPTIMISTIC_RETRY_TIME_MS + rand.nextInt(BASE_OPTIMISTIC_RETRY_TIME_MS));
    } while (!done);
  }
Esempio n. 4
0
 private Stat pathInForeground(final String path) throws Exception {
   TimeTrace trace = client.getZookeeperClient().startTracer("ExistsBuilderImpl-Foreground");
   Stat returnStat =
       RetryLoop.callWithRetry(
           client.getZookeeperClient(),
           new Callable<Stat>() {
             @Override
             public Stat call() throws Exception {
               Stat returnStat;
               if (watching.isWatched()) {
                 returnStat = client.getZooKeeper().exists(path, true);
               } else {
                 returnStat = client.getZooKeeper().exists(path, watching.getWatcher());
               }
               return returnStat;
             }
           });
   trace.commit();
   return returnStat;
 }