org.apache.hadoop.hbase.zookeeper.ZKUtil.connect()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.connect()方法的一些代码示例,展示了ZKUtil.connect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.connect()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:connect

ZKUtil.connect介绍

[英]Creates a new connection to ZooKeeper, pulling settings and ensemble config from the specified configuration object using methods from ZKConfig. Sets the connection status monitoring watcher to the specified watcher.
[中]创建到ZooKeeper的新连接,使用ZKConfig中的方法从指定的配置对象中提取设置和集合配置。将连接状态监视监视程序设置为指定的监视程序。

代码示例

代码示例来源:origin: apache/hbase

  1. public static RecoverableZooKeeper connect(Configuration conf, String ensemble,
  2. Watcher watcher)
  3. throws IOException {
  4. return connect(conf, ensemble, watcher, null);
  5. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Creates a new connection to ZooKeeper, pulling settings and ensemble config
  3. * from the specified configuration object using methods from {@link ZKConfig}.
  4. *
  5. * Sets the connection status monitoring watcher to the specified watcher.
  6. *
  7. * @param conf configuration to pull ensemble and other settings from
  8. * @param watcher watcher to monitor connection changes
  9. * @return connection to zookeeper
  10. * @throws IOException if unable to connect to zk or config problem
  11. */
  12. public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
  13. throws IOException {
  14. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  15. return connect(conf, ensemble, watcher);
  16. }

代码示例来源:origin: apache/hbase

  1. private void testZNodeACLs() throws IOException, KeeperException, InterruptedException {
  2. ZKWatcher watcher = new ZKWatcher(conf, "IntegrationTestZnodeACLs", null);
  3. RecoverableZooKeeper zk = ZKUtil.connect(this.conf, watcher);
  4. String baseZNode = watcher.getZNodePaths().baseZNode;
  5. LOG.info("");
  6. LOG.info("***********************************************************************************");
  7. LOG.info("Checking ZK permissions, root znode: " + baseZNode);
  8. LOG.info("***********************************************************************************");
  9. LOG.info("");
  10. checkZnodePermsRecursive(watcher, zk, baseZNode);
  11. LOG.info("Checking ZK permissions: SUCCESS");
  12. }

代码示例来源:origin: apache/hbase

  1. this.znodePaths = new ZNodePaths(conf);
  2. PendingWatcher pendingWatcher = new PendingWatcher();
  3. this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, pendingWatcher, identifier);
  4. pendingWatcher.prepare(this);
  5. if (canCreateBaseZNode) {

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testSetDataVersionMismatchInLoop() throws Exception {
  3. String znode = "/hbase/splitWAL/9af7cfc9b15910a0b3d714bf40a3248f";
  4. Configuration conf = TEST_UTIL.getConfiguration();
  5. ZKWatcher zkw = new ZKWatcher(conf, "testSetDataVersionMismatchInLoop",
  6. abortable, true);
  7. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  8. RecoverableZooKeeper rzk = ZKUtil.connect(conf, ensemble, zkw);
  9. rzk.create(znode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  10. rzk.setData(znode, "OPENING".getBytes(), 0);
  11. Field zkField = RecoverableZooKeeper.class.getDeclaredField("zk");
  12. zkField.setAccessible(true);
  13. int timeout = conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
  14. ZookeeperStub zkStub = new ZookeeperStub(ensemble, timeout, zkw);
  15. zkStub.setThrowExceptionInNumOperations(1);
  16. zkField.set(rzk, zkStub);
  17. byte[] opened = "OPENED".getBytes();
  18. rzk.setData(znode, opened, 1);
  19. byte[] data = rzk.getData(znode, false, new Stat());
  20. assertTrue(Bytes.equals(opened, data));
  21. }

代码示例来源:origin: co.cask.hbase/hbase

  1. public static RecoverableZooKeeper connect(Configuration conf, String ensemble,
  2. Watcher watcher)
  3. throws IOException {
  4. return connect(conf, ensemble, watcher, "");
  5. }

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. public static RecoverableZooKeeper connect(Configuration conf, String ensemble,
  2. Watcher watcher)
  3. throws IOException {
  4. return connect(conf, ensemble, watcher, null);
  5. }

代码示例来源:origin: harbby/presto-connectors

  1. public static RecoverableZooKeeper connect(Configuration conf, String ensemble,
  2. Watcher watcher)
  3. throws IOException {
  4. return connect(conf, ensemble, watcher, null);
  5. }

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. /**
  2. * Creates a new connection to ZooKeeper, pulling settings and ensemble config
  3. * from the specified configuration object using methods from {@link ZKConfig}.
  4. *
  5. * Sets the connection status monitoring watcher to the specified watcher.
  6. *
  7. * @param conf configuration to pull ensemble and other settings from
  8. * @param watcher watcher to monitor connection changes
  9. * @return connection to zookeeper
  10. * @throws IOException if unable to connect to zk or config problem
  11. */
  12. public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
  13. throws IOException {
  14. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  15. return connect(conf, ensemble, watcher);
  16. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * Creates a new connection to ZooKeeper, pulling settings and ensemble config
  3. * from the specified configuration object using methods from {@link ZKConfig}.
  4. *
  5. * Sets the connection status monitoring watcher to the specified watcher.
  6. *
  7. * @param conf configuration to pull ensemble and other settings from
  8. * @param watcher watcher to monitor connection changes
  9. * @return connection to zookeeper
  10. * @throws IOException if unable to connect to zk or config problem
  11. */
  12. public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
  13. throws IOException {
  14. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  15. return connect(conf, ensemble, watcher);
  16. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * Creates a new connection to ZooKeeper, pulling settings and ensemble config
  3. * from the specified configuration object using methods from {@link ZKConfig}.
  4. *
  5. * Sets the connection status monitoring watcher to the specified watcher.
  6. *
  7. * @param conf configuration to pull ensemble and other settings from
  8. * @param watcher watcher to monitor connection changes
  9. * @return connection to zookeeper
  10. * @throws IOException if unable to connect to zk or config problem
  11. */
  12. public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
  13. throws IOException {
  14. Properties properties = ZKConfig.makeZKProps(conf);
  15. String ensemble = ZKConfig.getZKQuorumServersString(properties);
  16. return connect(conf, ensemble, watcher);
  17. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * Instantiate a ZooKeeper connection and watcher.
  3. * @param descriptor Descriptive string that is added to zookeeper sessionid
  4. * and used as identifier for this instance.
  5. * @throws IOException
  6. * @throws ZooKeeperConnectionException
  7. */
  8. public ZooKeeperWatcher(Configuration conf, String descriptor,
  9. Abortable abortable, boolean canCreateBaseZNode)
  10. throws IOException, ZooKeeperConnectionException {
  11. this.conf = conf;
  12. // Capture a stack trace now. Will print it out later if problem so we can
  13. // distingush amongst the myriad ZKWs.
  14. try {
  15. throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING");
  16. } catch (Exception e) {
  17. this.constructorCaller = e;
  18. }
  19. this.quorum = ZKConfig.getZKQuorumServersString(conf);
  20. // Identifier will get the sessionid appended later below down when we
  21. // handle the syncconnect event.
  22. this.identifier = descriptor;
  23. this.abortable = abortable;
  24. setNodeNames(conf);
  25. this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, descriptor);
  26. if (canCreateBaseZNode) {
  27. createBaseZNodes();
  28. }
  29. }

代码示例来源:origin: org.apache.hbase/hbase-it

  1. private void testZNodeACLs() throws IOException, KeeperException, InterruptedException {
  2. ZKWatcher watcher = new ZKWatcher(conf, "IntegrationTestZnodeACLs", null);
  3. RecoverableZooKeeper zk = ZKUtil.connect(this.conf, watcher);
  4. String baseZNode = watcher.getZNodePaths().baseZNode;
  5. LOG.info("");
  6. LOG.info("***********************************************************************************");
  7. LOG.info("Checking ZK permissions, root znode: " + baseZNode);
  8. LOG.info("***********************************************************************************");
  9. LOG.info("");
  10. checkZnodePermsRecursive(watcher, zk, baseZNode);
  11. LOG.info("Checking ZK permissions: SUCCESS");
  12. }

代码示例来源:origin: harbby/presto-connectors

  1. this.abortable = abortable;
  2. setNodeNames(conf);
  3. this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, identifier);
  4. if (canCreateBaseZNode) {
  5. createBaseZNodes();

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. this.znodePaths = new ZNodePaths(conf);
  2. PendingWatcher pendingWatcher = new PendingWatcher();
  3. this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, pendingWatcher, identifier);
  4. pendingWatcher.prepare(this);
  5. if (canCreateBaseZNode) {

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. @Test
  2. public void testSetDataVersionMismatchInLoop() throws Exception {
  3. String znode = "/hbase/splitWAL/9af7cfc9b15910a0b3d714bf40a3248f";
  4. Configuration conf = TEST_UTIL.getConfiguration();
  5. ZKWatcher zkw = new ZKWatcher(conf, "testSetDataVersionMismatchInLoop",
  6. abortable, true);
  7. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  8. RecoverableZooKeeper rzk = ZKUtil.connect(conf, ensemble, zkw);
  9. rzk.create(znode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  10. rzk.setData(znode, "OPENING".getBytes(), 0);
  11. Field zkField = RecoverableZooKeeper.class.getDeclaredField("zk");
  12. zkField.setAccessible(true);
  13. int timeout = conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
  14. ZookeeperStub zkStub = new ZookeeperStub(ensemble, timeout, zkw);
  15. zkStub.setThrowExceptionInNumOperations(1);
  16. zkField.set(rzk, zkStub);
  17. byte[] opened = "OPENED".getBytes();
  18. rzk.setData(znode, opened, 1);
  19. byte[] data = rzk.getData(znode, false, new Stat());
  20. assertTrue(Bytes.equals(opened, data));
  21. }

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

  1. @Test
  2. public void testSetDataVersionMismatchInLoop() throws Exception {
  3. String znode = "/hbase/splitWAL/9af7cfc9b15910a0b3d714bf40a3248f";
  4. Configuration conf = TEST_UTIL.getConfiguration();
  5. ZKWatcher zkw = new ZKWatcher(conf, "testSetDataVersionMismatchInLoop",
  6. abortable, true);
  7. String ensemble = ZKConfig.getZKQuorumServersString(conf);
  8. RecoverableZooKeeper rzk = ZKUtil.connect(conf, ensemble, zkw);
  9. rzk.create(znode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  10. rzk.setData(znode, "OPENING".getBytes(), 0);
  11. Field zkField = RecoverableZooKeeper.class.getDeclaredField("zk");
  12. zkField.setAccessible(true);
  13. int timeout = conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
  14. ZookeeperStub zkStub = new ZookeeperStub(ensemble, timeout, zkw);
  15. zkStub.setThrowExceptionInNumOperations(1);
  16. zkField.set(rzk, zkStub);
  17. byte[] opened = "OPENED".getBytes();
  18. rzk.setData(znode, opened, 1);
  19. byte[] data = rzk.getData(znode, false, new Stat());
  20. assertTrue(Bytes.equals(opened, data));
  21. }

相关文章