Search in sources :

Example 71 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class ZooKeeperClient method getData.

@Override
public void getData(final String path, final boolean watch, final DataCallback cb, final Object context) {
    final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, getStats) {

        final DataCallback dataCb = new DataCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
                ZooWorker worker = (ZooWorker) ctx;
                if (allowRetry(worker, rc)) {
                    backOffAndRetry(that, worker.nextRetryWaitTime());
                } else {
                    cb.processResult(rc, path, context, data, stat);
                }
            }
        };

        @Override
        void zkRun() {
            ZooKeeper zkHandle = zk.get();
            if (null == zkHandle) {
                ZooKeeperClient.super.getData(path, watch, dataCb, worker);
            } else {
                zkHandle.getData(path, watch, dataCb, worker);
            }
        }

        @Override
        public String toString() {
            return String.format("getData (%s, watcher = %s)", path, watch);
        }
    };
    // execute it immediately
    proc.run();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeper(org.apache.zookeeper.ZooKeeper) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback)

Example 72 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class ZooKeeperClient method addAuthInfo.

@Override
public void addAuthInfo(String scheme, byte[] auth) {
    ZooKeeper zkHandle = zk.get();
    if (null == zkHandle) {
        super.addAuthInfo(scheme, auth);
        return;
    }
    zkHandle.addAuthInfo(scheme, auth);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper)

Example 73 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class ZooKeeperClient method getChildren.

@Override
public void getChildren(final String path, final Watcher watcher, final ChildrenCallback cb, final Object context) {
    final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, getChildrenStats) {

        final ChildrenCallback childCb = new ChildrenCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, List<String> children) {
                ZooWorker worker = (ZooWorker) ctx;
                if (allowRetry(worker, rc)) {
                    backOffAndRetry(that, worker.nextRetryWaitTime());
                } else {
                    cb.processResult(rc, path, context, children);
                }
            }
        };

        @Override
        void zkRun() {
            ZooKeeper zkHandle = zk.get();
            if (null == zkHandle) {
                ZooKeeperClient.super.getChildren(path, watcher, childCb, worker);
            } else {
                zkHandle.getChildren(path, watcher, childCb, worker);
            }
        }

        @Override
        public String toString() {
            return String.format("getChildren (%s, watcher = %s)", path, watcher);
        }
    };
    // execute it immediately
    proc.run();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ChildrenCallback(org.apache.zookeeper.AsyncCallback.ChildrenCallback)

Example 74 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class ZooKeeperClient method getChildren.

@Override
public void getChildren(final String path, final boolean watch, final ChildrenCallback cb, final Object context) {
    final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, getChildrenStats) {

        final ChildrenCallback childCb = new ChildrenCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, List<String> children) {
                ZooWorker worker = (ZooWorker) ctx;
                if (allowRetry(worker, rc)) {
                    backOffAndRetry(that, worker.nextRetryWaitTime());
                } else {
                    cb.processResult(rc, path, context, children);
                }
            }
        };

        @Override
        void zkRun() {
            ZooKeeper zkHandle = zk.get();
            if (null == zkHandle) {
                ZooKeeperClient.super.getChildren(path, watch, childCb, worker);
            } else {
                zkHandle.getChildren(path, watch, childCb, worker);
            }
        }

        @Override
        public String toString() {
            return String.format("getChildren (%s, watcher = %s)", path, watch);
        }
    };
    // execute it immediately
    proc.run();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ChildrenCallback(org.apache.zookeeper.AsyncCallback.ChildrenCallback)

Example 75 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class ZooKeeperClient method sync.

@Override
public void sync(final String path, final VoidCallback cb, final Object context) {
    final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, syncStats) {

        final VoidCallback vCb = new VoidCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx) {
                ZooWorker worker = (ZooWorker) ctx;
                if (allowRetry(worker, rc)) {
                    backOffAndRetry(that, worker.nextRetryWaitTime());
                } else {
                    cb.processResult(rc, path, context);
                }
            }
        };

        @Override
        public String toString() {
            return String.format("sync (%s)", path);
        }

        @Override
        void zkRun() {
            ZooKeeper zkHandle = zk.get();
            if (null == zkHandle) {
                ZooKeeperClient.super.sync(path, vCb, worker);
            } else {
                zkHandle.sync(path, vCb, worker);
            }
        }
    };
    // execute it immediately
    proc.run();
}
Also used : VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) ZooKeeper(org.apache.zookeeper.ZooKeeper)

Aggregations

ZooKeeper (org.apache.zookeeper.ZooKeeper)605 Test (org.junit.jupiter.api.Test)190 KeeperException (org.apache.zookeeper.KeeperException)153 Test (org.junit.Test)100 Stat (org.apache.zookeeper.data.Stat)86 IOException (java.io.IOException)83 CountDownLatch (java.util.concurrent.CountDownLatch)80 WatchedEvent (org.apache.zookeeper.WatchedEvent)70 Watcher (org.apache.zookeeper.Watcher)59 ArrayList (java.util.ArrayList)47 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)41 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)38 Timeout (org.junit.jupiter.api.Timeout)32 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)31 File (java.io.File)28 HashMap (java.util.HashMap)26 CompletableFuture (java.util.concurrent.CompletableFuture)22 Test (org.testng.annotations.Test)21 AsyncCallback (org.apache.zookeeper.AsyncCallback)19 ACL (org.apache.zookeeper.data.ACL)19