List of usage examples for org.apache.zookeeper AsyncCallback.StatCallback AsyncCallback.StatCallback
AsyncCallback.StatCallback
From source file:com.jbrisbin.vpc.zk.GroovyZooKeeperHelper.java
License:Apache License
/** * Check if node exists asynchronously.// ww w.j av a 2 s. c o m * * @param path * @param watch * @param callback * @throws InterruptedException * @throws KeeperException */ public void exists(Object path, boolean watch, final Closure callback) throws InterruptedException, KeeperException { zookeeper.exists(getPathAsString(path), watch, new AsyncCallback.StatCallback() { public void processResult(int rc, String path, Object ctx, Stat stat) { callback.setProperty("returnCode", rc); callback.setProperty("path", path); callback.setDelegate(ctx); callback.call(stat); } }, this); }
From source file:com.jbrisbin.vpc.zk.GroovyZooKeeperHelper.java
License:Apache License
/** * Set a node's data asynchronously.//from w w w. j a v a2 s . com * * @param path * @param data * @param version * @param callback */ public void setData(Object path, Object data, int version, final Closure callback) { zookeeper.setData(getPathAsString(path), serialize(data), version, new AsyncCallback.StatCallback() { public void processResult(int rc, String path, Object ctx, Stat stat) { callback.setDelegate(ctx); callback.setProperty("returnCode", rc); callback.setProperty("path", path); callback.call(stat); } }, this); }
From source file:com.sonian.elasticsearch.zookeeper.client.ZooKeeperClientService.java
License:Apache License
@Override public boolean verifyConnection(TimeValue timeout) throws InterruptedException { if (connected()) { final AtomicBoolean stats = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); zooKeeper.exists("/", null, new AsyncCallback.StatCallback() { @Override/*from ww w. j a v a 2 s. c o m*/ public void processResult(int rc, String path, Object ctx, Stat stat) { stats.set(stat != null); latch.countDown(); } }, null); latch.await(timeout.getMillis(), TimeUnit.MILLISECONDS); return stats.get(); } else { return false; } }
From source file:org.rioproject.zookeeper.watcher.ZooKeeperServiceWatcher.java
License:Apache License
public void process(WatchedEvent event) { String path = event.getPath(); if (logger.isDebugEnabled()) logger.debug("{}", event); if (path == null) return;/* w w w . ja v a2 s . com*/ if (event.getType() == Event.EventType.None && event.getState().equals(Event.KeeperState.Expired)) { services.remove(path).serviceFailure(null, path); } else { if (logger.isDebugEnabled()) logger.debug("Path: {}", path); if (services.get(path) != null) { /* Something has changed on the node, let's find out if it still exists */ zooKeeper.exists(path, false, new AsyncCallback.StatCallback() { public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.NONODE.equals(KeeperException.Code.get(rc))) { services.remove(path).serviceFailure(null, path); } } }, null); } } }