code: public void performWithLock (final NodeObject.Lock lock, final LockedOperation operation)
      {
          acquireLock(lock, new ResultListener<String>() {
              public void requestCompleted (String nodeName) {
                  if (getNodeObject().nodeName.equals(nodeName)) {
                      // lock acquired successfully - perform the operation, and release the lock.
                      try {
                          operation.run();
                      } finally {
                          releaseLock(lock, new ResultListener.NOOP<String>());
                      }
                  } else {
                      // some other peer beat us to it
                      operation.fail(nodeName);
                      if (nodeName == null) {
                          log.warning("Lock acquired by null?", "lock", lock);
                      }
                  }
              }
              public void requestFailed (Exception cause) {
                  log.warning("Lock acquisition failed", "lock", lock, cause);
                  operation.fail(null);
              }
          });
      }
docs: Tries to acquire the resource lock and, if successful, performs the operation and releases
  the lock; if unsuccessful, calls the operation's failure handler. Please note: the lock will
  be released immediately after the operation.