org.apache.zookeeper.ZooKeeper - java examples

Here are the examples of the java api org.apache.zookeeper.ZooKeeper taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : TestBookieWatcher.java
Copyright Apache License 2.0
Author : apache
@Test
public void testBookieWatcherDieWhenSessionExpired() throws Exception {
    final int timeout = 2000;
    final CountDownLatch connectLatch = new CountDownLatch(1);
    @Cleanup
    ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), timeout, new Watcher() {

        @Override
        public void process(WatchedEvent watchedEvent) {
            if (EventType.None == watchedEvent.getType() && KeeperState.SyncConnected == watchedEvent.getState()) {
                connectLatch.countDown();
            }
        }
    });
    connectLatch.await();
    runBookieWatcherWhenSessionExpired(zk, timeout, false);
}

19 View Complete Implementation : ZKAccessControlManager.java
Copyright Apache License 2.0
Author : apache
private void createDefaultAccessControlEntryIfNeeded(final CompletableFuture<ZKAccessControl> promise) {
    ZooKeeper zk;
    try {
        zk = zkc.get();
    } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
        promise.completeExceptionally(e);
        return;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        promise.completeExceptionally(e);
        return;
    }
    ZkUtils.asyncCreateFullPathOptimistic(zk, zkRootPath, new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT, new AsyncCallback.StringCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, String name) {
            if (KeeperException.Code.OK.intValue() == rc) {
                logger.info("Created zk path {} for default ACL.", zkRootPath);
                fetchDefaultAccessControlEntry(promise);
            } else {
                promise.completeExceptionally(KeeperException.create(KeeperException.Code.get(rc)));
            }
        }
    }, null);
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Updates the node data if the node exists.
 *
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param writable
 *          - Writable
 */
public static void existsUpdateNodeData(ZooKeeper zk, String path, Writable writable) throws OrbZKFailure {
    if (nodeExists(zk, path)) {
        updateNodeData(zk, path, writable);
    }
}

19 View Complete Implementation : LocalDLMEmulator.java
Copyright Apache License 2.0
Author : apache
public static ZooKeeper connectZooKeeper(String zkHost, int zkPort, int zkTimeoutSec) throws IOException, KeeperException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final String zkHostPort = zkHost + ":" + zkPort;
    ZooKeeper zkc = new ZooKeeper(zkHostPort, zkTimeoutSec * 1000, new Watcher() {

        public void process(WatchedEvent event) {
            if (event.getState() == Event.KeeperState.SyncConnected) {
                latch.countDown();
            }
        }
    });
    if (!latch.await(zkTimeoutSec, TimeUnit.SECONDS)) {
        throw new IOException("Zookeeper took too long to connect");
    }
    return zkc;
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @returns String
 */
public static String notExistCreateNode(ZooKeeper zk, String path) throws OrbZKFailure {
    String nodePath = null;
    if (!nodeExists(zk, path)) {
        nodePath = tryToCreateNode(zk, path);
    }
    return nodePath;
}

19 View Complete Implementation : OrbFastAllDoneBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests behavior of orbFastBarrier over groups of a large number and a
 * larger number of steps
 *
 * @throws InterruptedException
 * @throws IOException
 * @throws OrbZKFailure
 */
@Test
public void StressTest() throws IOException, InterruptedException, OrbZKFailure {
    // deleteThreads();
    int numBarrierStressThreads = 25;
    int numSteps = 25;
    CountDownLatch complete = new CountDownLatch(numBarrierStressThreads);
    CountDownLatch startLatch = new CountDownLatch(1);
    BarrierStressThread[] threads = new BarrierStressThread[numBarrierStressThreads];
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    for (int i = 0; i < numBarrierStressThreads; i++) {
        ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
        ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
        threads[i] = new BarrierStressThread(numSteps, complete, startLatch, numBarrierStressThreads, zk, orbConf, "member" + i);
        threads[i].start();
    }
    startLatch.countDown();
    complete.await();
    boolean allBarriersCreated = true;
    for (int i = 0; i < numBarrierStressThreads; i++) {
        allBarriersCreated = allBarriersCreated && ZookeeperUtils.nodeExists(zk, "/barrier" + i);
        if (allBarriersCreated) {
            ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
            ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
        }
    }
    replacedertTrue(allBarriersCreated);
}

19 View Complete Implementation : AuditorElector.java
Copyright Apache License 2.0
Author : apache
/**
 * Query zookeeper for the currently elected auditor.
 * @return the bookie id of the current auditor
 */
