com.indeed.util.zookeeper.ZooKeeperConnection.connect()方法的使用及代码示例

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

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

ZooKeeperConnection.connect介绍

暂无

代码示例

代码示例来源:origin: indeedeng/imhotep

private void createNode() {
  boolean created = false;
  while (!created) {
    try {
      try {
        zkConnection.connect();
        ZooKeeperConnection.createFullPath(zkConnection, rootPath, new byte[0], CreateMode.PERSISTENT, true);
        zkConnection.create(rootPath + "/"+nodeName, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
        created = true;
      } catch (IOException e) {
        log.error(e);
        Thread.sleep(TIMEOUT);
      } catch (KeeperException e) {
        log.error(e);
        zkConnection.close();
        Thread.sleep(TIMEOUT);
      }
    } catch (InterruptedException e) {
      log.error(e);
    }
  }
}

代码示例来源:origin: indeedeng/imhotep

public ZkHostsReloader(final String zkNodes, final String zkPath, final boolean readHostsBeforeReturning) {
  super("ZkHostsReloader");
  zkConnection = new ZooKeeperConnection(zkNodes, TIMEOUT);
  try {
    zkConnection.connect();
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
  this.zkPath = trimEndingSlash(zkPath);
  closed = false;
  hosts = new ArrayList<Host>();
  if (readHostsBeforeReturning) {
    int retries = 0;
    while (true) {
      updateLastLoadCheck();
      if (load()) {
        loadComplete();
        break;
      }
      try {
        Thread.sleep(TIMEOUT);
      } catch (InterruptedException e) {
        log.error("interrupted", e);
      }
      if (++retries == 5) {
        throw new RuntimeException("unable to connect to zookeeper");
      }
    }
  }
}

代码示例来源:origin: indeedeng/imhotep

@Override
public boolean load() {
  if (!closed) {
    try {
      try {
        try {
          final List<Host> newHosts = readHostsFromZK();
          if (!newHosts.equals(hosts)) {
            hosts = newHosts;
          }
          return true;
        } catch (KeeperException e) {
          log.error("zookeeper exception", e);
          loadFailed();
          zkConnection.close();
          zkConnection.connect();
        }
      } catch (IOException e) {
        loadFailed();
        log.error("io exception", e);
      }
    } catch (InterruptedException e) {
      log.error("interrupted", e);
      loadFailed();
    }
  }
  return false;
}

相关文章