Examples of ZooKeeperClient


Examples of org.apache.hdt.core.zookeeper.ZooKeeperClient

  @Override
  public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof ZNode) {
      ZNode zkn = (ZNode) parentElement;
      try {
        ZooKeeperClient client = ZooKeeperManager.INSTANCE.getClient(zkn.getServer());
        List<ZNode> zkChildren = client.getChildren(zkn);
        return zkChildren.toArray();
      } catch (Exception e) {
        logger.error("Error getting children of node", e);
        MessageDialog.openError(Display.getDefault().getActiveShell(),
            "ZooKeeper Error",e.getMessage());
View Full Code Here

Examples of org.apache.hdt.core.zookeeper.ZooKeeperClient

    if (clientsMap.containsKey(server.getUri()))
      return clientsMap.get(server.getUri());
    else {
      IConfigurationElement[] elementsFor = Platform.getExtensionRegistry().getConfigurationElementsFor("org.apache.hdt.core.zookeeperClient");
      for (IConfigurationElement element : elementsFor) {
        ZooKeeperClient client = (ZooKeeperClient) element.createExecutableExtension("class");
        client.initialize(server.getUri());
        clientsMap.put(server.getUri(), new InterruptableZooKeeperClient(server, client));
      }
      return clientsMap.get(server.getUri());
    }
  }
View Full Code Here

Examples of org.kiji.schema.layout.impl.ZooKeeperClient

  @Test
  public void testZooKeeperLockIsExclusiveWithZKMZooKeeperLock() throws Exception {
    final File path = new File("/lock/is/exclusive/zkm");
    CuratorFramework zkClient1 = ZooKeeperUtils.getZooKeeperClient(getZKAddress());
    try {
      ZooKeeperClient zkClient2 = ZooKeeperClient.getZooKeeperClient(getZKAddress());
      try {
        ZooKeeperLock lock1 = new ZooKeeperLock(zkClient1, path);
        try {
          org.kiji.schema.util.ZooKeeperLock lock2 =
              new org.kiji.schema.util.ZooKeeperLock(zkClient2, path);
          try {
            Assert.assertTrue(lock1.lock(1.0));
            Assert.assertFalse(lock2.lock(1.0));
            lock1.unlock();

            Assert.assertTrue(lock2.lock(1.0));
            Assert.assertFalse(lock1.lock(1.0));
            lock2.unlock();
          } finally {
            lock2.close();
          }
        } finally {
          lock1.close();
        }
      } finally {
        zkClient2.release();
      }
    } finally {
      zkClient1.close();
    }
  }
View Full Code Here

Examples of org.kiji.schema.layout.impl.ZooKeeperClient

  /** Overly basic test for ZooKeeper locks. */
  @Test
  public void testZooKeeperLock() throws Exception {
    final File lockDir = new File("/lock");
    final ZooKeeperClient zkClient = ZooKeeperClient.getZooKeeperClient(getZKAddress());
    try {
      final CyclicBarrier barrier = new CyclicBarrier(2);
      final ZooKeeperLock lock1 = new ZooKeeperLock(zkClient, lockDir);
      final ZooKeeperLock lock2 = new ZooKeeperLock(zkClient, lockDir);
      lock1.lock();

      final Thread thread = new Thread() {
        /** {@inheritDoc} */
        @Override
        public void run() {
          try {
            assertFalse(lock2.lock(0.1));
            barrier.await();
            lock2.lock();
            lock2.unlock();

            lock2.lock();
            lock2.unlock();
            lock2.close();
            barrier.await();
          } catch (Exception e) {
            LOG.warn("Exception caught in locking thread: {}", e.getMessage());
          }
        }
      };
      thread.start();

      barrier.await(5, TimeUnit.SECONDS); // Eventually fail

      lock1.unlock();
      lock1.close();

      barrier.await(5, TimeUnit.SECONDS); // Eventually fail
    } finally {
      zkClient.release();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.