public static BookieSocketAddress getCurrentAuditor(ServerConfiguration conf, ZooKeeper zk) throws KeeperException, InterruptedException, IOException {
    String electionRoot = ZKMetadataDriverBase.resolveZkLedgersRootPath(conf) + '/' + BookKeeperConstants.UNDER_REPLICATION_NODE + '/' + ELECTION_ZNODE;
    List<String> children = zk.getChildren(electionRoot, false);
    Collections.sort(children, new AuditorElector.ElectionComparator());
    if (children.size() < 1) {
        return null;
    }
    String ledger = electionRoot + "/" + children.get(AUDITOR_INDEX);
    byte[] data = zk.getData(ledger, false, null);
    AuditorVoteFormat.Builder builder = AuditorVoteFormat.newBuilder();
    TextFormat.merge(new String(data, UTF_8), builder);
    AuditorVoteFormat v = builder.build();
    String[] parts = v.getBookieId().split(":");
    return new BookieSocketAddress(parts[0], Integer.parseInt(parts[1]));
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Return the nodeWritable
 */
public static Writable getNodeWritable(ZooKeeper zk, String path, Clreplaced<? extends Writable> writableClreplaced, OrbConfiguration orbConf) throws OrbZKFailure {
    byte[] result = null;
    try {
        result = zk.getData(path, false, null);
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
    if (result != null) {
        return byteArrayToWritable(result, writableClreplaced, orbConf);
    } else {
        return null;
    }
}

19 View Complete Implementation : BenchThroughputLatency.java
Copyright Apache License 2.0
Author : apache
/**
 * The benchmark is replaceduming zookeeper based metadata service.
 *
 * <p>TODO: update benchmark to use metadata service uri {@link https://github.com/apache/bookkeeper/issues/1331}
 */
private static long warmUp(byte[] data, int ledgers, int ensemble, int qSize, byte[] preplacedwd, ClientConfiguration conf) throws KeeperException, IOException, InterruptedException, BKException {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final int bookies;
    String bookieRegistrationPath = ZKMetadataDriverBase.resolveZkLedgersRootPath(conf) + "/" + AVAILABLE_NODE;
    ZooKeeper zk = null;
    try {
        final String servers = ZKMetadataDriverBase.resolveZkServers(conf);
        zk = new ZooKeeper(servers, 15000, new Watcher() {

            @Override
            public void process(WatchedEvent event) {
                if (event.getState() == KeeperState.SyncConnected) {
                    connectLatch.countDown();
                }
            }
        });
        if (!connectLatch.await(10, TimeUnit.SECONDS)) {
            LOG.error("Couldn't connect to zookeeper at " + servers);
            throw new IOException("Couldn't connect to zookeeper " + servers);
        }
        bookies = zk.getChildren(bookieRegistrationPath, false).size() - 1;
    } finally {
        if (zk != null) {
            zk.close();
        }
    }
    BenchThroughputLatency warmup = new BenchThroughputLatency(bookies, bookies, bookies, preplacedwd, ledgers, 10000, conf);
    warmup.setEntryData(data);
    Thread thread = new Thread(warmup);
    thread.start();
    thread.join();
    warmup.close();
    return warmup.getThroughput();
}

19 View Complete Implementation : ConnectWatcher.java
Copyright Apache License 2.0
Author : jzachr
/**
 * This method connects to a running ZooKeeper.
 *
 * @param hosts
 *          - String containing a comma separated list of host:port pairs, each corresponding to a ZooKeeper
 *          server.
 * @returns ZooKeeper
 */
public ZooKeeper connect(String hosts) throws IOException, InterruptedException {
    ZooKeeper _zk = new ZooKeeper(hosts, SESSION_TIMEOUT, this);
    connectedSignal.await();
    return _zk;
}

19 View Complete Implementation : ZkUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Async get direct children under single node.
 *
 * @param zk
 *          zookeeper client
 * @param node
 *          node path
 * @param cb
 *          callback function
 */
public static void getChildrenInSingleNode(final ZooKeeper zk, final String node, final GenericCallback<List<String>> cb) {
    zk.sync(node, new AsyncCallback.VoidCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx) {
            if (rc != Code.OK.intValue()) {
                LOG.error("ZK error syncing nodes when getting children: ", KeeperException.create(KeeperException.Code.get(rc), path));
                cb.operationComplete(rc, null);
                return;
            }
            zk.getChildren(node, false, new AsyncCallback.ChildrenCallback() {

                @Override
                public void processResult(int rc, String path, Object ctx, List<String> nodes) {
                    if (rc != Code.OK.intValue()) {
                        LOG.error("Error polling ZK for the available nodes: ", KeeperException.create(KeeperException.Code.get(rc), path));
                        cb.operationComplete(rc, null);
                        return;
                    }
                    cb.operationComplete(rc, nodes);
                }
            }, null);
        }
    }, null);
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param createMode
 *          - CreateMode
 * @returns String
 */
public static String tryToCreateNode(ZooKeeper zk, String path, CreateMode createMode) throws OrbZKFailure {
    String result = null;
    try {
        result = zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, createMode);
    } catch (KeeperException.NodeExistsException e) {
        LOG.debug("Node " + path + " already exists!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
    return result;
}

19 View Complete Implementation : OrbBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if only some of the member nodes join.
 *
 * @throws Exception
 */
@Test
public void someMembersJoin() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    CountDownLatch lastMemberLatch = new CountDownLatch(1);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbBarrier testBarrier1 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbBarrier testBarrier2 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    OrbBarrier testBarrier3 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch);
    BarrierThread bThread3 = new BarrierThread(testBarrier3, lastMemberLatch, everyoneDoneLatch);
    bThread1.start();
    bThread2.start();
    bThread3.start();
    // start first 2 threads
    startLatch.countDown();
    // wait on the threads with 500ms timeout, expect to
    everyoneDoneLatch.await(500, TimeUnit.MILLISECONDS);
    // timeout
    // start the last member
    lastMemberLatch.countDown();
    everyoneDoneLatch.await();
    replacedertTrue(zk.exists(barrierName + "/member1", false) != null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) != null);
    replacedertTrue(zk.exists(barrierName + "/member3", false) != null);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member1");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member2");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member3");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
    zk.close();
}

