Java 类org.apache.zookeeper.AsyncCallback.StatCallback 实例源码

项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setData.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of exists. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #exists(String, boolean)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of setData. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of setACL. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:incubator-pulsar    文件:NamespaceService.java   
/**
 * update new bundle-range to LocalZk (create a new node if not present)
 *
 * @param nsname
 * @param nsBundles
 * @param callback
 * @throws Exception
 */
private void updateNamespaceBundles(NamespaceName nsname, NamespaceBundles nsBundles, StatCallback callback)
        throws Exception {
    checkNotNull(nsname);
    checkNotNull(nsBundles);
    String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString());
    Optional<LocalPolicies> policies = pulsar.getLocalZkCacheService().policiesCache().get(path);

    if (!policies.isPresent()) {
        // if policies is not present into localZk then create new policies
        this.pulsar.getLocalZkCacheService().createPolicies(path, false).get(cacheTimeOutInSec, SECONDS);
        policies = this.pulsar.getLocalZkCacheService().policiesCache().get(path);
    }

    policies.get().bundles = getBundlesData(nsBundles);
    this.pulsar.getLocalZkCache().getZooKeeper().setData(path,
            ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies.get()), -1, callback, null);
    // invalidate namespace's local-policies
    this.pulsar.getLocalZkCacheService().policiesCache().invalidate(path);
}
项目:incubator-pulsar    文件:MockZooKeeper.java   
@Override
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    executor.execute(() -> {
        mutex.lock();
        if (getProgrammedFailStatus()) {
            mutex.unlock();
            cb.processResult(failReturnCode.intValue(), path, ctx, null);
            return;
        } else if (stopped) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
            return;
        }

        if (tree.containsKey(path)) {
            mutex.unlock();
            cb.processResult(0, path, ctx, new Stat());
        } else {
            mutex.unlock();
            cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
        }
    });
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setData.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setData.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:zookeeper.dsc    文件:ZooKeeper.java   
/**
 * The Asynchronous version of exists. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #exists(String, boolean)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:zookeeper.dsc    文件:ZooKeeper.java   
/**
 * The Asynchronous version of setData. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:zookeeper.dsc    文件:ZooKeeper.java   
/**
 * The Asynchronous version of setACL. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:incubator-pulsar    文件:MockZooKeeper.java   
@Override
public void exists(String path, Watcher watcher, StatCallback cb, Object ctx) {
    executor.execute(() -> {
        mutex.lock();
        if (getProgrammedFailStatus()) {
            mutex.unlock();
            cb.processResult(failReturnCode.intValue(), path, ctx, null);
            return;
        } else if (stopped) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
            return;
        }

        if (watcher != null) {
            watchers.put(path, watcher);
        }

        if (tree.containsKey(path)) {
            mutex.unlock();
            cb.processResult(0, path, ctx, new Stat());
        } else {
            mutex.unlock();
            cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
        }
    });
}
项目:Camel    文件:ExistenceChangedOperation.java   
@Override
protected void installWatch() {
    connection.exists(getNode(), this, new StatCallback() {
        public void processResult(int rc, String path, Object ctx, Stat stat) {
        }
    }, null);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Installed exists watch");
    }
}
项目:bigstreams    文件:LedgerHandle.java   
public void writeLedgerConfig(StatCallback callback, Object ctx) {
  bk.getZkHandle().setData(StringUtils.getLedgerNodePath(ledgerId),
      metadata.serialize(), -1, callback, ctx);
}
项目:bigstreams    文件:LedgerHandle.java   
void handleBookieFailure(InetSocketAddress addr, final int bookieIndex) {
  InetSocketAddress newBookie;

  if (LOG.isDebugEnabled()) {
    LOG.debug("Handling failure of bookie: " + addr + " index: "
        + bookieIndex);
  }

  try {
    newBookie = bk.bookieWatcher
        .getAdditionalBookie(metadata.currentEnsemble);
  } catch (BKNotEnoughBookiesException e) {
    LOG
        .error("Could not get additional bookie to remake ensemble, closing ledger: "
            + ledgerId);
    handleUnrecoverableErrorDuringAdd(e.getCode());
    return;
  }

  final ArrayList<InetSocketAddress> newEnsemble = new ArrayList<InetSocketAddress>(
      metadata.currentEnsemble);
  newEnsemble.set(bookieIndex, newBookie);

  if (LOG.isDebugEnabled()) {
    LOG.debug("Changing ensemble from: " + metadata.currentEnsemble + " to: "
        + newEnsemble + " for ledger: " + ledgerId + " starting at entry: "
        + (lastAddConfirmed + 1));
  }

  metadata.addEnsemble(lastAddConfirmed + 1, newEnsemble);

  writeLedgerConfig(new StatCallback() {
    @Override
    public void processResult(final int rc, String path, Object ctx, Stat stat) {

      bk.mainWorkerPool.submitOrdered(ledgerId, new SafeRunnable() {
        @Override
        public void safeRun() {
          if (rc != KeeperException.Code.OK.intValue()) {
            LOG
                .error("Could not persist ledger metadata while changing ensemble to: "
                    + newEnsemble + " , closing ledger");
            handleUnrecoverableErrorDuringAdd(BKException.Code.ZKException);
            return;
          }

          for (PendingAddOp pendingAddOp : pendingAddOps) {
            pendingAddOp.unsetSuccessAndSendWriteRequest(bookieIndex);
          }
        }
      });

    }
  }, null);

}
项目:incubator-pulsar    文件:MockZooKeeper.java   
@Override
public void setData(final String path, final byte[] data, int version, final StatCallback cb, final Object ctx) {
    if (stopped) {
        cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
        return;
    }

    executor.execute(() -> {
        final Set<Watcher> toNotify = Sets.newHashSet();

        mutex.lock();

        if (getProgrammedFailStatus()) {
            mutex.unlock();
            cb.processResult(failReturnCode.intValue(), path, ctx, null);
            return;
        } else if (stopped) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
            return;
        }

        if (!tree.containsKey(path)) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
            return;
        }

        int currentVersion = tree.get(path).second;

        // Check version
        if (version != -1 && version != currentVersion) {
            log.debug("[{}] Current version: {} -- Expected: {}", path, currentVersion, version);
            mutex.unlock();
            cb.processResult(KeeperException.Code.BadVersion, path, ctx, null);
            return;
        }

        int newVersion = currentVersion + 1;
        log.debug("[{}] Updating -- current version: {}", path, currentVersion);
        tree.put(path, Pair.create(data, newVersion));
        Stat stat = new Stat();
        stat.setVersion(newVersion);

        mutex.unlock();
        cb.processResult(0, path, ctx, stat);

        toNotify.addAll(watchers.get(path));
        watchers.removeAll(path);

        for (Watcher watcher : toNotify) {
            watcher.process(new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path));
        }
    });
}
项目:zookeeper.dsc    文件:LedgerHandle.java   
public void writeLedgerConfig(StatCallback callback, Object ctx) {
  bk.getZkHandle().setData(StringUtils.getLedgerNodePath(ledgerId),
      metadata.serialize(), -1, callback, ctx);
}
项目:zookeeper.dsc    文件:LedgerHandle.java   
void handleBookieFailure(InetSocketAddress addr, final int bookieIndex) {
  InetSocketAddress newBookie;

  if (LOG.isDebugEnabled()) {
    LOG.debug("Handling failure of bookie: " + addr + " index: "
        + bookieIndex);
  }

  try {
    newBookie = bk.bookieWatcher
        .getAdditionalBookie(metadata.currentEnsemble);
  } catch (BKNotEnoughBookiesException e) {
    LOG
        .error("Could not get additional bookie to remake ensemble, closing ledger: "
            + ledgerId);
    handleUnrecoverableErrorDuringAdd(e.getCode());
    return;
  }

  final ArrayList<InetSocketAddress> newEnsemble = new ArrayList<InetSocketAddress>(
      metadata.currentEnsemble);
  newEnsemble.set(bookieIndex, newBookie);

  if (LOG.isDebugEnabled()) {
    LOG.debug("Changing ensemble from: " + metadata.currentEnsemble + " to: "
        + newEnsemble + " for ledger: " + ledgerId + " starting at entry: "
        + (lastAddConfirmed + 1));
  }

  metadata.addEnsemble(lastAddConfirmed + 1, newEnsemble);

  writeLedgerConfig(new StatCallback() {
    @Override
    public void processResult(final int rc, String path, Object ctx, Stat stat) {

      bk.mainWorkerPool.submitOrdered(ledgerId, new SafeRunnable() {
        @Override
        public void safeRun() {
          if (rc != KeeperException.Code.OK.intValue()) {
            LOG
                .error("Could not persist ledger metadata while changing ensemble to: "
                    + newEnsemble + " , closing ledger");
            handleUnrecoverableErrorDuringAdd(BKException.Code.ZKException);
            return;
          }

          for (PendingAddOp pendingAddOp : pendingAddOps) {
            pendingAddOp.unsetSuccessAndSendWriteRequest(bookieIndex);
          }
        }
      });

    }
  }, null);

}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, boolean)
 */
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of exists. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #exists(String, boolean)
 */
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, boolean)
 */
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, boolean)
 */
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}
项目:zookeeper.dsc    文件:ZooKeeper.java   
/**
 * The Asynchronous version of exists. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #exists(String, boolean)
 */
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
    exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}