Ejemplo n.º 1
0
  public Set<InetSocketAddress> getServers(String zookeeperInstance, String serviceName) {
    try (CuratorFramework zkClient = connectToZookeeper(zookeeperInstance)) {
      ZookeeperServiceReader reader = new ZookeeperServiceReader();

      Set<InetSocketAddress> servers =
          reader
              .nodePaths(zkClient, serviceName)
              .stream()
              .map(nodePath -> toInetAdrress(nodePath, reader, zkClient))
              .filter(address -> address != null)
              .collect(Collectors.toSet());

      return servers;
    } catch (Exception e) {
      logger.error("Rethrowing error ", e);
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 2
0
 private InetSocketAddress toInetAdrress(
     String nodePath, ZookeeperServiceReader reader, CuratorFramework zkClient) {
   try {
     byte[] data = zkClient.getData().forPath(nodePath);
     if (data == null) {
       // clustered service member went away, but path still exists
       return null;
     }
     return reader.deserialize(data);
   } catch (Exception e) {
     logger.error("Rethrowing exception ", e);
     throw new RuntimeException(e);
   }
 }