19 View Complete Implementation : ZkUtils.java
Copyright Apache License 2.0
Author : apache
public static void deleteFullPathOptimistic(ZooKeeper zkc, String path, int znodeVersion) throws KeeperException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(Code.OK.intValue());
    asyncDeleteFullPathOptimistic(zkc, path, znodeVersion, new VoidCallback() {

        @Override
        public void processResult(int rc2, String path, Object ctx) {
            rc.set(rc2);
            latch.countDown();
        }
    }, path);
    latch.await();
    if (rc.get() != Code.OK.intValue()) {
        throw KeeperException.create(Code.get(rc.get()));
    }
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param string
 *          - String
 * @returns boolean
 */
public static boolean nodeExists(ZooKeeper zk, String string) {
    Stat stat;
    try {
        stat = zk.exists(string, false);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return stat != null;
}

19 View Complete Implementation : TestBookieWatcher.java
Copyright Apache License 2.0
Author : apache
private void expireZooKeeperSession(ZooKeeper zk, int timeout) throws IOException, InterruptedException, KeeperException {
    final CountDownLatch latch = new CountDownLatch(1);
    ZooKeeper newZk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), timeout, new Watcher() {

        @Override
        public void process(WatchedEvent event) {
            if (event.getType() == EventType.None && event.getState() == KeeperState.SyncConnected) {
                latch.countDown();
            }
        }
    }, zk.getSessionId(), zk.getSessionPreplacedwd());
    if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
        throw KeeperException.create(KeeperException.Code.CONNECTIONLOSS);
    }
    newZk.close();
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Sets the data of an already existing node to the value of the writable.
 *
 * @param zk
 *          is the zookeeper instance
 * @param path
 *          is the path of the node
 * @param writable
 *          is the Writable object who's data will set in the node
 * @throws OrbZKFailure
 */
public static void setNodeData(ZooKeeper zk, String path, Writable writable) throws OrbZKFailure {
    try {
        zk.setData(path, writableToByteArray(writable), -1);
    } catch (KeeperException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    } catch (IOException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    }
}

19 View Complete Implementation : TestZkRegistrationManager.java
Copyright Apache License 2.0
Author : apache
/**
 * Unit test of {@link RegistrationManager}.
 */
