示例#1
0
文件: ZkRing.java 项目: thaingo/hank
 @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;
 }
示例#2
0
文件: ZkRing.java 项目: thaingo/hank
 @Override
 public Host getHostByAddress(PartitionServerAddress address) {
   for (ZkHost host : hosts.values()) {
     if (host.getAddress().equals(address)) {
       return host;
     }
   }
   return null;
 }
示例#3
0
文件: ZkRing.java 项目: thaingo/hank
  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());
  }
示例#4
0
文件: ZkRing.java 项目: thaingo/hank
 @Override
 public Set<Host> getHosts() {
   return new HashSet<Host>(hosts.values());
 }