Esempio n. 1
0
 @Override
 public boolean removeHost(PartitionServerAddress address) throws IOException {
   for (Map.Entry<String, ZkHost> entry : hosts.entrySet()) {
     if (entry.getValue().getAddress().equals(address)) {
       ZkHost host = hosts.remove(entry.getKey());
       host.delete();
       fireDataLocationChangeListener();
       return true;
     }
   }
   return false;
 }
Esempio n. 2
0
 @Override
 public Host getHostByAddress(PartitionServerAddress address) {
   for (ZkHost host : hosts.values()) {
     if (host.getAddress().equals(address)) {
       return host;
     }
   }
   return null;
 }
Esempio n. 3
0
  public ZkRing(
      ZooKeeperPlus zk,
      final String ringPath,
      RingGroup ringGroup,
      final Coordinator coordinator,
      final DataLocationChangeListener dataLocationChangeListener)
      throws InterruptedException, KeeperException {
    super(parseRingNum(ringPath), ringGroup);
    this.zk = zk;
    this.ringPath = ringPath;
    this.coordinator = coordinator;
    this.dataLocationChangeListener = dataLocationChangeListener;

    if (coordinator == null) {
      throw new RuntimeException("Cannot initialize a ZkRing with a null Coordinator.");
    }

    hosts =
        new WatchedMap<ZkHost>(
            zk,
            ZkPath.append(ringPath, HOSTS_PATH_SEGMENT),
            new WatchedMap.ElementLoader<ZkHost>() {
              @Override
              public ZkHost load(ZooKeeperPlus zk, String basePath, String relPath)
                  throws InterruptedException, KeeperException {
                return new ZkHost(
                    zk,
                    coordinator,
                    ZkPath.append(basePath, relPath),
                    dataLocationChangeListener,
                    false,
                    null,
                    null);
              }
            },
            new DotComplete());
    hosts.addListener(new ZkRing.HostsWatchedMapListener());
  }
Esempio n. 4
0
 @Override
 public Set<Host> getHosts() {
   return new HashSet<Host>(hosts.values());
 }