public clreplaced TestZkRegistrationManager {

    private ZooKeeperCluster localZkServer;

    private ZooKeeper zkc;

    @Before
    public void setup() throws Exception {
        localZkServer = new ZooKeeperUtil();
        localZkServer.startCluster();
    }

    @After
    public void teardown() throws Exception {
        localZkServer.stopCluster();
    }

    @Test
    public void testPrepareFormat() throws Exception {
        try {
            ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
            conf.setMetadataServiceUri("zk+hierarchical://localhost:2181/test/ledgers");
            zkc = localZkServer.getZooKeeperClient();
            ZKRegistrationManager zkRegistrationManager = new ZKRegistrationManager(conf, zkc, () -> {
            });
            zkRegistrationManager.prepareFormat();
            replacedertTrue(zkc.exists("/test/ledgers", false) != null);
        } finally {
            if (zkc != null) {
                zkc.close();
            }
        }
    }
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Updates data in a node with the given Writable parameter.
 *
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param writable
 *          - Writable
 */
public static void updateNodeData(ZooKeeper zk, String path, Writable writable) throws OrbZKFailure {
    try {
        zk.setData(path, writableToByteArray(writable), -1);
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    } catch (IOException e) {
        throw new OrbZKFailure(e);
    }
}

19 View Complete Implementation : BookKeeperClusterUtils.java
Copyright Apache License 2.0
Author : apache
public static ZooKeeper zookeeperClient(DockerClient docker) throws Exception {
    String connectString = BookKeeperClusterUtils.zookeeperConnectString(docker);
    CompletableFuture<Void> future = new CompletableFuture<>();
    ZooKeeper zk = new ZooKeeper(connectString, 10000, (e) -> {
        if (e.getState().equals(KeeperState.SyncConnected)) {
            future.complete(null);
        }
    });
    future.get();
    return zk;
}

19 View Complete Implementation : OrbFastBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 */
private void deleteThreads() throws InterruptedException, OrbZKFailure, IOException {
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    for (int i = 0; i < 100; i++) {
        ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
        ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
    }
    System.err.println("Waiting 10 seconds");
    Thread.sleep(10000);
}

19 View Complete Implementation : OrbFastAllDoneBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if all expected member nodes join in a
 * timely manner.
 *
 * @throws Exception
 */
@Test
public void allMembersJoin() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbFastAllDoneBarrier testBarrier1 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbFastAllDoneBarrier testBarrier2 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    OrbFastAllDoneBarrier testBarrier3 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch, true);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch, true);
    BarrierThread bThread3 = new BarrierThread(testBarrier3, startLatch, everyoneDoneLatch, true);
    bThread1.start();
    bThread2.start();
    bThread3.start();
    // start all threads
    startLatch.countDown();
    // wait until all threads are done
    everyoneDoneLatch.await();
    // the nodes have deleted themselves ont the way out
    replacedertTrue(zk.exists(barrierName + "/member1", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member3", false) == null);
    // the nodes say they are all done
    replacedertTrue(bThread1.allDone());
    replacedertTrue(bThread2.allDone());
    replacedertTrue(bThread3.allDone());
    // the AllDone node exits
    replacedertTrue(zk.exists(barrierName + "/AllDone", false) != null);
    ZookeeperUtils.recursiveDelete(zk, barrierName);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param node
 *          - Writable
 * @param createMode
 *          - CreateMode
 * @returns String
 */
public static String notExistCreateNode(ZooKeeper zk, String path, Writable node, CreateMode createMode) throws OrbZKFailure {
    String nodePath = null;
    if (!nodeExists(zk, path)) {
        nodePath = tryToCreateNode(zk, path, node, createMode);
    }
    return nodePath;
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Returns the children of a given node.
 *
 * @param zk
 *          is the zookeeper instance
 * @param path
 *          is the path of the node
 * @param watcher
 */
public static List<String> getChildren(ZooKeeper zk, String path, Watcher watcher) throws OrbZKFailure {
    try {
        return zk.getChildren(path, watcher);
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param createMode
 *          - CreateMode
 * @returns String
 */
public static String notExistCreateNode(ZooKeeper zk, String path, CreateMode createMode) throws OrbZKFailure {
    String nodePath = null;
    if (!nodeExists(zk, path)) {
        nodePath = tryToCreateNode(zk, path, createMode);
    }
    return nodePath;
}

19 View Complete Implementation : TestZooKeeperClient.java
Copyright Apache License 2.0
Author : apache
@Test(timeout = 60000)
public void testZooKeeperReconnection() throws Exception {
    int sessionTimeoutMs = 100;
    ZooKeeperClient zkc = clientBuilder(sessionTimeoutMs).zkAclId(null).build();
    ZooKeeper zk = zkc.get();
    long sessionId = zk.getSessionId();
    ZooKeeperClientUtils.expireSession(zkc, zkServers, 2 * sessionTimeoutMs);
    ZooKeeper newZk = zkc.get();
    while (!ZooKeeper.States.CONNECTED.equals(newZk.getState())) {
        TimeUnit.MILLISECONDS.sleep(sessionTimeoutMs / 2);
    }
    long newSessionId = newZk.getSessionId();
    replacedertTrue(newZk == zk);
    replacedertFalse(sessionId == newSessionId);
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Deletes a ZooKeeper node if it is empty (has no children).
 *
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 */
public static void deleteNodeIfEmpty(ZooKeeper zk, String path) throws OrbZKFailure {
    try {
        zk.delete(path, -1);
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException.BadVersionException e) {
        e.printStackTrace();
    } catch (KeeperException.NotEmptyException e) {
        LOG.debug("Node " + path + " is not empty!");
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    }
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @returns String
 */
public static String tryToCreateNode(ZooKeeper zk, String path) throws OrbZKFailure {
    String result = null;
    try {
        result = zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException.NodeExistsException e) {
        LOG.debug("Node " + path + " already exists!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
    return result;
}

19 View Complete Implementation : AutoRecoveryMainTest.java
Copyright Apache License 2.0
Author : apache
/*
     * start autoRecoveryMain and make sure all its components are running and
     * myVote node is existing
     */
ZKMetadataClientDriver startAutoRecoveryMain(AutoRecoveryMain autoRecoveryMain) throws InterruptedException, KeeperException, UnavailableException {
    autoRecoveryMain.start();
    ZKMetadataClientDriver metadataClientDriver = (ZKMetadataClientDriver) autoRecoveryMain.bkc.getMetadataClientDriver();
    ZooKeeper zk = metadataClientDriver.getZk();
    String myVote;
    for (int i = 0; i < 10; i++) {
        if (autoRecoveryMain.auditorElector.isRunning() && autoRecoveryMain.replicationWorker.isRunning() && autoRecoveryMain.isAutoRecoveryRunning()) {
            myVote = autoRecoveryMain.auditorElector.getMyVote();
            if (myVote != null) {
                if (null != zk.exists(myVote, false)) {
                    break;
                }
            }
        }
        Thread.sleep(100);
    }
    replacedertTrue("autoRecoveryMain components should be running", autoRecoveryMain.auditorElector.isRunning() && autoRecoveryMain.replicationWorker.isRunning() && autoRecoveryMain.isAutoRecoveryRunning());
    replacedertTrue("autoRecoveryMain's vote node should be existing", zk.exists(autoRecoveryMain.auditorElector.getMyVote(), false) != null);
    return metadataClientDriver;
}

19 View Complete Implementation : CommandLineUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Connects to ZooKeeper.
 *
 * @returns ZooKeeper
 */
public static ZooKeeper connectZookeeper() {
    OrbConfiguration orbConf = new OrbConfiguration(true);
    ZooKeeper zk = null;
    if (connectString == null) {
        connectString = orbConf.getOrbZooKeeperQuorum();
    }
    try {
        zk = ZookeeperUtils.connect(connectString);
    } catch (IOException e) {
        System.err.println("Could not connect : ");
        e.printStackTrace();
        System.exit(-1);
    } catch (InterruptedException e) {
        System.err.println("Could not connect : ");
        e.printStackTrace();
        System.exit(-1);
    }
    return zk;
}

19 View Complete Implementation : ZkUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Create zookeeper path recursively and optimistically. This method can throw
 * any of the KeeperExceptions which can be thrown by ZooKeeper#create.
 * KeeperException.NodeExistsException will only be thrown if the full path specified
 * by _path_ already exists. The existence of any parent znodes is not an error
 * condition.
 *
 * @param zkc
 *            - ZK instance
 * @param path
 *            - znode path
 * @param data
 *            - znode data
 * @param acl
 *            - Acl of the zk path
 * @param createMode
 *            - Create mode of zk path
 * @throws KeeperException
 *             if the server returns a non-zero error code, or invalid ACL
 * @throws InterruptedException
 *             if the transaction is interrupted
 */
public static void createFullPathOptimistic(ZooKeeper zkc, String path, byte[] data, final List<ACL> acl, final CreateMode createMode) throws KeeperException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(Code.OK.intValue());
    asyncCreateFullPathOptimistic(zkc, path, data, acl, createMode, new StringCallback() {

        @Override
        public void processResult(int rc2, String path, Object ctx, String name) {
            rc.set(rc2);
            latch.countDown();
        }
    }, null);
    latch.await();
    if (rc.get() != Code.OK.intValue()) {
        throw KeeperException.create(Code.get(rc.get()));
    }
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Recursively deletes a node and its children.
 *
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 */
public static void recursiveDelete(ZooKeeper zk, String path) throws OrbZKFailure {
    try {
        List<String> children = zk.getChildren(path, false);
        if (children != null) {
            for (String child : children) {
                recursiveDelete(zk, path + "/" + child);
            }
            for (String child : children) {
                zk.delete(path + "/" + child, -1);
            }
        }
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
}

19 View Complete Implementation : BookKeeperClusterUtils.java
Copyright Apache License 2.0
Author : apache
public static boolean metadataFormatIfNeeded(DockerClient docker, String version) throws Exception {
    @Cleanup
    ZooKeeper zk = BookKeeperClusterUtils.zookeeperClient(docker);
    if (zk.exists("/ledgers", false) == null) {
        String bookkeeper = "/opt/bookkeeper/" + version + "/bin/bookkeeper";
        runOnAnyBookie(docker, bookkeeper, "shell", "metaformat", "-nonInteractive");
        return true;
    } else {
        return false;
    }
}

19 View Complete Implementation : OrbFastBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if all expected member nodes join in a timely manner.
 *
 * @throws Exception
 */
@Test
public void allMembersJoin() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbFastBarrier testBarrier1 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbFastBarrier testBarrier2 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    OrbFastBarrier testBarrier3 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch);
    BarrierThread bThread3 = new BarrierThread(testBarrier3, startLatch, everyoneDoneLatch);
    bThread1.start();
    bThread2.start();
    bThread3.start();
    // start all threads
    startLatch.countDown();
    // wait until all threads are done
    everyoneDoneLatch.await();
    replacedertTrue(zk.exists(barrierName + "/member1", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member3", false) == null);
    ZookeeperUtils.recursiveDelete(zk, barrierName);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
    zk.close();
}

19 View Complete Implementation : ZKLogStreamMetadataStore.java
Copyright Apache License 2.0
Author : apache
private static void existPath(ZooKeeper zk, String path, String basePath, LinkedList<String> missingPaths, CompletableFuture<List<String>> future) {
    if (basePath.equals(path)) {
        future.complete(missingPaths);
        return;
    }
    zk.exists(path, false, (rc, path1, ctx, stat) -> {
        if (Code.OK.intValue() != rc && Code.NONODE.intValue() != rc) {
            future.completeExceptionally(new ZKException("Failed to check existence of path " + path1, Code.get(rc)));
            return;
        }
        if (Code.OK.intValue() == rc) {
            future.complete(missingPaths);
            return;
        }
        missingPaths.addLast(path);
        String parentPath = Utils.getParent(path);
        existPath(zk, parentPath, basePath, missingPaths, future);
    }, null);
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * @param zk
 *          - ZooKeeper
 * @param path
 *          - String
 * @param node
 *          - Writable
 * @param createMode
 *          - CreateMode
 * @returns String
 */
public static String tryToCreateNode(ZooKeeper zk, String path, Writable node, CreateMode createMode) throws OrbZKFailure {
    String result = null;
    try {
        result = zk.create(path, writableToByteArray(node), Ids.OPEN_ACL_UNSAFE, createMode);
    } catch (KeeperException.NodeExistsException e) {
        LOG.debug("Node " + path + " already exists!");
    } catch (KeeperException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    } catch (IOException e) {
        e.printStackTrace();
        throw new OrbZKFailure(e);
    }
    return result;
}

19 View Complete Implementation : ReplicationTestUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks whether ledger is in under-replication.
 */
static boolean isLedgerInUnderReplication(ZooKeeper zkc, long id, String basePath) throws KeeperException, InterruptedException {
    List<String> children;
    try {
        children = zkc.getChildren(basePath, true);
    } catch (KeeperException.NoNodeException nne) {
        return false;
    }
    boolean isMatched = false;
    for (String child : children) {
        if (child.startsWith("urL") && child.contains(String.valueOf(id))) {
            isMatched = true;
            break;
        } else {
            String path = basePath + '/' + child;
            try {
                if (zkc.getChildren(path, false).size() > 0) {
                    isMatched = isLedgerInUnderReplication(zkc, id, path);
                }
            } catch (KeeperException.NoNodeException nne) {
                return false;
            }
        }
    }
    return isMatched;
}

19 View Complete Implementation : TestWatchMemberData.java
Copyright Apache License 2.0
Author : jzachr
public clreplaced TesreplacedchMemberData {

    private static ZooKeeper zk;

    private static String basePath = "/TesreplacedchMemberData";

    private static TMember member = new TMember();

    /**
     */
    @Test
    public void WatchMemberData() throws IOException, InterruptedException, OrbZKFailure, KeeperException {
        zk = ZookeeperUtils.connect("localhost:21810");
        int data = 1;
        member.setData(data);
        ZookeeperUtils.tryToCreateNode(zk, basePath, CreateMode.PERSISTENT);
        CountDownLatch dataChangedCdl = new CountDownLatch(1);
        CountDownLatch startCdl = new CountDownLatch(1);
        CountDownLatch leaderChangeCdl = new CountDownLatch(1);
        CountDownLatch leaveCdl = new CountDownLatch(1);
        TTracker tt = new TTracker(zk, data, basePath, startCdl, leaderChangeCdl, leaveCdl, dataChangedCdl);
        tt.run();
        startCdl.await();
        int newData = 9999;
        tt.changeMemberData(newData);
        dataChangedCdl.await();
        replacedertTrue(tt.getMemberData() == newData);
        tt.leave();
        List<String> children = zk.getChildren(basePath, false);
        for (String node : children) {
            ZookeeperUtils.deleteNodeIfEmpty(zk, basePath + "/" + node);
        }
        ZookeeperUtils.deleteNodeIfEmpty(zk, basePath);
    }
}

19 View Complete Implementation : WhoIsAuditorCommand.java
Copyright Apache License 2.0
Author : apache
public boolean getAuditor(ServerConfiguration conf) throws ConfigurationException, InterruptedException, IOException, KeeperException {
    ZooKeeper zk = null;
    try {
        String metadataServiceUri = conf.getMetadataServiceUri();
        String zkServers = ZKMetadataDriverBase.getZKServersFromServiceUri(URI.create(metadataServiceUri));
        zk = ZooKeeperClient.newBuilder().connectString(zkServers).sessionTimeoutMs(conf.getZkTimeout()).build();
        BookieSocketAddress bookieId = AuditorElector.getCurrentAuditor(conf, zk);
        if (bookieId == null) {
            LOG.info("No auditor elected");
            return false;
        }
        LOG.info("Auditor: " + getBookieSocketAddrStringRepresentation(bookieId));
    } finally {
        if (zk != null) {
            zk.close();
        }
    }
    return true;
}

19 View Complete Implementation : OrbFastBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests behavior of orbFastBarrier over groups of a large number and a larger number of steps
 * @throws InterruptedException
 * @throws IOException
 * @throws OrbZKFailure
 */
@Test
public void StressTest() throws IOException, InterruptedException, OrbZKFailure {
    // deleteThreads();
    int numBarrierStressThreads = 100;
    int numSteps = 100;
    CountDownLatch complete = new CountDownLatch(numBarrierStressThreads);
    CountDownLatch startLatch = new CountDownLatch(1);
    BarrierStressThread[] threads = new BarrierStressThread[numBarrierStressThreads];
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    for (int i = 0; i < numBarrierStressThreads; i++) {
        ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
        ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
        threads[i] = new BarrierStressThread(numSteps, complete, startLatch, numBarrierStressThreads, zk, orbConf, "member" + i);
        threads[i].start();
    }
    startLatch.countDown();
    complete.await();
    boolean allBarriersCreated = true;
    for (int i = 0; i < numBarrierStressThreads; i++) {
        allBarriersCreated = allBarriersCreated && ZookeeperUtils.nodeExists(zk, "/barrier" + i);
        if (allBarriersCreated) {
            ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
            ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
        }
    }
    replacedertTrue(allBarriersCreated);
}

19 View Complete Implementation : BookKeeperTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testConstructionNotConnectedExplicitZk() throws Exception {
    ClientConfiguration conf = new ClientConfiguration();
    conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()).setZkTimeout(20000);
    CountDownLatch l = new CountDownLatch(1);
    zkUtil.sleepCluster(200, TimeUnit.MILLISECONDS, l);
    l.await();
    ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 50, event -> {
    });
    replacedertFalse("ZK shouldn't have connected yet", zk.getState().isConnected());
    try {
        BookKeeper bkc = new BookKeeper(conf, zk);
        fail("Shouldn't be able to construct with unconnected zk");
    } catch (IOException cle) {
        // correct behaviour
        replacedertTrue(cle.getCause() instanceof ConnectionLossException);
    }
}

19 View Complete Implementation : OrbPartitionProcess.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Calculates what the clreplaced paths for the distributed files that are in this parreplacedions temp directory. All
 * files are distributed to /temp directory/GoldenOrb/jobNumber/file name.
 *
 * @return A list of the clreplaced paths that need to be added to this parreplacedions clreplaced path
 * @throws IOException
 * @throws InterruptedException
 * @throws OrbZKFailure
 */
private List<String> getLocalFilesPath() throws IOException, InterruptedException, OrbZKFailure {
    List<String> paths = null;
    ZooKeeper zk = ZookeeperUtils.connect(conf.getOrbZooKeeperQuorum());
    String zkPath = "/GoldenOrb/" + conf.getOrbClusterName() + "/JobQueue/" + jobNumber;
    logger.info("Getting node " + zkPath + " from ZooKeeper");
    OrbConfiguration orbConf = (OrbConfiguration) ZookeeperUtils.getNodeWritable(zk, zkPath, OrbConfiguration.clreplaced, conf);
    if (orbConf != null) {
        Path[] tempPaths = orbConf.getHDFSdistributedFiles();
        if (tempPaths != null) {
            paths = new ArrayList<String>();
            for (Path path : tempPaths) {
                String[] name = path.toString().split("/");
                // files are always put in /<temp directory>/GoldenOrb/<jobNumber>/<file name>
                paths.add(System.getProperty("java.io.tmpdir") + "/GoldenOrb/" + orbConf.getOrbClusterName() + "/" + jobNumber + "/" + name[name.length - 1]);
            }
        }
    }
    zk.close();
    return paths;
}

19 View Complete Implementation : BookKeeperClusterUtils.java
Copyright Apache License 2.0
Author : apache
private static boolean waitBookieState(DockerClient docker, String containerId, int timeout, TimeUnit timeoutUnit, boolean upOrDown) {
    long timeoutMillis = timeoutUnit.toMillis(timeout);
    long pollMillis = 1000;
    String bookieId = DockerUtils.getContainerIP(docker, containerId) + ":3181";
    try {
        @Cleanup
        ZooKeeper zk = BookKeeperClusterUtils.zookeeperClient(docker);
        String path = "/ledgers/available/" + bookieId;
        while (timeoutMillis > 0) {
            if ((zk.exists(path, false) != null) == upOrDown) {
                return true;
            }
            Thread.sleep(pollMillis);
            timeoutMillis -= pollMillis;
        }
    } catch (Exception e) {
        LOG.error("Exception checking for bookie state", e);
        return false;
    }
    LOG.warn("Bookie {} didn't go {} after {} seconds", containerId, upOrDown ? "up" : "down", timeoutUnit.toSeconds(timeout));
    return false;
}

19 View Complete Implementation : CommandLineUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Provides a "job" command in the CLI.
 *
 * @param args
 *          - String[]
 */
public static void job(String[] args) {
    ZooKeeper zk = connectZookeeper();
    if (args[1].equalsIgnoreCase("-kill")) {
        jobKill(args, zk);
    } else if (args[1].equalsIgnoreCase("-status")) {
        jobStatus(args, zk);
    } else {
        System.out.println(args[1] + "is an invalid argument for 'Job'. Use 'Help -Job' for a list of valid arguments.");
    }
}

19 View Complete Implementation : OrbFastBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if only some of the member nodes join.
 *
 * @throws Exception
 */
@Test
public void someMembersJoin() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    CountDownLatch lastMemberLatch = new CountDownLatch(1);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbFastBarrier testBarrier1 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbFastBarrier testBarrier2 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    // OrbFastBarrier testBarrier3 = new OrbFastBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch);
    // BarrierThread bThread3 = new BarrierThread(testBarrier3, lastMemberLatch, everyoneDoneLatch);
    bThread1.start();
    bThread2.start();
    // bThread3.start();
    // start first 2 threads
    startLatch.countDown();
    // wait on the threads with 500ms timeout, expect to
    everyoneDoneLatch.await(500, TimeUnit.MILLISECONDS);
    // timeout
    // lastMemberLatch.countDown(); // start the last member
    // everyoneDoneLatch.await();
    replacedertTrue(zk.exists(barrierName + "/member1", false) != null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) != null);
    // replacedertTrue(zk.exists("/" + barrierName + "/member3", false) != null);
    testBarrier1.makeInactive();
    testBarrier2.makeInactive();
    ZookeeperUtils.recursiveDelete(zk, barrierName);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
// zk.close();
}

19 View Complete Implementation : OrbBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if all expected member nodes join in a timely manner.
 *
 * @throws Exception
 */
@Test
public void allMembersJoin() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbBarrier testBarrier1 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbBarrier testBarrier2 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    OrbBarrier testBarrier3 = new OrbBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch);
    BarrierThread bThread3 = new BarrierThread(testBarrier3, startLatch, everyoneDoneLatch);
    bThread1.start();
    bThread2.start();
    bThread3.start();
    // start all threads
    startLatch.countDown();
    // wait until all threads are done
    everyoneDoneLatch.await();
    replacedertTrue(zk.exists(barrierName + "/member1", false) != null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) != null);
    replacedertTrue(zk.exists(barrierName + "/member3", false) != null);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member1");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member2");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName + "/member3");
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
    zk.close();
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Gets data from the Znode specified by the path, reads it into the Writable and sets a watcher
 *
 * @param zk
 * @param path
 *          is the path to the node
 * @param writable
 *          is the Writable object the node data will be read into
 * @param watcher
 *          is the Watcher object to set upon reading the node data
 * @return
 * @throws OrbZKFailure
 */
public static Writable getNodeWritable(ZooKeeper zk, String path, Writable writable, Watcher watcher) throws OrbZKFailure {
    byte[] data = null;
    try {
        data = zk.getData(path, watcher, null);
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
    if (data != null) {
        try {
            return byteArrayToWritable(data, writable);
        } catch (IOException e) {
            throw new OrbZKFailure(e);
        }
    }
    return null;
}

19 View Complete Implementation : ZookeeperUtils.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Gets data from the Znode specified by path and sets a watcher.
 *
 * @param zk
 * @param path
 * @param writableClreplaced
 * @param orbConf
 * @param watcher
 * @return
 * @throws OrbZKFailure
 */
public static Writable getNodeWritable(ZooKeeper zk, String path, Clreplaced<? extends Writable> writableClreplaced, OrbConfiguration orbConf, Watcher watcher) throws OrbZKFailure {
    byte[] data = null;
    try {
        data = zk.getData(path, watcher, null);
    } catch (KeeperException.NoNodeException e) {
        LOG.debug("Node " + path + " does not exist!");
    } catch (KeeperException e) {
        throw new OrbZKFailure(e);
    } catch (InterruptedException e) {
        throw new OrbZKFailure(e);
    }
    if (data != null) {
        return byteArrayToWritable(data, writableClreplaced, orbConf);
    } else {
        return null;
    }
}

19 View Complete Implementation : OrbFastAllDoneBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 * Tests the behavior of the barrier if all expected member nodes join in a
 * timely manner.
 *
 * @throws Exception
 */
@Test
public void allMembersJoinNotAllDone() throws Exception {
    numOfMembers = 3;
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfMembers);
    startLatch = new CountDownLatch(1);
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    OrbFastAllDoneBarrier testBarrier1 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member1", zk);
    OrbFastAllDoneBarrier testBarrier2 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member2", zk);
    OrbFastAllDoneBarrier testBarrier3 = new OrbFastAllDoneBarrier(orbConf, barrierName, numOfMembers, "member3", zk);
    BarrierThread bThread1 = new BarrierThread(testBarrier1, startLatch, everyoneDoneLatch, true);
    BarrierThread bThread2 = new BarrierThread(testBarrier2, startLatch, everyoneDoneLatch, true);
    BarrierThread bThread3 = new BarrierThread(testBarrier3, startLatch, everyoneDoneLatch, false);
    bThread1.start();
    bThread2.start();
    bThread3.start();
    // start all threads
    startLatch.countDown();
    // wait until all threads are done
    everyoneDoneLatch.await();
    // the nodes have deleted themselves ont the way out
    replacedertTrue(zk.exists(barrierName + "/member1", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member2", false) == null);
    replacedertTrue(zk.exists(barrierName + "/member3", false) == null);
    // the nodes say they are all done
    replacedertTrue(!bThread1.allDone());
    replacedertTrue(!bThread2.allDone());
    replacedertTrue(!bThread3.allDone());
    // the AllDone node exits
    replacedertTrue(zk.exists(barrierName + "/AllClear", false) != null);
    ZookeeperUtils.recursiveDelete(zk, barrierName);
    ZookeeperUtils.deleteNodeIfEmpty(zk, barrierName);
}

19 View Complete Implementation : OrbFastAllDoneBarrierTest.java
Copyright Apache License 2.0
Author : jzachr
/**
 */
private void deleteThreads() throws InterruptedException, OrbZKFailure, IOException {
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    ZooKeeper zk = ZookeeperUtils.connect(orbConf.getOrbZooKeeperQuorum());
    for (int i = 0; i < 10; i++) {
        ZookeeperUtils.recursiveDelete(zk, "/barrier" + i);
        ZookeeperUtils.deleteNodeIfEmpty(zk, "/barrier" + i);
    }
    System.err.println("Waiting 10 seconds");
    Thread.sleep(10000);
}