예제 #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());
 }